Skip to content

Commit

Permalink
do add/sub lt hash
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoranYi committed Feb 27, 2024
1 parent 3f05a77 commit 8107a48
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7979,8 +7979,12 @@ impl AccountsDb {
HashMap<Pubkey, (Option<AccountSharedData>, Option<AccountLTHash>)>,
>,
) {
// 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);
Expand All @@ -7995,15 +7999,19 @@ impl AccountsDb {
}
})
.collect::<Vec<_>>();

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);
});
}

Expand Down

0 comments on commit 8107a48

Please sign in to comment.