Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 1704789

Browse files
authored
Define tick related helper test methods (#33537)
* Define tick related helper methods * dcou VoteSimulator * blacklist ledger-tool for dcou * fix dcou ci... * github
1 parent 0a38108 commit 1704789

12 files changed

+60
-38
lines changed

core/src/replay_stage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4834,7 +4834,7 @@ pub(crate) mod tests {
48344834
genesis_config.ticks_per_slot = 4;
48354835
let bank0 = Bank::new_for_tests(&genesis_config);
48364836
for _ in 0..genesis_config.ticks_per_slot {
4837-
bank0.register_tick(&Hash::default());
4837+
bank0.register_default_tick_for_test();
48384838
}
48394839
bank0.freeze();
48404840
let arc_bank0 = Arc::new(bank0);
@@ -4879,7 +4879,7 @@ pub(crate) mod tests {
48794879
&solana_sdk::pubkey::new_rand(),
48804880
);
48814881
for _ in 0..genesis_config.ticks_per_slot {
4882-
bank.register_tick(&Hash::default());
4882+
bank.register_default_tick_for_test();
48834883
}
48844884
bank_forks.write().unwrap().insert(bank);
48854885
let arc_bank = bank_forks.read().unwrap().get(i).unwrap();

core/src/vote_simulator.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg(feature = "dev-context-only-utils")]
12
use {
23
crate::{
34
cluster_info_vote_listener::VoteTracker,
@@ -117,7 +118,7 @@ impl VoteSimulator {
117118
}
118119
}
119120
while new_bank.tick_height() < new_bank.max_tick_height() {
120-
new_bank.register_tick(&Hash::new_unique());
121+
new_bank.register_unique_tick();
121122
}
122123
if !visit.node().has_no_child() || is_frozen {
123124
new_bank.freeze();
@@ -358,7 +359,7 @@ pub fn initialize_state(
358359
}
359360

360361
while bank0.tick_height() < bank0.max_tick_height() {
361-
bank0.register_tick(&Hash::new_unique());
362+
bank0.register_unique_tick();
362363
}
363364
bank0.freeze();
364365
let mut progress = ProgressMap::default();

core/tests/snapshots.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ fn goto_end_of_slot(bank: &Bank) {
310310
let mut tick_hash = bank.last_blockhash();
311311
loop {
312312
tick_hash = hashv(&[tick_hash.as_ref(), &[42]]);
313-
bank.register_tick(&tick_hash);
313+
bank.register_tick_for_test(&tick_hash);
314314
if tick_hash == bank.last_blockhash() {
315315
bank.freeze();
316316
return;
@@ -742,7 +742,7 @@ fn test_bank_forks_incremental_snapshot(
742742
assert_eq!(bank.process_transaction(&tx), Ok(()));
743743

744744
while !bank.is_complete() {
745-
bank.register_tick(&Hash::new_unique());
745+
bank.register_unique_tick();
746746
}
747747

748748
bank_forks.insert(bank)
@@ -1041,7 +1041,7 @@ fn test_snapshots_with_background_services(
10411041
assert_eq!(bank.process_transaction(&tx), Ok(()));
10421042

10431043
while !bank.is_complete() {
1044-
bank.register_tick(&Hash::new_unique());
1044+
bank.register_unique_tick();
10451045
}
10461046

10471047
bank_forks.write().unwrap().insert(bank);

ledger-tool/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ solana-logger = { workspace = true }
3939
solana-measure = { workspace = true }
4040
solana-program-runtime = { workspace = true }
4141
solana-rpc = { workspace = true }
42-
solana-runtime = { workspace = true }
42+
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
4343
solana-sdk = { workspace = true }
4444
solana-stake-program = { workspace = true }
4545
solana-storage-bigtable = { workspace = true }
@@ -57,6 +57,9 @@ jemallocator = { workspace = true }
5757
assert_cmd = { workspace = true }
5858
bytecount = { workspace = true }
5959

60+
[features]
61+
dev-context-only-utils = []
62+
6063
[target."cfg(unix)".dependencies]
6164
signal-hook = { workspace = true }
6265

ledger-tool/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3139,7 +3139,7 @@ fn main() {
31393139

31403140
if child_bank_required {
31413141
while !bank.is_complete() {
3142-
bank.register_tick(&Hash::new_unique());
3142+
bank.register_unique_tick();
31433143
}
31443144
}
31453145

ledger/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ features = ["lz4"]
7878
bs58 = { workspace = true }
7979
solana-account-decoder = { workspace = true }
8080
solana-logger = { workspace = true }
81+
solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
8182
spl-pod = { workspace = true }
8283
test-case = { workspace = true }
8384

ledger/src/blockstore_processor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3373,7 +3373,7 @@ pub mod tests {
33733373

33743374
let blockhash = bank.last_blockhash();
33753375
while blockhash == bank.last_blockhash() {
3376-
bank.register_tick(&Hash::default());
3376+
bank.register_default_tick_for_test();
33773377
}
33783378

33793379
// ensure bank can process 2 entries that do not have a common account and tick is registered

runtime/src/bank.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4208,6 +4208,22 @@ impl Bank {
42084208
self.tick_height.fetch_add(1, Relaxed);
42094209
}
42104210

4211+
#[cfg(feature = "dev-context-only-utils")]
4212+
pub fn register_tick_for_test(&self, hash: &Hash) {
4213+
// currently meaningless wrapper; upcoming pr will make it an actual helper...
4214+
self.register_tick(hash)
4215+
}
4216+
4217+
#[cfg(feature = "dev-context-only-utils")]
4218+
pub fn register_default_tick_for_test(&self) {
4219+
self.register_tick(&Hash::default())
4220+
}
4221+
4222+
#[cfg(feature = "dev-context-only-utils")]
4223+
pub fn register_unique_tick(&self) {
4224+
self.register_tick(&Hash::new_unique())
4225+
}
4226+
42114227
pub fn is_complete(&self) -> bool {
42124228
self.tick_height() == self.max_tick_height()
42134229
}

runtime/src/bank/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ fn test_race_register_tick_freeze() {
180180
let register_tick_thread = Builder::new()
181181
.name("register_tick".to_string())
182182
.spawn(move || {
183-
bank0_.register_tick(&hash);
183+
bank0_.register_tick_for_test(&hash);
184184
})
185185
.unwrap();
186186

@@ -4204,7 +4204,7 @@ fn test_is_delta_true() {
42044204
assert!(!bank1.is_delta.load(Relaxed));
42054205
assert_ne!(hash1, bank.hash());
42064206
// ticks don't make a bank into a delta or change its state unless a block boundary is crossed
4207-
bank1.register_tick(&Hash::default());
4207+
bank1.register_default_tick_for_test();
42084208
assert!(!bank1.is_delta.load(Relaxed));
42094209
assert_eq!(bank1.hash_internal_state(), hash1);
42104210
}
@@ -4928,7 +4928,7 @@ fn test_hash_internal_state_unchanged_with_ticks() {
49284928
// because blockhashes are only recorded at block boundaries
49294929
for _ in 0..genesis_config.ticks_per_slot {
49304930
assert_eq!(bank1.hash_internal_state(), hash1);
4931-
bank1.register_tick(&Hash::default());
4931+
bank1.register_default_tick_for_test();
49324932
}
49334933
assert_eq!(bank1.hash_internal_state(), hash1);
49344934
}

runtime/src/bank_forks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ mod tests {
696696
let bank = Bank::new_for_tests(&genesis_config);
697697
let mut bank_forks = BankForks::new(bank);
698698
let child_bank = Bank::new_from_parent(bank_forks[0].clone(), &Pubkey::default(), 1);
699-
child_bank.register_tick(&Hash::default());
699+
child_bank.register_default_tick_for_test();
700700
bank_forks.insert(child_bank);
701701
assert_eq!(bank_forks[1u64].tick_height(), 1);
702702
assert_eq!(bank_forks.working_bank().tick_height(), 1);

runtime/src/snapshot_bank_utils.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ mod tests {
12901290
let original_bank = Bank::new_for_tests(&genesis_config);
12911291

12921292
while !original_bank.is_complete() {
1293-
original_bank.register_tick(&Hash::new_unique());
1293+
original_bank.register_unique_tick();
12941294
}
12951295

12961296
let (_tmp_dir, accounts_dir) = create_tmp_accounts_dir_for_tests();
@@ -1359,7 +1359,7 @@ mod tests {
13591359
.transfer(sol_to_lamports(3.), &mint_keypair, &key3.pubkey())
13601360
.unwrap();
13611361
while !bank0.is_complete() {
1362-
bank0.register_tick(&Hash::new_unique());
1362+
bank0.register_unique_tick();
13631363
}
13641364

13651365
let slot = 1;
@@ -1374,7 +1374,7 @@ mod tests {
13741374
.transfer(sol_to_lamports(5.), &mint_keypair, &key5.pubkey())
13751375
.unwrap();
13761376
while !bank1.is_complete() {
1377-
bank1.register_tick(&Hash::new_unique());
1377+
bank1.register_unique_tick();
13781378
}
13791379

13801380
let slot = slot + 1;
@@ -1383,7 +1383,7 @@ mod tests {
13831383
.transfer(sol_to_lamports(1.), &mint_keypair, &key1.pubkey())
13841384
.unwrap();
13851385
while !bank2.is_complete() {
1386-
bank2.register_tick(&Hash::new_unique());
1386+
bank2.register_unique_tick();
13871387
}
13881388

13891389
let slot = slot + 1;
@@ -1392,7 +1392,7 @@ mod tests {
13921392
.transfer(sol_to_lamports(1.), &mint_keypair, &key1.pubkey())
13931393
.unwrap();
13941394
while !bank3.is_complete() {
1395-
bank3.register_tick(&Hash::new_unique());
1395+
bank3.register_unique_tick();
13961396
}
13971397

13981398
let slot = slot + 1;
@@ -1401,7 +1401,7 @@ mod tests {
14011401
.transfer(sol_to_lamports(1.), &mint_keypair, &key1.pubkey())
14021402
.unwrap();
14031403
while !bank4.is_complete() {
1404-
bank4.register_tick(&Hash::new_unique());
1404+
bank4.register_unique_tick();
14051405
}
14061406

14071407
let (_tmp_dir, accounts_dir) = create_tmp_accounts_dir_for_tests();
@@ -1476,7 +1476,7 @@ mod tests {
14761476
.transfer(sol_to_lamports(3.), &mint_keypair, &key3.pubkey())
14771477
.unwrap();
14781478
while !bank0.is_complete() {
1479-
bank0.register_tick(&Hash::new_unique());
1479+
bank0.register_unique_tick();
14801480
}
14811481

14821482
let slot = 1;
@@ -1491,7 +1491,7 @@ mod tests {
14911491
.transfer(sol_to_lamports(5.), &mint_keypair, &key5.pubkey())
14921492
.unwrap();
14931493
while !bank1.is_complete() {
1494-
bank1.register_tick(&Hash::new_unique());
1494+
bank1.register_unique_tick();
14951495
}
14961496

14971497
let (_tmp_dir, accounts_dir) = create_tmp_accounts_dir_for_tests();
@@ -1519,7 +1519,7 @@ mod tests {
15191519
.transfer(sol_to_lamports(1.), &mint_keypair, &key1.pubkey())
15201520
.unwrap();
15211521
while !bank2.is_complete() {
1522-
bank2.register_tick(&Hash::new_unique());
1522+
bank2.register_unique_tick();
15231523
}
15241524

15251525
let slot = slot + 1;
@@ -1528,7 +1528,7 @@ mod tests {
15281528
.transfer(sol_to_lamports(1.), &mint_keypair, &key1.pubkey())
15291529
.unwrap();
15301530
while !bank3.is_complete() {
1531-
bank3.register_tick(&Hash::new_unique());
1531+
bank3.register_unique_tick();
15321532
}
15331533

15341534
let slot = slot + 1;
@@ -1537,7 +1537,7 @@ mod tests {
15371537
.transfer(sol_to_lamports(1.), &mint_keypair, &key1.pubkey())
15381538
.unwrap();
15391539
while !bank4.is_complete() {
1540-
bank4.register_tick(&Hash::new_unique());
1540+
bank4.register_unique_tick();
15411541
}
15421542

15431543
let incremental_snapshot_archive_info = bank_to_incremental_snapshot_archive(
@@ -1597,7 +1597,7 @@ mod tests {
15971597
.transfer(sol_to_lamports(3.), &mint_keypair, &key3.pubkey())
15981598
.unwrap();
15991599
while !bank0.is_complete() {
1600-
bank0.register_tick(&Hash::new_unique());
1600+
bank0.register_unique_tick();
16011601
}
16021602

16031603
let slot = 1;
@@ -1612,7 +1612,7 @@ mod tests {
16121612
.transfer(sol_to_lamports(3.), &mint_keypair, &key3.pubkey())
16131613
.unwrap();
16141614
while !bank1.is_complete() {
1615-
bank1.register_tick(&Hash::new_unique());
1615+
bank1.register_unique_tick();
16161616
}
16171617

16181618
let (_tmp_dir, accounts_dir) = create_tmp_accounts_dir_for_tests();
@@ -1640,7 +1640,7 @@ mod tests {
16401640
.transfer(sol_to_lamports(1.), &mint_keypair, &key1.pubkey())
16411641
.unwrap();
16421642
while !bank2.is_complete() {
1643-
bank2.register_tick(&Hash::new_unique());
1643+
bank2.register_unique_tick();
16441644
}
16451645

16461646
let slot = slot + 1;
@@ -1649,7 +1649,7 @@ mod tests {
16491649
.transfer(sol_to_lamports(2.), &mint_keypair, &key2.pubkey())
16501650
.unwrap();
16511651
while !bank3.is_complete() {
1652-
bank3.register_tick(&Hash::new_unique());
1652+
bank3.register_unique_tick();
16531653
}
16541654

16551655
let slot = slot + 1;
@@ -1658,7 +1658,7 @@ mod tests {
16581658
.transfer(sol_to_lamports(3.), &mint_keypair, &key3.pubkey())
16591659
.unwrap();
16601660
while !bank4.is_complete() {
1661-
bank4.register_tick(&Hash::new_unique());
1661+
bank4.register_unique_tick();
16621662
}
16631663

16641664
bank_to_incremental_snapshot_archive(
@@ -1746,7 +1746,7 @@ mod tests {
17461746
.transfer(lamports_to_transfer, &mint_keypair, &key2.pubkey())
17471747
.unwrap();
17481748
while !bank0.is_complete() {
1749-
bank0.register_tick(&Hash::new_unique());
1749+
bank0.register_unique_tick();
17501750
}
17511751

17521752
let slot = 1;
@@ -1755,7 +1755,7 @@ mod tests {
17551755
.transfer(lamports_to_transfer, &key2, &key1.pubkey())
17561756
.unwrap();
17571757
while !bank1.is_complete() {
1758-
bank1.register_tick(&Hash::new_unique());
1758+
bank1.register_unique_tick();
17591759
}
17601760

17611761
let full_snapshot_slot = slot;
@@ -1794,7 +1794,7 @@ mod tests {
17941794
"Ensure Account1's balance is zero"
17951795
);
17961796
while !bank2.is_complete() {
1797-
bank2.register_tick(&Hash::new_unique());
1797+
bank2.register_unique_tick();
17981798
}
17991799

18001800
// Take an incremental snapshot and then do a roundtrip on the bank and ensure it
@@ -1844,13 +1844,13 @@ mod tests {
18441844
.transfer(lamports_to_transfer, &mint_keypair, &key2.pubkey())
18451845
.unwrap();
18461846
while !bank3.is_complete() {
1847-
bank3.register_tick(&Hash::new_unique());
1847+
bank3.register_unique_tick();
18481848
}
18491849

18501850
let slot = slot + 1;
18511851
let bank4 = Arc::new(Bank::new_from_parent(bank3, &collector, slot));
18521852
while !bank4.is_complete() {
1853-
bank4.register_tick(&Hash::new_unique());
1853+
bank4.register_unique_tick();
18541854
}
18551855

18561856
// Ensure account1 has been cleaned/purged from everywhere
@@ -1917,13 +1917,13 @@ mod tests {
19171917
let (genesis_config, mint_keypair) = create_genesis_config(sol_to_lamports(1_000_000.));
19181918
let bank0 = Arc::new(Bank::new_for_tests(&genesis_config));
19191919
while !bank0.is_complete() {
1920-
bank0.register_tick(&Hash::new_unique());
1920+
bank0.register_unique_tick();
19211921
}
19221922

19231923
let slot = 1;
19241924
let bank1 = Arc::new(Bank::new_from_parent(bank0, &collector, slot));
19251925
while !bank1.is_complete() {
1926-
bank1.register_tick(&Hash::new_unique());
1926+
bank1.register_unique_tick();
19271927
}
19281928

19291929
let all_snapshots_dir = tempfile::TempDir::new().unwrap();
@@ -1948,7 +1948,7 @@ mod tests {
19481948
.transfer(sol_to_lamports(1.), &mint_keypair, &key1.pubkey())
19491949
.unwrap();
19501950
while !bank2.is_complete() {
1951-
bank2.register_tick(&Hash::new_unique());
1951+
bank2.register_unique_tick();
19521952
}
19531953

19541954
bank_to_incremental_snapshot_archive(

scripts/check-dev-context-only-utils.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ source ci/rust-version.sh nightly
2929
# reason to bend dev-context-only-utils's original intention and that listed
3030
# package isn't part of released binaries.
3131
declare tainted_packages=(
32+
solana-ledger-tool
3233
)
3334

3435
# convert to comma separeted (ref: https://stackoverflow.com/a/53839433)

0 commit comments

Comments
 (0)