diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index 59036a997039c1..5af02b9c382898 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -4834,7 +4834,7 @@ pub(crate) mod tests { genesis_config.ticks_per_slot = 4; let bank0 = Bank::new_for_tests(&genesis_config); for _ in 0..genesis_config.ticks_per_slot { - bank0.register_tick(&Hash::default()); + bank0.register_default_tick_for_test(); } bank0.freeze(); let arc_bank0 = Arc::new(bank0); @@ -4879,7 +4879,7 @@ pub(crate) mod tests { &solana_sdk::pubkey::new_rand(), ); for _ in 0..genesis_config.ticks_per_slot { - bank.register_tick(&Hash::default()); + bank.register_default_tick_for_test(); } bank_forks.write().unwrap().insert(bank); let arc_bank = bank_forks.read().unwrap().get(i).unwrap(); diff --git a/core/src/vote_simulator.rs b/core/src/vote_simulator.rs index 79c418bcc7892f..50d76bf4caa447 100644 --- a/core/src/vote_simulator.rs +++ b/core/src/vote_simulator.rs @@ -1,3 +1,4 @@ +#![cfg(feature = "dev-context-only-utils")] use { crate::{ cluster_info_vote_listener::VoteTracker, @@ -117,7 +118,7 @@ impl VoteSimulator { } } while new_bank.tick_height() < new_bank.max_tick_height() { - new_bank.register_tick(&Hash::new_unique()); + new_bank.register_unique_tick(); } if !visit.node().has_no_child() || is_frozen { new_bank.freeze(); @@ -358,7 +359,7 @@ pub fn initialize_state( } while bank0.tick_height() < bank0.max_tick_height() { - bank0.register_tick(&Hash::new_unique()); + bank0.register_unique_tick(); } bank0.freeze(); let mut progress = ProgressMap::default(); diff --git a/core/tests/snapshots.rs b/core/tests/snapshots.rs index b61e84a90810c9..3b689a8423e8b7 100644 --- a/core/tests/snapshots.rs +++ b/core/tests/snapshots.rs @@ -310,7 +310,7 @@ fn goto_end_of_slot(bank: &Bank) { let mut tick_hash = bank.last_blockhash(); loop { tick_hash = hashv(&[tick_hash.as_ref(), &[42]]); - bank.register_tick(&tick_hash); + bank.register_tick_for_test(&tick_hash); if tick_hash == bank.last_blockhash() { bank.freeze(); return; @@ -742,7 +742,7 @@ fn test_bank_forks_incremental_snapshot( assert_eq!(bank.process_transaction(&tx), Ok(())); while !bank.is_complete() { - bank.register_tick(&Hash::new_unique()); + bank.register_unique_tick(); } bank_forks.insert(bank) @@ -1041,7 +1041,7 @@ fn test_snapshots_with_background_services( assert_eq!(bank.process_transaction(&tx), Ok(())); while !bank.is_complete() { - bank.register_tick(&Hash::new_unique()); + bank.register_unique_tick(); } bank_forks.write().unwrap().insert(bank); diff --git a/ledger-tool/Cargo.toml b/ledger-tool/Cargo.toml index fb387773c14cfa..c64dfa07e91a91 100644 --- a/ledger-tool/Cargo.toml +++ b/ledger-tool/Cargo.toml @@ -39,7 +39,7 @@ solana-logger = { workspace = true } solana-measure = { workspace = true } solana-program-runtime = { workspace = true } solana-rpc = { workspace = true } -solana-runtime = { workspace = true } +solana-runtime = { workspace = true, features = ["dev-context-only-utils"] } solana-sdk = { workspace = true } solana-stake-program = { workspace = true } solana-storage-bigtable = { workspace = true } @@ -57,6 +57,9 @@ jemallocator = { workspace = true } assert_cmd = { workspace = true } bytecount = { workspace = true } +[features] +dev-context-only-utils = [] + [target."cfg(unix)".dependencies] signal-hook = { workspace = true } diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 1cce5ad2789371..697199981b26f8 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -3139,7 +3139,7 @@ fn main() { if child_bank_required { while !bank.is_complete() { - bank.register_tick(&Hash::new_unique()); + bank.register_unique_tick(); } } diff --git a/ledger/Cargo.toml b/ledger/Cargo.toml index df52fb3462eaf1..b3fb1ac5f9b97d 100644 --- a/ledger/Cargo.toml +++ b/ledger/Cargo.toml @@ -78,6 +78,7 @@ features = ["lz4"] bs58 = { workspace = true } solana-account-decoder = { workspace = true } solana-logger = { workspace = true } +solana-runtime = { workspace = true, features = ["dev-context-only-utils"] } spl-pod = { workspace = true } test-case = { workspace = true } diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index f5a8836087d3d4..219fa4c62ed3d4 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -3373,7 +3373,7 @@ pub mod tests { let blockhash = bank.last_blockhash(); while blockhash == bank.last_blockhash() { - bank.register_tick(&Hash::default()); + bank.register_default_tick_for_test(); } // ensure bank can process 2 entries that do not have a common account and tick is registered diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 61fab556e503a4..76102732c7d2d8 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -4208,6 +4208,22 @@ impl Bank { self.tick_height.fetch_add(1, Relaxed); } + #[cfg(feature = "dev-context-only-utils")] + pub fn register_tick_for_test(&self, hash: &Hash) { + // currently meaningless wrapper; upcoming pr will make it an actual helper... + self.register_tick(hash) + } + + #[cfg(feature = "dev-context-only-utils")] + pub fn register_default_tick_for_test(&self) { + self.register_tick(&Hash::default()) + } + + #[cfg(feature = "dev-context-only-utils")] + pub fn register_unique_tick(&self) { + self.register_tick(&Hash::new_unique()) + } + pub fn is_complete(&self) -> bool { self.tick_height() == self.max_tick_height() } diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index 58ce790d43d0d4..d009f60d5e4073 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -180,7 +180,7 @@ fn test_race_register_tick_freeze() { let register_tick_thread = Builder::new() .name("register_tick".to_string()) .spawn(move || { - bank0_.register_tick(&hash); + bank0_.register_tick_for_test(&hash); }) .unwrap(); @@ -4204,7 +4204,7 @@ fn test_is_delta_true() { assert!(!bank1.is_delta.load(Relaxed)); assert_ne!(hash1, bank.hash()); // ticks don't make a bank into a delta or change its state unless a block boundary is crossed - bank1.register_tick(&Hash::default()); + bank1.register_default_tick_for_test(); assert!(!bank1.is_delta.load(Relaxed)); assert_eq!(bank1.hash_internal_state(), hash1); } @@ -4928,7 +4928,7 @@ fn test_hash_internal_state_unchanged_with_ticks() { // because blockhashes are only recorded at block boundaries for _ in 0..genesis_config.ticks_per_slot { assert_eq!(bank1.hash_internal_state(), hash1); - bank1.register_tick(&Hash::default()); + bank1.register_default_tick_for_test(); } assert_eq!(bank1.hash_internal_state(), hash1); } diff --git a/runtime/src/bank_forks.rs b/runtime/src/bank_forks.rs index ec69df9dded953..c1ef6830d1998c 100644 --- a/runtime/src/bank_forks.rs +++ b/runtime/src/bank_forks.rs @@ -696,7 +696,7 @@ mod tests { let bank = Bank::new_for_tests(&genesis_config); let mut bank_forks = BankForks::new(bank); let child_bank = Bank::new_from_parent(bank_forks[0].clone(), &Pubkey::default(), 1); - child_bank.register_tick(&Hash::default()); + child_bank.register_default_tick_for_test(); bank_forks.insert(child_bank); assert_eq!(bank_forks[1u64].tick_height(), 1); assert_eq!(bank_forks.working_bank().tick_height(), 1); diff --git a/runtime/src/snapshot_bank_utils.rs b/runtime/src/snapshot_bank_utils.rs index 43b0ef5a364563..e538b07677630f 100644 --- a/runtime/src/snapshot_bank_utils.rs +++ b/runtime/src/snapshot_bank_utils.rs @@ -1290,7 +1290,7 @@ mod tests { let original_bank = Bank::new_for_tests(&genesis_config); while !original_bank.is_complete() { - original_bank.register_tick(&Hash::new_unique()); + original_bank.register_unique_tick(); } let (_tmp_dir, accounts_dir) = create_tmp_accounts_dir_for_tests(); @@ -1359,7 +1359,7 @@ mod tests { .transfer(sol_to_lamports(3.), &mint_keypair, &key3.pubkey()) .unwrap(); while !bank0.is_complete() { - bank0.register_tick(&Hash::new_unique()); + bank0.register_unique_tick(); } let slot = 1; @@ -1374,7 +1374,7 @@ mod tests { .transfer(sol_to_lamports(5.), &mint_keypair, &key5.pubkey()) .unwrap(); while !bank1.is_complete() { - bank1.register_tick(&Hash::new_unique()); + bank1.register_unique_tick(); } let slot = slot + 1; @@ -1383,7 +1383,7 @@ mod tests { .transfer(sol_to_lamports(1.), &mint_keypair, &key1.pubkey()) .unwrap(); while !bank2.is_complete() { - bank2.register_tick(&Hash::new_unique()); + bank2.register_unique_tick(); } let slot = slot + 1; @@ -1392,7 +1392,7 @@ mod tests { .transfer(sol_to_lamports(1.), &mint_keypair, &key1.pubkey()) .unwrap(); while !bank3.is_complete() { - bank3.register_tick(&Hash::new_unique()); + bank3.register_unique_tick(); } let slot = slot + 1; @@ -1401,7 +1401,7 @@ mod tests { .transfer(sol_to_lamports(1.), &mint_keypair, &key1.pubkey()) .unwrap(); while !bank4.is_complete() { - bank4.register_tick(&Hash::new_unique()); + bank4.register_unique_tick(); } let (_tmp_dir, accounts_dir) = create_tmp_accounts_dir_for_tests(); @@ -1476,7 +1476,7 @@ mod tests { .transfer(sol_to_lamports(3.), &mint_keypair, &key3.pubkey()) .unwrap(); while !bank0.is_complete() { - bank0.register_tick(&Hash::new_unique()); + bank0.register_unique_tick(); } let slot = 1; @@ -1491,7 +1491,7 @@ mod tests { .transfer(sol_to_lamports(5.), &mint_keypair, &key5.pubkey()) .unwrap(); while !bank1.is_complete() { - bank1.register_tick(&Hash::new_unique()); + bank1.register_unique_tick(); } let (_tmp_dir, accounts_dir) = create_tmp_accounts_dir_for_tests(); @@ -1519,7 +1519,7 @@ mod tests { .transfer(sol_to_lamports(1.), &mint_keypair, &key1.pubkey()) .unwrap(); while !bank2.is_complete() { - bank2.register_tick(&Hash::new_unique()); + bank2.register_unique_tick(); } let slot = slot + 1; @@ -1528,7 +1528,7 @@ mod tests { .transfer(sol_to_lamports(1.), &mint_keypair, &key1.pubkey()) .unwrap(); while !bank3.is_complete() { - bank3.register_tick(&Hash::new_unique()); + bank3.register_unique_tick(); } let slot = slot + 1; @@ -1537,7 +1537,7 @@ mod tests { .transfer(sol_to_lamports(1.), &mint_keypair, &key1.pubkey()) .unwrap(); while !bank4.is_complete() { - bank4.register_tick(&Hash::new_unique()); + bank4.register_unique_tick(); } let incremental_snapshot_archive_info = bank_to_incremental_snapshot_archive( @@ -1597,7 +1597,7 @@ mod tests { .transfer(sol_to_lamports(3.), &mint_keypair, &key3.pubkey()) .unwrap(); while !bank0.is_complete() { - bank0.register_tick(&Hash::new_unique()); + bank0.register_unique_tick(); } let slot = 1; @@ -1612,7 +1612,7 @@ mod tests { .transfer(sol_to_lamports(3.), &mint_keypair, &key3.pubkey()) .unwrap(); while !bank1.is_complete() { - bank1.register_tick(&Hash::new_unique()); + bank1.register_unique_tick(); } let (_tmp_dir, accounts_dir) = create_tmp_accounts_dir_for_tests(); @@ -1640,7 +1640,7 @@ mod tests { .transfer(sol_to_lamports(1.), &mint_keypair, &key1.pubkey()) .unwrap(); while !bank2.is_complete() { - bank2.register_tick(&Hash::new_unique()); + bank2.register_unique_tick(); } let slot = slot + 1; @@ -1649,7 +1649,7 @@ mod tests { .transfer(sol_to_lamports(2.), &mint_keypair, &key2.pubkey()) .unwrap(); while !bank3.is_complete() { - bank3.register_tick(&Hash::new_unique()); + bank3.register_unique_tick(); } let slot = slot + 1; @@ -1658,7 +1658,7 @@ mod tests { .transfer(sol_to_lamports(3.), &mint_keypair, &key3.pubkey()) .unwrap(); while !bank4.is_complete() { - bank4.register_tick(&Hash::new_unique()); + bank4.register_unique_tick(); } bank_to_incremental_snapshot_archive( @@ -1746,7 +1746,7 @@ mod tests { .transfer(lamports_to_transfer, &mint_keypair, &key2.pubkey()) .unwrap(); while !bank0.is_complete() { - bank0.register_tick(&Hash::new_unique()); + bank0.register_unique_tick(); } let slot = 1; @@ -1755,7 +1755,7 @@ mod tests { .transfer(lamports_to_transfer, &key2, &key1.pubkey()) .unwrap(); while !bank1.is_complete() { - bank1.register_tick(&Hash::new_unique()); + bank1.register_unique_tick(); } let full_snapshot_slot = slot; @@ -1794,7 +1794,7 @@ mod tests { "Ensure Account1's balance is zero" ); while !bank2.is_complete() { - bank2.register_tick(&Hash::new_unique()); + bank2.register_unique_tick(); } // Take an incremental snapshot and then do a roundtrip on the bank and ensure it @@ -1844,13 +1844,13 @@ mod tests { .transfer(lamports_to_transfer, &mint_keypair, &key2.pubkey()) .unwrap(); while !bank3.is_complete() { - bank3.register_tick(&Hash::new_unique()); + bank3.register_unique_tick(); } let slot = slot + 1; let bank4 = Arc::new(Bank::new_from_parent(bank3, &collector, slot)); while !bank4.is_complete() { - bank4.register_tick(&Hash::new_unique()); + bank4.register_unique_tick(); } // Ensure account1 has been cleaned/purged from everywhere @@ -1917,13 +1917,13 @@ mod tests { let (genesis_config, mint_keypair) = create_genesis_config(sol_to_lamports(1_000_000.)); let bank0 = Arc::new(Bank::new_for_tests(&genesis_config)); while !bank0.is_complete() { - bank0.register_tick(&Hash::new_unique()); + bank0.register_unique_tick(); } let slot = 1; let bank1 = Arc::new(Bank::new_from_parent(bank0, &collector, slot)); while !bank1.is_complete() { - bank1.register_tick(&Hash::new_unique()); + bank1.register_unique_tick(); } let all_snapshots_dir = tempfile::TempDir::new().unwrap(); @@ -1948,7 +1948,7 @@ mod tests { .transfer(sol_to_lamports(1.), &mint_keypair, &key1.pubkey()) .unwrap(); while !bank2.is_complete() { - bank2.register_tick(&Hash::new_unique()); + bank2.register_unique_tick(); } bank_to_incremental_snapshot_archive( diff --git a/scripts/check-dev-context-only-utils.sh b/scripts/check-dev-context-only-utils.sh index debb323db113c4..fb459f0759729d 100755 --- a/scripts/check-dev-context-only-utils.sh +++ b/scripts/check-dev-context-only-utils.sh @@ -29,6 +29,7 @@ source ci/rust-version.sh nightly # reason to bend dev-context-only-utils's original intention and that listed # package isn't part of released binaries. declare tainted_packages=( + solana-ledger-tool ) # convert to comma separeted (ref: https://stackoverflow.com/a/53839433)