pass expected capitalization to hash calculation to improve assert msg (#15191) (#15248)

* cleanup if

        * pass expected capitalization to hash calculation to improve assert message

        * fix bank function

        * one more level

        * calculate_accounts_hash_helper

        * add slot to error message

        * success

        (cherry picked from commit e59a24d9f9)

Co-authored-by: Jeff Washington (jwash) <wash678@gmail.com>
This commit is contained in:
mergify[bot]
2021-02-24 17:13:16 +00:00
committed by GitHub
parent abfae5d46a
commit 7f9d5ac383
4 changed files with 26 additions and 18 deletions

View File

@ -109,11 +109,12 @@ fn main() {
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_with_index_option( let results_store = accounts.accounts_db.update_accounts_hash_with_index_option(
true, false,
false, false,
solana_sdk::clock::Slot::default(), solana_sdk::clock::Slot::default(),
&ancestors, &ancestors,
true, true,
None,
); );
time_store.stop(); time_store.stop();
if results != results_store { if results != results_store {

View File

@ -122,14 +122,15 @@ impl SnapshotRequestHandler {
flush_accounts_cache_time.stop(); flush_accounts_cache_time.stop();
let mut hash_time = Measure::start("hash_time"); let mut hash_time = Measure::start("hash_time");
let mut hash_for_testing = None;
snapshot_root_bank.update_accounts_hash_with_index_option( snapshot_root_bank.update_accounts_hash_with_index_option(
!use_index_hash_calculation, use_index_hash_calculation,
test_hash_calculation, test_hash_calculation,
); );
if test_hash_calculation { let hash_for_testing = if test_hash_calculation {
hash_for_testing = Some(snapshot_root_bank.get_accounts_hash()); Some(snapshot_root_bank.get_accounts_hash())
} } else {
None
};
hash_time.stop(); hash_time.stop();
let mut clean_time = Measure::start("clean_time"); let mut clean_time = Measure::start("clean_time");

View File

@ -3665,11 +3665,12 @@ impl AccountsDb {
simple_capitalization_enabled: bool, simple_capitalization_enabled: bool,
) -> (Hash, u64) { ) -> (Hash, u64) {
self.update_accounts_hash_with_index_option( self.update_accounts_hash_with_index_option(
false, true,
false, false,
slot, slot,
ancestors, ancestors,
simple_capitalization_enabled, simple_capitalization_enabled,
None,
) )
} }
@ -3680,11 +3681,12 @@ impl AccountsDb {
simple_capitalization_enabled: bool, simple_capitalization_enabled: bool,
) -> (Hash, u64) { ) -> (Hash, u64) {
self.update_accounts_hash_with_index_option( self.update_accounts_hash_with_index_option(
false, true,
true, true,
slot, slot,
ancestors, ancestors,
simple_capitalization_enabled, simple_capitalization_enabled,
None,
) )
} }
@ -3774,12 +3776,12 @@ impl AccountsDb {
fn calculate_accounts_hash_helper( fn calculate_accounts_hash_helper(
&self, &self,
do_not_use_index: bool, use_index: bool,
slot: Slot, slot: Slot,
ancestors: &Ancestors, ancestors: &Ancestors,
simple_capitalization_enabled: bool, simple_capitalization_enabled: bool,
) -> (Hash, u64) { ) -> (Hash, u64) {
if do_not_use_index { if !use_index {
let combined_maps = self.get_snapshot_storages(slot); let combined_maps = self.get_snapshot_storages(slot);
Self::calculate_accounts_hash_without_index( Self::calculate_accounts_hash_without_index(
@ -3795,14 +3797,15 @@ impl AccountsDb {
pub fn update_accounts_hash_with_index_option( pub fn update_accounts_hash_with_index_option(
&self, &self,
do_not_use_index: bool, use_index: bool,
debug_verify: bool, debug_verify: bool,
slot: Slot, slot: Slot,
ancestors: &Ancestors, ancestors: &Ancestors,
simple_capitalization_enabled: bool, simple_capitalization_enabled: bool,
expected_capitalization: Option<u64>,
) -> (Hash, u64) { ) -> (Hash, u64) {
let (hash, total_lamports) = self.calculate_accounts_hash_helper( let (hash, total_lamports) = self.calculate_accounts_hash_helper(
do_not_use_index, use_index,
slot, slot,
ancestors, ancestors,
simple_capitalization_enabled, simple_capitalization_enabled,
@ -3810,14 +3813,16 @@ impl AccountsDb {
if debug_verify { if debug_verify {
// calculate the other way (store or non-store) and verify results match. // calculate the other way (store or non-store) and verify results match.
let (hash_other, total_lamports_other) = self.calculate_accounts_hash_helper( let (hash_other, total_lamports_other) = self.calculate_accounts_hash_helper(
!do_not_use_index, !use_index,
slot, slot,
ancestors, ancestors,
simple_capitalization_enabled, simple_capitalization_enabled,
); );
assert_eq!(hash, hash_other); let success = hash == hash_other
assert_eq!(total_lamports, total_lamports_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_hashes = self.bank_hashes.write().unwrap();
let mut bank_hash_info = bank_hashes.get_mut(&slot).unwrap(); let mut bank_hash_info = bank_hashes.get_mut(&slot).unwrap();

View File

@ -4291,7 +4291,7 @@ impl Bank {
pub fn update_accounts_hash_with_index_option( pub fn update_accounts_hash_with_index_option(
&self, &self,
do_not_use_index: bool, use_index: bool,
debug_verify: bool, debug_verify: bool,
) -> Hash { ) -> Hash {
let (hash, total_lamports) = self let (hash, total_lamports) = self
@ -4299,18 +4299,19 @@ impl Bank {
.accounts .accounts
.accounts_db .accounts_db
.update_accounts_hash_with_index_option( .update_accounts_hash_with_index_option(
do_not_use_index, use_index,
debug_verify, debug_verify,
self.slot(), self.slot(),
&self.ancestors, &self.ancestors,
self.simple_capitalization_enabled(), self.simple_capitalization_enabled(),
Some(self.capitalization()),
); );
assert_eq!(total_lamports, self.capitalization()); assert_eq!(total_lamports, self.capitalization());
hash hash
} }
pub fn update_accounts_hash(&self) -> 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 /// A snapshot bank should be purged of 0 lamport accounts which are not part of the hash