diff --git a/accounts-bench/src/main.rs b/accounts-bench/src/main.rs index a8305b4ab..8693a7c5b 100644 --- a/accounts-bench/src/main.rs +++ b/accounts-bench/src/main.rs @@ -108,11 +108,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 13eabeb64..fecbe1f5d 100644 --- a/runtime/src/accounts_background_service.rs +++ b/runtime/src/accounts_background_service.rs @@ -121,13 +121,14 @@ impl SnapshotRequestHandler { flush_accounts_cache_time.stop(); let mut hash_time = Measure::start("hash_time"); - let mut hash_for_testing = None; const USE_INDEX: bool = true; snapshot_root_bank - .update_accounts_hash_with_index_option(!USE_INDEX, test_hash_calculation); - if test_hash_calculation { - hash_for_testing = Some(snapshot_root_bank.get_accounts_hash()); - } + .update_accounts_hash_with_index_option(USE_INDEX, test_hash_calculation); + 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 62ad3330a..5bb28ea16 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -3624,11 +3624,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, ) } @@ -3639,11 +3640,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, ) } @@ -3866,12 +3868,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( @@ -3887,14 +3889,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, @@ -3902,14 +3905,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 22ecad88a..eee46d901 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -4280,7 +4280,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 @@ -4288,18 +4288,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