Skip to content

Commit

Permalink
v1.18: Recompute hash on load if default hash is stored for the accou…
Browse files Browse the repository at this point in the history
…nt (backport of #519) (#546)

Recompute hash on load if default hash is stored for the account (#519)

recompute hash on load if default hash is stored for the account

Co-authored-by: HaoranYi <[email protected]>
(cherry picked from commit 9ea627c)

Co-authored-by: HaoranYi <[email protected]>
  • Loading branch information
2 people authored and yihau committed Apr 26, 2024
1 parent b22eb22 commit 51af2c8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7837,7 +7837,10 @@ impl AccountsDb {
Some((*loaded_account.pubkey(), loaded_account.loaded_hash()))
},
|accum: &DashMap<Pubkey, AccountHash>, loaded_account: LoadedAccount| {
let loaded_hash = loaded_account.loaded_hash();
let mut loaded_hash = loaded_account.loaded_hash();
if loaded_hash == AccountHash(Hash::default()) {
loaded_hash = Self::hash_account(&loaded_account, loaded_account.pubkey())
}
accum.insert(*loaded_account.pubkey(), loaded_hash);
},
);
Expand Down Expand Up @@ -7869,9 +7872,13 @@ impl AccountsDb {
|accum: &DashMap<Pubkey, (AccountHash, AccountSharedData)>,
loaded_account: LoadedAccount| {
// Storage may have duplicates so only keep the latest version for each key
let mut loaded_hash = loaded_account.loaded_hash();
if loaded_hash == AccountHash(Hash::default()) {
loaded_hash = Self::hash_account(&loaded_account, loaded_account.pubkey())
}
accum.insert(
*loaded_account.pubkey(),
(loaded_account.loaded_hash(), loaded_account.take_account()),
(loaded_hash, loaded_account.take_account()),
);
},
);
Expand Down

0 comments on commit 51af2c8

Please sign in to comment.