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

* 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
This commit is contained in:
Jeff Washington (jwash)
2021-02-10 14:38:00 -06:00
committed by GitHub
parent c1e93b3ef9
commit e59a24d9f9
4 changed files with 26 additions and 18 deletions

View File

@@ -108,11 +108,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

@@ -121,13 +121,14 @@ 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;
const USE_INDEX: bool = true; const USE_INDEX: bool = true;
snapshot_root_bank snapshot_root_bank
.update_accounts_hash_with_index_option(!USE_INDEX, test_hash_calculation); .update_accounts_hash_with_index_option(USE_INDEX, 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

@@ -3624,11 +3624,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,
) )
} }
@@ -3639,11 +3640,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,
) )
} }
@@ -3866,12 +3868,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(
@@ -3887,14 +3889,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,
@@ -3902,14 +3905,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

@@ -4280,7 +4280,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
@@ -4288,18 +4288,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