Use update_accounts_hash() in AccountsHashVerifier (#32830)
This commit is contained in:
parent
bf77a6c7f2
commit
ce57cac370
|
@ -125,7 +125,7 @@ fn main() {
|
||||||
.update_accounts_hash_for_tests(0, &ancestors, false, false);
|
.update_accounts_hash_for_tests(0, &ancestors, false, false);
|
||||||
time.stop();
|
time.stop();
|
||||||
let mut time_store = Measure::start("hash using store");
|
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,
|
CalcAccountsHashDataSource::Storages,
|
||||||
false,
|
false,
|
||||||
solana_sdk::clock::Slot::default(),
|
solana_sdk::clock::Slot::default(),
|
||||||
|
|
|
@ -7054,7 +7054,7 @@ impl AccountsDb {
|
||||||
debug_verify: bool,
|
debug_verify: bool,
|
||||||
is_startup: bool,
|
is_startup: bool,
|
||||||
) -> (AccountsHash, u64) {
|
) -> (AccountsHash, u64) {
|
||||||
self.update_accounts_hash(
|
self.update_accounts_hash_with_verify(
|
||||||
CalcAccountsHashDataSource::IndexForTests,
|
CalcAccountsHashDataSource::IndexForTests,
|
||||||
debug_verify,
|
debug_verify,
|
||||||
slot,
|
slot,
|
||||||
|
@ -7373,7 +7373,7 @@ impl AccountsDb {
|
||||||
|
|
||||||
/// run the accounts hash calculation and store the results
|
/// run the accounts hash calculation and store the results
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn update_accounts_hash(
|
pub fn update_accounts_hash_with_verify(
|
||||||
&self,
|
&self,
|
||||||
data_source: CalcAccountsHashDataSource,
|
data_source: CalcAccountsHashDataSource,
|
||||||
debug_verify: bool,
|
debug_verify: bool,
|
||||||
|
@ -7407,6 +7407,22 @@ impl AccountsDb {
|
||||||
(accounts_hash, total_lamports)
|
(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`
|
/// Calculate the incremental accounts hash for `storages` and save the results at `slot`
|
||||||
pub fn update_incremental_accounts_hash(
|
pub fn update_incremental_accounts_hash(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -396,25 +396,18 @@ impl AccountsHashVerifier {
|
||||||
include_slot_in_hash: accounts_package.include_slot_in_hash,
|
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
|
let ((accounts_hash, lamports), measure_hash_us) = measure_us!(accounts_package
|
||||||
.accounts
|
.accounts
|
||||||
.accounts_db
|
.accounts_db
|
||||||
.calculate_accounts_hash_from_storages(
|
.update_accounts_hash(
|
||||||
&calculate_accounts_hash_config,
|
&calculate_accounts_hash_config,
|
||||||
&sorted_storages,
|
&sorted_storages,
|
||||||
|
slot,
|
||||||
timings,
|
timings,
|
||||||
)
|
)
|
||||||
.unwrap()); // unwrap here will never fail since check_hash = false
|
.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 {
|
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.
|
// 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.
|
// 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.
|
||||||
|
|
|
@ -7279,7 +7279,7 @@ impl Bank {
|
||||||
self.rc
|
self.rc
|
||||||
.accounts
|
.accounts
|
||||||
.accounts_db
|
.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
|
// we have to use the index since the slot could be in the write cache still
|
||||||
CalcAccountsHashDataSource::IndexForTests,
|
CalcAccountsHashDataSource::IndexForTests,
|
||||||
debug_verify,
|
debug_verify,
|
||||||
|
@ -7385,7 +7385,11 @@ impl Bank {
|
||||||
mut debug_verify: bool,
|
mut debug_verify: bool,
|
||||||
is_startup: bool,
|
is_startup: bool,
|
||||||
) -> AccountsHash {
|
) -> AccountsHash {
|
||||||
let (accounts_hash, total_lamports) = self.rc.accounts.accounts_db.update_accounts_hash(
|
let (accounts_hash, total_lamports) = self
|
||||||
|
.rc
|
||||||
|
.accounts
|
||||||
|
.accounts_db
|
||||||
|
.update_accounts_hash_with_verify(
|
||||||
data_source,
|
data_source,
|
||||||
debug_verify,
|
debug_verify,
|
||||||
self.slot(),
|
self.slot(),
|
||||||
|
@ -7408,7 +7412,10 @@ impl Bank {
|
||||||
// cap mismatch detected. It has been logged to metrics above.
|
// cap mismatch detected. It has been logged to metrics above.
|
||||||
// Run both versions of the calculation to attempt to get more info.
|
// Run both versions of the calculation to attempt to get more info.
|
||||||
debug_verify = true;
|
debug_verify = true;
|
||||||
self.rc.accounts.accounts_db.update_accounts_hash(
|
self.rc
|
||||||
|
.accounts
|
||||||
|
.accounts_db
|
||||||
|
.update_accounts_hash_with_verify(
|
||||||
data_source,
|
data_source,
|
||||||
debug_verify,
|
debug_verify,
|
||||||
self.slot(),
|
self.slot(),
|
||||||
|
|
Loading…
Reference in New Issue