From 5cf28689e6c7272f7734a6b7e9add096caa5a4c3 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" <75863576+jeffwashington@users.noreply.github.com> Date: Thu, 5 Aug 2021 11:15:26 -0500 Subject: [PATCH] accounts_db calls AccountsDb::new(bins) (#19068) --- runtime/src/accounts_db.rs | 2 +- runtime/src/accounts_index.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) 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); + } }