diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index 8d35f1f1f05bbd..2620521d4286fe 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -7452,6 +7452,27 @@ impl AccountsDb { (hashes, scan.as_us(), accumulate) } + /// Return all of the accounts for a given slot + pub fn get_pubkey_account_for_slot(&self, slot: Slot) -> Vec<(Pubkey, AccountSharedData)> { + let scan_result = self.scan_account_storage( + slot, + |loaded_account| { + // Cache only has one version per key, don't need to worry about versioning + Some((*loaded_account.pubkey(), loaded_account.take_account())) + }, + |accum: &DashMap<_, _>, loaded_account, _data| { + // Storage may have duplicates so only keep the latest version for each key + accum.insert(*loaded_account.pubkey(), loaded_account.take_account()); + }, + ScanAccountStorageData::NoData, + ); + + match scan_result { + ScanStorageResult::Cached(cached_result) => cached_result, + ScanStorageResult::Stored(stored_result) => stored_result.into_iter().collect(), + } + } + /// Return all of the accounts for a given slot pub fn get_pubkey_hash_account_for_slot(&self, slot: Slot) -> Vec { type ScanResult = diff --git a/runtime/src/bank/accounts_lt_hash.rs b/runtime/src/bank/accounts_lt_hash.rs index 260eafa8827f70..814106533e972b 100644 --- a/runtime/src/bank/accounts_lt_hash.rs +++ b/runtime/src/bank/accounts_lt_hash.rs @@ -82,7 +82,7 @@ impl Bank { self.rc .accounts .accounts_db - .get_pubkey_hash_account_for_slot(slot) + .get_pubkey_account_for_slot(slot) }); let num_accounts_total = accounts_curr.len(); @@ -118,10 +118,7 @@ impl Bank { .fold_chunks( CHUNK_SIZE, || (LtHash::identity(), Stats::default()), - |mut accum, elem| { - let pubkey = &elem.pubkey; - let curr_account = &elem.account; - + |mut accum, (pubkey, curr_account)| { // load the initial state of the account let (initial_state_of_account, measure_load) = meas_dur!({ match cache_for_accounts_lt_hash.get(pubkey) {