From eb1a04af65950b86b3e128d1611f218caabf2b17 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 3 Jun 2021 05:24:11 +0000 Subject: [PATCH] refactor SnapshotStorage helpers to prepare for later changes (#17560) (#17678) (cherry picked from commit 654918ab27000b71e8af024f374e5d6e3e00cce0) # Conflicts: # runtime/src/accounts_db.rs Co-authored-by: Jeff Washington (jwash) <75863576+jeffwashington@users.noreply.github.com> --- runtime/src/accounts_db.rs | 42 +++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 06e4fafc77..5e4344b141 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -5599,13 +5599,18 @@ pub mod tests { ancestors } + fn empty_storages<'a>() -> &'a [SnapshotStorage] { + &[] + } + #[test] #[should_panic(expected = "assertion failed: bins <= max_plus_1 && bins > 0")] fn test_accountsdb_scan_snapshot_stores_illegal_bins2() { let mut stats = HashStats::default(); let bounds = Range { start: 0, end: 0 }; - AccountsDb::scan_snapshot_stores(&[], &mut stats, 257, &bounds, false).unwrap(); + AccountsDb::scan_snapshot_stores(&empty_storages(), &mut stats, 257, &bounds, false) + .unwrap(); } #[test] #[should_panic(expected = "assertion failed: bins <= max_plus_1 && bins > 0")] @@ -5613,7 +5618,7 @@ pub mod tests { let mut stats = HashStats::default(); let bounds = Range { start: 0, end: 0 }; - AccountsDb::scan_snapshot_stores(&[], &mut stats, 0, &bounds, false).unwrap(); + AccountsDb::scan_snapshot_stores(&empty_storages(), &mut stats, 0, &bounds, false).unwrap(); } #[test] @@ -5624,7 +5629,7 @@ pub mod tests { let mut stats = HashStats::default(); let bounds = Range { start: 2, end: 2 }; - AccountsDb::scan_snapshot_stores(&[], &mut stats, 2, &bounds, false).unwrap(); + AccountsDb::scan_snapshot_stores(&empty_storages(), &mut stats, 2, &bounds, false).unwrap(); } #[test] #[should_panic( @@ -5634,7 +5639,7 @@ pub mod tests { let mut stats = HashStats::default(); let bounds = Range { start: 1, end: 3 }; - AccountsDb::scan_snapshot_stores(&[], &mut stats, 2, &bounds, false).unwrap(); + AccountsDb::scan_snapshot_stores(&empty_storages(), &mut stats, 2, &bounds, false).unwrap(); } #[test] @@ -5645,7 +5650,7 @@ pub mod tests { let mut stats = HashStats::default(); let bounds = Range { start: 1, end: 0 }; - AccountsDb::scan_snapshot_stores(&[], &mut stats, 2, &bounds, false).unwrap(); + AccountsDb::scan_snapshot_stores(&empty_storages(), &mut stats, 2, &bounds, false).unwrap(); } fn sample_storages_and_accounts() -> (SnapshotStorages, Vec) { @@ -5726,6 +5731,11 @@ pub mod tests { (storages, raw_expected) } + fn get_storage_refs(input: &[SnapshotStorage]) -> &[SnapshotStorage] { + // these types will be refactored later and this will be a convenient helper function for tests + input + } + #[test] fn test_accountsdb_scan_snapshot_stores() { solana_logger::setup(); @@ -5735,7 +5745,7 @@ pub mod tests { let mut stats = HashStats::default(); let result = AccountsDb::scan_snapshot_stores( - &storages, + &get_storage_refs(&storages), &mut stats, bins, &Range { @@ -5749,7 +5759,7 @@ pub mod tests { let bins = 2; let result = AccountsDb::scan_snapshot_stores( - &storages, + &get_storage_refs(&storages), &mut stats, bins, &Range { @@ -5768,7 +5778,7 @@ pub mod tests { let bins = 4; let result = AccountsDb::scan_snapshot_stores( - &storages, + &get_storage_refs(&storages), &mut stats, bins, &Range { @@ -5787,7 +5797,7 @@ pub mod tests { let bins = 256; let result = AccountsDb::scan_snapshot_stores( - &storages, + &get_storage_refs(&storages), &mut stats, bins, &Range { @@ -5811,7 +5821,7 @@ pub mod tests { let mut stats = HashStats::default(); let result = AccountsDb::scan_snapshot_stores( - &storages, + &get_storage_refs(&storages), &mut stats, bins, &Range { @@ -5835,7 +5845,7 @@ pub mod tests { // just the first bin of 2 let bins = 2; let result = AccountsDb::scan_snapshot_stores( - &storages, + &get_storage_refs(&storages), &mut stats, bins, &Range { @@ -5852,7 +5862,7 @@ pub mod tests { // just the second bin of 2 let result = AccountsDb::scan_snapshot_stores( - &storages, + &get_storage_refs(&storages), &mut stats, bins, &Range { @@ -5872,7 +5882,7 @@ pub mod tests { let bins = 4; for bin in 0..bins { let result = AccountsDb::scan_snapshot_stores( - &storages, + &get_storage_refs(&storages), &mut stats, bins, &Range { @@ -5891,7 +5901,7 @@ pub mod tests { let bin_locations = vec![0, 127, 128, 255]; for bin in 0..bins { let result = AccountsDb::scan_snapshot_stores( - &storages, + &get_storage_refs(&storages), &mut stats, bins, &Range { @@ -5917,7 +5927,7 @@ pub mod tests { let mut stats = HashStats::default(); let result = AccountsDb::scan_snapshot_stores( - &storages, + &get_storage_refs(&storages), &mut stats, bins, &Range { @@ -6003,7 +6013,7 @@ pub mod tests { let calls = AtomicU64::new(0); let result = AccountsDb::scan_account_storage_no_bank( - &storages, + &get_storage_refs(&storages), |loaded_account: LoadedAccount, accum: &mut Vec, slot: Slot| { calls.fetch_add(1, Ordering::Relaxed); assert_eq!(loaded_account.pubkey(), &pubkey);