From 0b8d14b0fc19345411dabeface475d27a58779cb Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" <75863576+jeffwashington@users.noreply.github.com> Date: Wed, 4 Aug 2021 15:28:35 -0500 Subject: [PATCH] move towards account index being dynamically allocated (#19034) --- runtime/src/accounts_index.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index 81474243fe..fc91292829 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -676,15 +676,15 @@ pub struct AccountsIndex { pub removed_bank_ids: Mutex>, } -impl Default for AccountsIndex { +impl< + T: 'static + Clone + IsCached + ZeroLamport + std::marker::Sync + std::marker::Send + Debug, + > Default for AccountsIndex +{ fn default() -> Self { - let bins = BINS_DEFAULT; + let (account_maps, bin_calculator) = Self::allocate_accounts_index(BINS_DEFAULT); Self { - account_maps: (0..bins) - .into_iter() - .map(|_| RwLock::new(AccountMap::default())) - .collect::>(), - bin_calculator: PubkeyBinCalculator16::new(bins), + account_maps, + bin_calculator, program_id_index: SecondaryIndex::::new( "program_id_index_stats", ), @@ -705,6 +705,14 @@ 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() + .map(|_| RwLock::new(AccountMap::default())) + .collect::>(); + let bin_calculator = PubkeyBinCalculator16::new(bins); + (account_maps, bin_calculator) + } fn iter(&self, range: Option) -> AccountsIndexIterator where R: RangeBounds,