Skip to content

Commit

Permalink
Define tick related helper test methods (#33537)
Browse files Browse the repository at this point in the history
* Define tick related helper methods

* dcou VoteSimulator

* blacklist ledger-tool for dcou

* fix dcou ci...

* github
  • Loading branch information
ryoqun authored Oct 10, 2023
1 parent 0a38108 commit 1704789
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 38 deletions.
4 changes: 2 additions & 2 deletions core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions core/src/vote_simulator.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(feature = "dev-context-only-utils")]
use {
crate::{
cluster_info_vote_listener::VoteTracker,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions core/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion ledger-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3139,7 +3139,7 @@ fn main() {

if child_bank_required {
while !bank.is_complete() {
bank.register_tick(&Hash::new_unique());
bank.register_unique_tick();
}
}

Expand Down
1 change: 1 addition & 0 deletions ledger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
6 changes: 3 additions & 3 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank_forks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
48 changes: 24 additions & 24 deletions runtime/src/snapshot_bank_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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(
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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(
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions scripts/check-dev-context-only-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1704789

Please sign in to comment.