From c0952831be0e4916a477613d76e2a28de5df5d8c Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" <75863576+jeffwashington@users.noreply.github.com> Date: Wed, 3 Nov 2021 11:27:15 -0500 Subject: [PATCH] correctly clean filler accounts (#21139) --- runtime/src/accounts_db.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index e3212f616e..c8e51ad854 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -5815,19 +5815,12 @@ impl AccountsDb { .scan_account_storage( slot, |loaded_account: LoadedAccount| { - if self.is_filler_account(loaded_account.pubkey()) { - None - } else { - // Cache only has one version per key, don't need to worry about versioning - Some((*loaded_account.pubkey(), loaded_account.loaded_hash())) - } + // Cache only has one version per key, don't need to worry about versioning + Some((*loaded_account.pubkey(), loaded_account.loaded_hash())) }, |accum: &DashMap, loaded_account: LoadedAccount| { let loaded_write_version = loaded_account.write_version(); let loaded_hash = loaded_account.loaded_hash(); - if self.is_filler_account(loaded_account.pubkey()) { - return; - } // keep the latest write version for each pubkey match accum.entry(*loaded_account.pubkey()) { Occupied(mut occupied_entry) => { @@ -5845,7 +5838,7 @@ impl AccountsDb { scan.stop(); let mut accumulate = Measure::start("accumulate"); - let hashes: Vec<_> = match scan_result { + let mut hashes: Vec<_> = match scan_result { ScanStorageResult::Cached(cached_result) => cached_result, ScanStorageResult::Stored(stored_result) => stored_result .into_iter() @@ -5854,6 +5847,11 @@ impl AccountsDb { }; let dirty_keys = hashes.iter().map(|(pubkey, _hash)| *pubkey).collect(); + if self.filler_accounts_enabled() { + // filler accounts must be added to 'dirty_keys' above but cannot be used to calculate hash + hashes.retain(|(pubkey, _hash)| !self.is_filler_account(pubkey)); + } + let ret = AccountsHash::accumulate_account_hashes(hashes); accumulate.stop(); let mut uncleaned_time = Measure::start("uncleaned_index"); @@ -6748,10 +6746,16 @@ impl AccountsDb { .unwrap_or_default() } + /// true if 'pubkey' is a filler account pub fn is_filler_account(&self, pubkey: &Pubkey) -> bool { Self::is_filler_account_helper(pubkey, self.filler_account_suffix.as_ref()) } + /// true if it is possible that there are filler accounts present + pub fn filler_accounts_enabled(&self) -> bool { + self.filler_account_suffix.is_some() + } + /// retain slots in 'roots' that are > (max(roots) - slots_per_epoch) fn retain_roots_within_one_epoch_range(roots: &mut Vec, slots_per_epoch: SlotCount) { if let Some(max) = roots.iter().max() {