diff --git a/accounts-bench/src/main.rs b/accounts-bench/src/main.rs index fdff9ea8b..c7e75bc4c 100644 --- a/accounts-bench/src/main.rs +++ b/accounts-bench/src/main.rs @@ -125,7 +125,7 @@ fn main() { .update_accounts_hash_for_tests(0, &ancestors, false, false); time.stop(); let mut time_store = Measure::start("hash using store"); - let results_store = accounts.accounts_db.update_accounts_hash( + let results_store = accounts.accounts_db.update_accounts_hash_with_verify( CalcAccountsHashDataSource::Storages, false, solana_sdk::clock::Slot::default(), diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index 4c59a3856..591e70074 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -7054,7 +7054,7 @@ impl AccountsDb { debug_verify: bool, is_startup: bool, ) -> (AccountsHash, u64) { - self.update_accounts_hash( + self.update_accounts_hash_with_verify( CalcAccountsHashDataSource::IndexForTests, debug_verify, slot, @@ -7373,7 +7373,7 @@ impl AccountsDb { /// run the accounts hash calculation and store the results #[allow(clippy::too_many_arguments)] - pub fn update_accounts_hash( + pub fn update_accounts_hash_with_verify( &self, data_source: CalcAccountsHashDataSource, debug_verify: bool, @@ -7407,6 +7407,22 @@ impl AccountsDb { (accounts_hash, total_lamports) } + /// Calculate the full accounts hash for `storages` and save the results at `slot` + pub fn update_accounts_hash( + &self, + config: &CalcAccountsHashConfig<'_>, + storages: &SortedStorages<'_>, + slot: Slot, + stats: HashStats, + ) -> Result<(AccountsHash, /*capitalization*/ u64), AccountsHashVerificationError> { + let accounts_hash = self.calculate_accounts_hash_from_storages(config, storages, stats)?; + let old_accounts_hash = self.set_accounts_hash(slot, accounts_hash); + if let Some(old_accounts_hash) = old_accounts_hash { + warn!("Accounts hash was already set for slot {slot}! old: {old_accounts_hash:?}, new: {accounts_hash:?}"); + } + Ok(accounts_hash) + } + /// Calculate the incremental accounts hash for `storages` and save the results at `slot` pub fn update_incremental_accounts_hash( &self, diff --git a/core/src/accounts_hash_verifier.rs b/core/src/accounts_hash_verifier.rs index b09cd9001..cee3cf3c6 100644 --- a/core/src/accounts_hash_verifier.rs +++ b/core/src/accounts_hash_verifier.rs @@ -396,25 +396,18 @@ impl AccountsHashVerifier { include_slot_in_hash: accounts_package.include_slot_in_hash, }; + let slot = accounts_package.slot; let ((accounts_hash, lamports), measure_hash_us) = measure_us!(accounts_package .accounts .accounts_db - .calculate_accounts_hash_from_storages( + .update_accounts_hash( &calculate_accounts_hash_config, &sorted_storages, + slot, timings, ) .unwrap()); // unwrap here will never fail since check_hash = false - let slot = accounts_package.slot; - let old_accounts_hash = accounts_package - .accounts - .accounts_db - .set_accounts_hash(slot, (accounts_hash, lamports)); - if let Some(old_accounts_hash) = old_accounts_hash { - warn!("Accounts hash was already set for slot {slot}! old: {old_accounts_hash:?}, new: {accounts_hash:?}"); - } - if accounts_package.expected_capitalization != lamports { // before we assert, run the hash calc again. This helps track down whether it could have been a failure in a race condition possibly with shrink. // We could add diagnostics to the hash calc here to produce a per bin cap or something to help narrow down how many pubkeys are different. diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 80320a346..cc9b77aeb 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -7279,7 +7279,7 @@ impl Bank { self.rc .accounts .accounts_db - .update_accounts_hash( + .update_accounts_hash_with_verify( // we have to use the index since the slot could be in the write cache still CalcAccountsHashDataSource::IndexForTests, debug_verify, @@ -7385,17 +7385,21 @@ impl Bank { mut debug_verify: bool, is_startup: bool, ) -> AccountsHash { - let (accounts_hash, total_lamports) = self.rc.accounts.accounts_db.update_accounts_hash( - data_source, - debug_verify, - self.slot(), - &self.ancestors, - Some(self.capitalization()), - self.epoch_schedule(), - &self.rent_collector, - is_startup, - self.include_slot_in_hash(), - ); + let (accounts_hash, total_lamports) = self + .rc + .accounts + .accounts_db + .update_accounts_hash_with_verify( + data_source, + debug_verify, + self.slot(), + &self.ancestors, + Some(self.capitalization()), + self.epoch_schedule(), + &self.rent_collector, + is_startup, + self.include_slot_in_hash(), + ); if total_lamports != self.capitalization() { datapoint_info!( "capitalization_mismatch", @@ -7408,17 +7412,20 @@ impl Bank { // cap mismatch detected. It has been logged to metrics above. // Run both versions of the calculation to attempt to get more info. debug_verify = true; - self.rc.accounts.accounts_db.update_accounts_hash( - data_source, - debug_verify, - self.slot(), - &self.ancestors, - Some(self.capitalization()), - self.epoch_schedule(), - &self.rent_collector, - is_startup, - self.include_slot_in_hash(), - ); + self.rc + .accounts + .accounts_db + .update_accounts_hash_with_verify( + data_source, + debug_verify, + self.slot(), + &self.ancestors, + Some(self.capitalization()), + self.epoch_schedule(), + &self.rent_collector, + is_startup, + self.include_slot_in_hash(), + ); } panic!(