diff --git a/accounts-bench/src/main.rs b/accounts-bench/src/main.rs index 1b5169e860..ce224d37e4 100644 --- a/accounts-bench/src/main.rs +++ b/accounts-bench/src/main.rs @@ -109,11 +109,12 @@ fn main() { time.stop(); let mut time_store = Measure::start("hash using store"); let results_store = accounts.accounts_db.update_accounts_hash_with_index_option( - true, + false, false, solana_sdk::clock::Slot::default(), &ancestors, true, + None, ); time_store.stop(); if results != results_store { diff --git a/runtime/src/accounts_background_service.rs b/runtime/src/accounts_background_service.rs index c784f1c351..ef092255bd 100644 --- a/runtime/src/accounts_background_service.rs +++ b/runtime/src/accounts_background_service.rs @@ -122,14 +122,15 @@ impl SnapshotRequestHandler { flush_accounts_cache_time.stop(); let mut hash_time = Measure::start("hash_time"); - let mut hash_for_testing = None; snapshot_root_bank.update_accounts_hash_with_index_option( - !use_index_hash_calculation, + use_index_hash_calculation, test_hash_calculation, ); - if test_hash_calculation { - hash_for_testing = Some(snapshot_root_bank.get_accounts_hash()); - } + let hash_for_testing = if test_hash_calculation { + Some(snapshot_root_bank.get_accounts_hash()) + } else { + None + }; hash_time.stop(); let mut clean_time = Measure::start("clean_time"); diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 01fe2535fb..d06733c2dd 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -3665,11 +3665,12 @@ impl AccountsDb { simple_capitalization_enabled: bool, ) -> (Hash, u64) { self.update_accounts_hash_with_index_option( - false, + true, false, slot, ancestors, simple_capitalization_enabled, + None, ) } @@ -3680,11 +3681,12 @@ impl AccountsDb { simple_capitalization_enabled: bool, ) -> (Hash, u64) { self.update_accounts_hash_with_index_option( - false, + true, true, slot, ancestors, simple_capitalization_enabled, + None, ) } @@ -3774,12 +3776,12 @@ impl AccountsDb { fn calculate_accounts_hash_helper( &self, - do_not_use_index: bool, + use_index: bool, slot: Slot, ancestors: &Ancestors, simple_capitalization_enabled: bool, ) -> (Hash, u64) { - if do_not_use_index { + if !use_index { let combined_maps = self.get_snapshot_storages(slot); Self::calculate_accounts_hash_without_index( @@ -3795,14 +3797,15 @@ impl AccountsDb { pub fn update_accounts_hash_with_index_option( &self, - do_not_use_index: bool, + use_index: bool, debug_verify: bool, slot: Slot, ancestors: &Ancestors, simple_capitalization_enabled: bool, + expected_capitalization: Option, ) -> (Hash, u64) { let (hash, total_lamports) = self.calculate_accounts_hash_helper( - do_not_use_index, + use_index, slot, ancestors, simple_capitalization_enabled, @@ -3810,14 +3813,16 @@ impl AccountsDb { if debug_verify { // calculate the other way (store or non-store) and verify results match. let (hash_other, total_lamports_other) = self.calculate_accounts_hash_helper( - !do_not_use_index, + !use_index, slot, ancestors, simple_capitalization_enabled, ); - assert_eq!(hash, hash_other); - assert_eq!(total_lamports, total_lamports_other); + let success = hash == hash_other + && total_lamports == total_lamports_other + && total_lamports == expected_capitalization.unwrap_or(total_lamports); + assert!(success, "update_accounts_hash_with_index_option mismatch. hashes: {}, {}; lamports: {}, {}; expected lamports: {:?}, using index: {}, slot: {}", hash, hash_other, total_lamports, total_lamports_other, expected_capitalization, use_index, slot); } let mut bank_hashes = self.bank_hashes.write().unwrap(); let mut bank_hash_info = bank_hashes.get_mut(&slot).unwrap(); diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 83222d4a09..0d0565d5d3 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -4291,7 +4291,7 @@ impl Bank { pub fn update_accounts_hash_with_index_option( &self, - do_not_use_index: bool, + use_index: bool, debug_verify: bool, ) -> Hash { let (hash, total_lamports) = self @@ -4299,18 +4299,19 @@ impl Bank { .accounts .accounts_db .update_accounts_hash_with_index_option( - do_not_use_index, + use_index, debug_verify, self.slot(), &self.ancestors, self.simple_capitalization_enabled(), + Some(self.capitalization()), ); assert_eq!(total_lamports, self.capitalization()); hash } pub fn update_accounts_hash(&self) -> Hash { - self.update_accounts_hash_with_index_option(false, false) + self.update_accounts_hash_with_index_option(true, false) } /// A snapshot bank should be purged of 0 lamport accounts which are not part of the hash