From 1b201107ca7e22e40b4282e0bdf1572ac1983c19 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Wed, 3 Jul 2024 13:02:50 -0600 Subject: [PATCH 1/6] Move recent_blockhashes_account to runtime --- runtime/src/bank.rs | 3 +-- {sdk/src => runtime/src/bank}/recent_blockhashes_account.rs | 0 sdk/src/lib.rs | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) rename {sdk/src => runtime/src/bank}/recent_blockhashes_account.rs (100%) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 3ee96afc86db3c..4885824f1a0ec6 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -33,8 +33,6 @@ //! It offers a high-level API that signs transactions //! on behalf of the caller, and a low-level API for when they have //! already been signed and verified. -#[allow(deprecated)] -use solana_sdk::recent_blockhashes_account; use { crate::{ bank::{ @@ -228,6 +226,7 @@ pub mod epoch_accounts_hash_utils; mod fee_distribution; mod metrics; pub(crate) mod partitioned_epoch_rewards; +mod recent_blockhashes_account; mod serde_snapshot; mod sysvar_cache; pub(crate) mod tests; diff --git a/sdk/src/recent_blockhashes_account.rs b/runtime/src/bank/recent_blockhashes_account.rs similarity index 100% rename from sdk/src/recent_blockhashes_account.rs rename to runtime/src/bank/recent_blockhashes_account.rs diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 93e99fb769c22d..098da40b821efb 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -93,7 +93,6 @@ pub mod precompiles; pub mod program_utils; pub mod pubkey; pub mod quic; -pub mod recent_blockhashes_account; pub mod rent_collector; pub mod rent_debits; pub mod reserved_account_keys; From cdf2cc8de97fbf296772db01a23922666946262e Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Wed, 3 Jul 2024 13:03:27 -0600 Subject: [PATCH 2/6] Fixup imports --- runtime/src/bank/recent_blockhashes_account.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/src/bank/recent_blockhashes_account.rs b/runtime/src/bank/recent_blockhashes_account.rs index 4235fc798a0b87..38b8331bb430fd 100644 --- a/runtime/src/bank/recent_blockhashes_account.rs +++ b/runtime/src/bank/recent_blockhashes_account.rs @@ -1,11 +1,11 @@ //! Helpers for the recent blockhashes sysvar. #[allow(deprecated)] -use solana_program::sysvar::recent_blockhashes::{ +use solana_sdk::sysvar::recent_blockhashes::{ IntoIterSorted, IterItem, RecentBlockhashes, MAX_ENTRIES, }; use { - crate::{ + solana_sdk::{ account::{ create_account_shared_data_with_fields, to_account, AccountSharedData, InheritableAccountFields, DUMMY_INHERITABLE_ACCOUNT_FIELDS, @@ -87,9 +87,9 @@ mod tests { #![allow(deprecated)] use { super::*, - crate::account::from_account, rand::{seq::SliceRandom, thread_rng}, - solana_program::{ + solana_sdk::{ + account::from_account, hash::{Hash, HASH_BYTES}, sysvar::recent_blockhashes::Entry, }, From 3f77fb2183936c485d1f88dc6b04387f5a1133c1 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Wed, 3 Jul 2024 13:10:05 -0600 Subject: [PATCH 3/6] Reduce pub --- runtime/src/bank/recent_blockhashes_account.rs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/runtime/src/bank/recent_blockhashes_account.rs b/runtime/src/bank/recent_blockhashes_account.rs index 38b8331bb430fd..6a82cdc9755878 100644 --- a/runtime/src/bank/recent_blockhashes_account.rs +++ b/runtime/src/bank/recent_blockhashes_account.rs @@ -15,15 +15,8 @@ use { std::{collections::BinaryHeap, iter::FromIterator}, }; -#[deprecated( - since = "1.9.0", - note = "Please do not use, will no longer be available in the future" -)] #[allow(deprecated)] -pub fn update_account<'a, I>( - account: &mut AccountSharedData, - recent_blockhash_iter: I, -) -> Option<()> +fn update_account<'a, I>(account: &mut AccountSharedData, recent_blockhash_iter: I) -> Option<()> where I: IntoIterator>, { @@ -50,12 +43,8 @@ where create_account_with_data_and_fields(recent_blockhash_iter, (lamports, INITIAL_RENT_EPOCH)) } -#[deprecated( - since = "1.9.0", - note = "Please do not use, will no longer be available in the future" -)] #[allow(deprecated)] -pub fn create_account_with_data_and_fields<'a, I>( +pub(in crate::bank) fn create_account_with_data_and_fields<'a, I>( recent_blockhash_iter: I, fields: InheritableAccountFields, ) -> AccountSharedData From 908cf9dc10c4cfbd42c6d8c342f0bce5b4438971 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Wed, 3 Jul 2024 13:12:17 -0600 Subject: [PATCH 4/6] Remove unused method --- runtime/src/bank/recent_blockhashes_account.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/runtime/src/bank/recent_blockhashes_account.rs b/runtime/src/bank/recent_blockhashes_account.rs index 6a82cdc9755878..99775d9a2964e3 100644 --- a/runtime/src/bank/recent_blockhashes_account.rs +++ b/runtime/src/bank/recent_blockhashes_account.rs @@ -30,19 +30,6 @@ where to_account(&recent_blockhashes, account) } -#[deprecated( - since = "1.5.17", - note = "Please use `create_account_with_data_for_test` instead" -)] -#[allow(deprecated)] -pub fn create_account_with_data<'a, I>(lamports: u64, recent_blockhash_iter: I) -> AccountSharedData -where - I: IntoIterator>, -{ - #[allow(deprecated)] - create_account_with_data_and_fields(recent_blockhash_iter, (lamports, INITIAL_RENT_EPOCH)) -} - #[allow(deprecated)] pub(in crate::bank) fn create_account_with_data_and_fields<'a, I>( recent_blockhash_iter: I, From 0af1727a08570ea1ad2c053f6899f38cc2828c00 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Wed, 3 Jul 2024 13:29:11 -0600 Subject: [PATCH 5/6] Duplicate code to limit pub and dependency complexity --- programs/system/src/system_processor.rs | 53 ++++++++++++++++++------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/programs/system/src/system_processor.rs b/programs/system/src/system_processor.rs index d455fb84ba5c12..db14cc9c5ebba7 100644 --- a/programs/system/src/system_processor.rs +++ b/programs/system/src/system_processor.rs @@ -542,7 +542,10 @@ declare_process_instruction!(Entrypoint, DEFAULT_COMPUTE_UNITS, |invoke_context| mod tests { #[allow(deprecated)] use solana_sdk::{ - account::{self, Account, AccountSharedData, ReadableAccount}, + account::{ + self, create_account_shared_data_with_fields, to_account, Account, AccountSharedData, + ReadableAccount, DUMMY_INHERITABLE_ACCOUNT_FIELDS, + }, fee_calculator::FeeCalculator, hash::{hash, Hash}, instruction::{AccountMeta, Instruction, InstructionError}, @@ -552,8 +555,12 @@ mod tests { Data as NonceData, DurableNonce, State as NonceState, Versions as NonceVersions, }, }, - nonce_account, recent_blockhashes_account, system_instruction, system_program, - sysvar::{self, recent_blockhashes::IterItem, rent::Rent}, + nonce_account, system_instruction, system_program, + sysvar::{ + self, + recent_blockhashes::{IntoIterSorted, IterItem, RecentBlockhashes, MAX_ENTRIES}, + rent::Rent, + }, }; use { super::*, @@ -562,6 +569,7 @@ mod tests { solana_program_runtime::{ invoke_context::mock_process_instruction, with_mock_invoke_context, }, + std::collections::BinaryHeap, }; impl From for Address { @@ -595,11 +603,30 @@ mod tests { fn create_default_account() -> AccountSharedData { AccountSharedData::new(0, 0, &Pubkey::new_unique()) } + #[allow(deprecated)] + fn create_recent_blockhashes_account_for_test<'a, I>( + recent_blockhash_iter: I, + ) -> AccountSharedData + where + I: IntoIterator>, + { + let mut account = create_account_shared_data_with_fields::( + &RecentBlockhashes::default(), + DUMMY_INHERITABLE_ACCOUNT_FIELDS, + ); + let sorted = BinaryHeap::from_iter(recent_blockhash_iter); + let sorted_iter = IntoIterSorted::new(sorted); + let recent_blockhash_iter = sorted_iter.take(MAX_ENTRIES); + let recent_blockhashes: RecentBlockhashes = recent_blockhash_iter.collect(); + to_account(&recent_blockhashes, &mut account); + account + } fn create_default_recent_blockhashes_account() -> AccountSharedData { #[allow(deprecated)] - recent_blockhashes_account::create_account_with_data_for_test( - vec![IterItem(0u64, &Hash::default(), 0); sysvar::recent_blockhashes::MAX_ENTRIES], - ) + create_recent_blockhashes_account_for_test(vec![ + IterItem(0u64, &Hash::default(), 0); + sysvar::recent_blockhashes::MAX_ENTRIES + ]) } fn create_default_rent_account() -> AccountSharedData { account::create_account_shared_data_for_test(&Rent::free()) @@ -1551,10 +1578,10 @@ mod tests { ); let blockhash = hash(&serialize(&0).unwrap()); #[allow(deprecated)] - let new_recent_blockhashes_account = - solana_sdk::recent_blockhashes_account::create_account_with_data_for_test( - vec![IterItem(0u64, &blockhash, 0); sysvar::recent_blockhashes::MAX_ENTRIES], - ); + let new_recent_blockhashes_account = create_recent_blockhashes_account_for_test(vec![ + IterItem(0u64, &blockhash, 0); + sysvar::recent_blockhashes::MAX_ENTRIES + ]); mock_process_instruction( &system_program::id(), Vec::new(), @@ -1837,8 +1864,7 @@ mod tests { #[allow(deprecated)] let blockhash_id = sysvar::recent_blockhashes::id(); #[allow(deprecated)] - let new_recent_blockhashes_account = - solana_sdk::recent_blockhashes_account::create_account_with_data_for_test(vec![]); + let new_recent_blockhashes_account = create_recent_blockhashes_account_for_test(vec![]); process_instruction( &serialize(&SystemInstruction::InitializeNonceAccount(nonce_address)).unwrap(), vec![ @@ -1900,8 +1926,7 @@ mod tests { Ok(()), ); #[allow(deprecated)] - let new_recent_blockhashes_account = - solana_sdk::recent_blockhashes_account::create_account_with_data_for_test(vec![]); + let new_recent_blockhashes_account = create_recent_blockhashes_account_for_test(vec![]); mock_process_instruction( &system_program::id(), Vec::new(), From 2ebaaa80d78dcc5e397138b05eb3fe5f61159107 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Wed, 3 Jul 2024 13:32:28 -0600 Subject: [PATCH 6/6] Move test-only fn into tests module --- .../src/bank/recent_blockhashes_account.rs | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/runtime/src/bank/recent_blockhashes_account.rs b/runtime/src/bank/recent_blockhashes_account.rs index 99775d9a2964e3..71815ef00f4e02 100644 --- a/runtime/src/bank/recent_blockhashes_account.rs +++ b/runtime/src/bank/recent_blockhashes_account.rs @@ -5,12 +5,9 @@ use solana_sdk::sysvar::recent_blockhashes::{ IntoIterSorted, IterItem, RecentBlockhashes, MAX_ENTRIES, }; use { - solana_sdk::{ - account::{ - create_account_shared_data_with_fields, to_account, AccountSharedData, - InheritableAccountFields, DUMMY_INHERITABLE_ACCOUNT_FIELDS, - }, - clock::INITIAL_RENT_EPOCH, + solana_sdk::account::{ + create_account_shared_data_with_fields, to_account, AccountSharedData, + InheritableAccountFields, }, std::{collections::BinaryHeap, iter::FromIterator}, }; @@ -46,18 +43,6 @@ where account } -#[deprecated( - since = "1.9.0", - note = "Please do not use, will no longer be available in the future" -)] -#[allow(deprecated)] -pub fn create_account_with_data_for_test<'a, I>(recent_blockhash_iter: I) -> AccountSharedData -where - I: IntoIterator>, -{ - create_account_with_data_and_fields(recent_blockhash_iter, DUMMY_INHERITABLE_ACCOUNT_FIELDS) -} - #[cfg(test)] mod tests { #![allow(deprecated)] @@ -65,12 +50,19 @@ mod tests { super::*, rand::{seq::SliceRandom, thread_rng}, solana_sdk::{ - account::from_account, + account::{from_account, DUMMY_INHERITABLE_ACCOUNT_FIELDS}, hash::{Hash, HASH_BYTES}, sysvar::recent_blockhashes::Entry, }, }; + fn create_account_with_data_for_test<'a, I>(recent_blockhash_iter: I) -> AccountSharedData + where + I: IntoIterator>, + { + create_account_with_data_and_fields(recent_blockhash_iter, DUMMY_INHERITABLE_ACCOUNT_FIELDS) + } + #[test] fn test_create_account_empty() { let account = create_account_with_data_for_test(vec![]);