From 9ea627c16d7719227d50eb5ecf93f8698c688d4f Mon Sep 17 00:00:00 2001 From: HaoranYi Date: Tue, 2 Apr 2024 13:10:18 -0500 Subject: [PATCH] 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 --- accounts-db/src/accounts_db.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index 2684c44b93..53b8d1346b 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -7607,7 +7607,10 @@ impl AccountsDb { Some((*loaded_account.pubkey(), loaded_account.loaded_hash())) }, |accum: &DashMap, 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); }, ); @@ -7639,9 +7642,13 @@ impl AccountsDb { |accum: &DashMap, 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()), ); }, );