From dfe99efa7cfaa14390844e7c6cb6594eec3d1afc Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" <75863576+jeffwashington@users.noreply.github.com> Date: Wed, 4 Aug 2021 21:58:53 -0500 Subject: [PATCH] introduce AccountsIndex::default_for_tests() (#19067) --- runtime/src/accounts_index.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index c4e804c5ee..a5df9be5a0 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -33,6 +33,7 @@ use thiserror::Error; pub const ITER_BATCH_SIZE: usize = 1000; const BINS_DEFAULT: usize = 16; +const BINS_FOR_TESTING: usize = BINS_DEFAULT; pub type ScanResult = Result; pub type SlotList = Vec<(Slot, T)>; pub type SlotSlice<'s, T> = &'s [(Slot, T)]; @@ -681,7 +682,21 @@ impl< > Default for AccountsIndex { fn default() -> Self { - let (account_maps, bin_calculator) = Self::allocate_accounts_index(BINS_DEFAULT); + // all test callers will move to default_for_tests + Self::new(BINS_DEFAULT) + } +} + +impl< + T: 'static + Clone + IsCached + ZeroLamport + std::marker::Sync + std::marker::Send + Debug, + > AccountsIndex +{ + pub fn default_for_tests() -> Self { + Self::new(BINS_FOR_TESTING) + } + + fn new(bins: usize) -> Self { + let (account_maps, bin_calculator) = Self::allocate_accounts_index(bins); Self { account_maps, bin_calculator, @@ -699,12 +714,7 @@ impl< removed_bank_ids: Mutex::>::default(), } } -} -impl< - T: 'static + Clone + IsCached + ZeroLamport + std::marker::Sync + std::marker::Send + Debug, - > AccountsIndex -{ fn allocate_accounts_index(bins: usize) -> (LockMapType, PubkeyBinCalculator16) { let account_maps = (0..bins) .into_iter() @@ -713,6 +723,7 @@ impl< let bin_calculator = PubkeyBinCalculator16::new(bins); (account_maps, bin_calculator) } + fn iter(&self, range: Option) -> AccountsIndexIterator where R: RangeBounds,