From 8d4f2e6221ee8931f914ab38ca5487074bee10ec Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Sun, 21 Apr 2024 20:07:05 -0500 Subject: [PATCH] use scan_accounts to replace account_iter (#921) --- accounts-db/src/accounts_db.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index 1dbfddfd6b2a28..f2f4edbf4fae4a 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -6662,7 +6662,7 @@ impl AccountsDb { where S: AppendVecScan, { - storage.accounts.account_iter().for_each(|account| { + storage.accounts.scan_accounts(|account| { if scanner.filter(account.pubkey()) { scanner.found_account(&LoadedAccount::Stored(account)) } @@ -8806,7 +8806,7 @@ impl AccountsDb { // verify index matches expected and measure the time to get all items assert!(verify); let mut lookup_time = Measure::start("lookup_time"); - for account_info in storage.accounts.account_iter() { + storage.accounts.scan_accounts(|account_info| { let key = account_info.pubkey(); let index_entry = self.accounts_index.get_cloned(key).unwrap(); let slot_list = index_entry.slot_list.read().unwrap(); @@ -8825,7 +8825,7 @@ impl AccountsDb { } } assert_eq!(1, count); - } + }); lookup_time.stop(); lookup_time.as_us() }; @@ -9334,16 +9334,13 @@ impl AccountsDb { } pub fn sizes_of_accounts_in_storage_for_tests(&self, slot: Slot) -> Vec { - self.storage - .get_slot_storage_entry(slot) - .map(|storage| { - storage - .accounts - .account_iter() - .map(|account| account.stored_size()) - .collect() - }) - .unwrap_or_default() + let mut sizes = Vec::default(); + if let Some(storage) = self.storage.get_slot_storage_entry(slot) { + storage.accounts.scan_accounts(|account| { + sizes.push(account.stored_size()); + }); + } + sizes } pub fn ref_count_for_pubkey(&self, pubkey: &Pubkey) -> RefCount { @@ -17017,7 +17014,7 @@ pub mod tests { fn populate_index(db: &AccountsDb, slots: Range) { slots.into_iter().for_each(|slot| { if let Some(storage) = db.get_storage_for_slot(slot) { - storage.accounts.account_iter().for_each(|account| { + storage.accounts.scan_accounts(|account| { let info = AccountInfo::new( StorageLocation::AppendVec(storage.append_vec_id(), account.offset()), account.lamports(),