Use update_accounts_hash() in AccountsHashVerifier (#32830)

This commit is contained in:
Brooks 2023-08-14 13:11:23 -04:00 committed by GitHub
parent bf77a6c7f2
commit ce57cac370
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 36 deletions

View File

@ -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(),

View File

@ -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,

View File

@ -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.

View File

@ -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!(