diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 16183e1024..754bafd825 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -1352,7 +1352,7 @@ impl Default for AccountsDb { let mut bank_hashes = HashMap::new(); bank_hashes.insert(0, BankHashInfo::default()); AccountsDb { - accounts_index: AccountsIndex::default(), + accounts_index: AccountsIndex::new(crate::accounts_index::BINS_DEFAULT), storage: AccountStorage::default(), accounts_cache: AccountsCache::default(), sender_bg_hasher: None, diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index d9cc992e0b..cfa10708b4 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -32,7 +32,7 @@ use std::{ use thiserror::Error; pub const ITER_BATCH_SIZE: usize = 1000; -const BINS_DEFAULT: usize = 16; +pub const BINS_DEFAULT: usize = 16; const BINS_FOR_TESTING: usize = BINS_DEFAULT; pub type ScanResult = Result; pub type SlotList = Vec<(Slot, T)>; @@ -759,7 +759,7 @@ impl< Self::new(BINS_FOR_TESTING) } - fn new(bins: usize) -> Self { + pub fn new(bins: usize) -> Self { let (account_maps, bin_calculator) = Self::allocate_accounts_index(bins); Self { account_maps, @@ -3987,4 +3987,10 @@ pub mod tests { assert_eq!(iter.start_bin(), bins - 1); // start at highest possible pubkey, so bins - 1 assert_eq!(iter.end_bin_inclusive(), bins - 1); } + + #[test] + #[should_panic(expected = "bins.is_power_of_two()")] + fn test_illegal_bins() { + AccountsIndex::::new(3); + } }