From 435d4aded9437ecd24f46b1de80ea66d21c47684 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Wed, 5 Oct 2022 19:42:06 -0700 Subject: [PATCH] run initial hash calc in background, using background threads (#28239) --- runtime/benches/accounts.rs | 1 + runtime/src/accounts.rs | 2 ++ runtime/src/accounts_db.rs | 19 +++++++++++++++---- runtime/src/bank.rs | 4 ++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/runtime/benches/accounts.rs b/runtime/benches/accounts.rs index 5fcdd00ba..360d3f2cf 100644 --- a/runtime/benches/accounts.rs +++ b/runtime/benches/accounts.rs @@ -113,6 +113,7 @@ fn test_accounts_hash_bank_hash(bencher: &mut Bencher) { false, false, true, + false, )) }); } diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index c46df23aa..376631d85 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -834,6 +834,7 @@ impl Accounts { ignore_mismatch: bool, store_detailed_debug_info: bool, enable_rehashing: bool, + use_bg_thread_pool: bool, ) -> bool { if let Err(err) = self.accounts_db.verify_bank_hash_and_lamports_new( slot, @@ -845,6 +846,7 @@ impl Accounts { ignore_mismatch, store_detailed_debug_info, enable_rehashing, + use_bg_thread_pool, ) { warn!("verify_bank_hash failed: {:?}, slot: {}", err, slot); false diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index cef35a153..a4b5640dc 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -7513,6 +7513,7 @@ impl AccountsDb { epoch_schedule: &EpochSchedule, rent_collector: &RentCollector, enable_rehashing: bool, + use_bg_thread_pool: bool, ) -> Result<(), BankHashVerificationError> { self.verify_bank_hash_and_lamports_new( slot, @@ -7524,6 +7525,7 @@ impl AccountsDb { false, false, enable_rehashing, + use_bg_thread_pool, ) } @@ -7540,20 +7542,19 @@ impl AccountsDb { ignore_mismatch: bool, store_hash_raw_data_for_debug: bool, enable_rehashing: bool, + use_bg_thread_pool: bool, ) -> Result<(), BankHashVerificationError> { use BankHashVerificationError::*; let use_index = false; let check_hash = false; // this will not be supported anymore - // interesting to consider this - let is_startup = true; let (calculated_hash, calculated_lamports) = self .calculate_accounts_hash_helper_with_verify( use_index, test_hash_calculation, slot, CalcAccountsHashConfig { - use_bg_thread_pool: !is_startup, + use_bg_thread_pool, check_hash, ancestors: Some(ancestors), epoch_schedule, @@ -11843,6 +11844,7 @@ pub mod tests { &EpochSchedule::default(), &RentCollector::default(), true, + false, ) .unwrap(); } @@ -12247,6 +12249,7 @@ pub mod tests { &EpochSchedule::default(), &RentCollector::default(), true, + false, ), Ok(_) ); @@ -12261,6 +12264,7 @@ pub mod tests { &EpochSchedule::default(), &RentCollector::default(), true, + false, ), Err(MissingBankHash) ); @@ -12284,6 +12288,7 @@ pub mod tests { &EpochSchedule::default(), &RentCollector::default(), true, + false, ), Err(MismatchedBankHash) ); @@ -12313,6 +12318,7 @@ pub mod tests { &EpochSchedule::default(), &RentCollector::default(), true, + false, ), Ok(_) ); @@ -12335,12 +12341,13 @@ pub mod tests { &EpochSchedule::default(), &RentCollector::default(), true, + false, ), Ok(_) ); assert_matches!( - db.verify_bank_hash_and_lamports(some_slot, &ancestors, 10, true, &EpochSchedule::default(), &RentCollector::default(), true,), + db.verify_bank_hash_and_lamports(some_slot, &ancestors, 10, true, &EpochSchedule::default(), &RentCollector::default(), true, false,), Err(MismatchedTotalLamports(expected, actual)) if expected == 2 && actual == 10 ); } @@ -12368,6 +12375,7 @@ pub mod tests { &EpochSchedule::default(), &RentCollector::default(), true, + false, ), Ok(_) ); @@ -12412,6 +12420,7 @@ pub mod tests { &EpochSchedule::default(), &RentCollector::default(), true, + false, ), Err(MismatchedBankHash) ); @@ -13032,6 +13041,7 @@ pub mod tests { &EpochSchedule::default(), &RentCollector::default(), true, + false, ) .unwrap(); @@ -13045,6 +13055,7 @@ pub mod tests { &EpochSchedule::default(), &RentCollector::default(), true, + false, ) .unwrap(); diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 4b894ccb2..b9cb13f9e 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -7010,6 +7010,8 @@ impl Bank { config.ignore_mismatch, config.store_hash_raw_data_for_debug, enable_rehashing, + // true to run using bg thread pool + true, ); accounts_ .accounts_db @@ -7031,6 +7033,8 @@ impl Bank { config.ignore_mismatch, config.store_hash_raw_data_for_debug, enable_rehashing, + // fg is waiting for this to run, so we can use the fg thread pool + false, ); self.set_initial_accounts_hash_verification_completed(); result