diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index 47995e5a073a9f..b1fee862250f7f 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -7979,8 +7979,12 @@ impl AccountsDb { HashMap, Option)>, >, ) { - // we are assuming it was easy to lookup a hash for everything written in `slot` when we were calculating the delta hash. So, caller passes in `pubkey_hash` - // note we don't need rewrites in `pubkey_hash`. these accounts had the same hash before and after. So, we only have to consider what was written that changed. + // We are assuming it was easy to lookup a hash for everything written + // in `slot` when we were calculating the delta hash. So, caller passes + // in `pubkey_hash`. Note we don't need rewrites in `pubkey_hash`. these + // accounts had the same hash before and after. So, we only have to + // consider what was written that changed. + let curr_ancestor = ancestors.clone(); ancestors.remove(&slot); let old_written_accounts = old_written_accounts.read().unwrap(); // if we want to look it up ourselves: let (hashes, _scan_us, _accumulate) = self.get_pubkey_hash_for_slot(slot); @@ -7995,15 +7999,19 @@ impl AccountsDb { } }) .collect::>(); + pubkey_hash .into_iter() .zip(old.into_iter()) - .for_each(|((k, new_hash), old_hash)| { + .for_each(|((k, _new_hash), old_hash)| { if let Some(old) = old_hash { // todo if old == new, then we can avoid this update altogether - // todo subtract accumulated_accounts_hash -= old_hash + accumulated_accounts_hash.sub(&old); } - // todo add accumulated_accounts_hash += new_hash + let new = self + .load_with_fixed_root(&curr_ancestors, &k) + .map(|(account, _)| Self::lt_hash_account(&account, &k)); + accumulated_accounts_hash.add(&new); }); }