From 8eba4d1698de7143efc9acbab09b9918cb682cc9 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Tue, 5 Jul 2022 18:01:02 -0500 Subject: [PATCH] add 2nd pass at hash calc when failure seen (#26392) --- core/src/accounts_hash_verifier.rs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/core/src/accounts_hash_verifier.rs b/core/src/accounts_hash_verifier.rs index 351b683d4..80bd1b1ed 100644 --- a/core/src/accounts_hash_verifier.rs +++ b/core/src/accounts_hash_verifier.rs @@ -147,6 +147,30 @@ impl AccountsHashVerifier { ) .unwrap(); + assert_eq!(accounts_package.expected_capitalization, lamports); + if let Some(expected_hash) = accounts_package.accounts_hash_for_testing { + // 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. + if expected_hash != accounts_hash { + let _ = accounts_package + .accounts + .accounts_db + .calculate_accounts_hash_without_index( + &CalcAccountsHashConfig { + use_bg_thread_pool: false, + check_hash: false, + ancestors: None, + use_write_cache: false, + epoch_schedule: &accounts_package.epoch_schedule, + rent_collector: &accounts_package.rent_collector, + }, + &sorted_storages, + HashStats::default(), + ); + } + assert_eq!(expected_hash, accounts_hash); + }; + accounts_package .accounts .accounts_db @@ -155,11 +179,6 @@ impl AccountsHashVerifier { &accounts_package.epoch_schedule, ); - assert_eq!(accounts_package.expected_capitalization, lamports); - if let Some(expected_hash) = accounts_package.accounts_hash_for_testing { - assert_eq!(expected_hash, accounts_hash); - }; - measure_hash.stop(); solana_runtime::serde_snapshot::reserialize_bank_with_new_accounts_hash( accounts_package.snapshot_links.path(),