From 22007a3c96124691395b73b746fa328b2d869a40 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Wed, 7 Sep 2022 10:16:52 -0700 Subject: [PATCH] allow accounts hash calc to specify enable_rehashing (#27615) --- core/src/accounts_hash_verifier.rs | 5 ++ runtime/src/accounts_background_service.rs | 1 + runtime/src/accounts_db.rs | 58 +++++++++++++--------- runtime/src/accounts_hash.rs | 2 + 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/core/src/accounts_hash_verifier.rs b/core/src/accounts_hash_verifier.rs index 15e61e374..33bf4e3f2 100644 --- a/core/src/accounts_hash_verifier.rs +++ b/core/src/accounts_hash_verifier.rs @@ -130,6 +130,8 @@ impl AccountsHashVerifier { }; timings.calc_storage_size_quartiles(&accounts_package.snapshot_storages); + let enable_rehashing = true; + let (accounts_hash, lamports) = accounts_package .accounts .accounts_db @@ -143,6 +145,7 @@ impl AccountsHashVerifier { rent_collector: &accounts_package.rent_collector, store_detailed_debug_info_on_failure: false, full_snapshot: None, + enable_rehashing, }, &sorted_storages, timings, @@ -166,6 +169,7 @@ impl AccountsHashVerifier { rent_collector: &accounts_package.rent_collector, store_detailed_debug_info_on_failure: false, full_snapshot: None, + enable_rehashing, }, ); info!( @@ -186,6 +190,7 @@ impl AccountsHashVerifier { // now that we've failed, store off the failing contents that produced a bad capitalization store_detailed_debug_info_on_failure: true, full_snapshot: None, + enable_rehashing, }, &sorted_storages, HashStats::default(), diff --git a/runtime/src/accounts_background_service.rs b/runtime/src/accounts_background_service.rs index 59f381ce1..7b70980dc 100644 --- a/runtime/src/accounts_background_service.rs +++ b/runtime/src/accounts_background_service.rs @@ -195,6 +195,7 @@ impl SnapshotRequestHandler { rent_collector: snapshot_root_bank.rent_collector(), store_detailed_debug_info_on_failure: false, full_snapshot: None, + enable_rehashing: true, }, ).unwrap(); assert_eq!(previous_hash, this_hash); diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 366b079d6..44da3a11f 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -1840,18 +1840,24 @@ impl<'a, T: Fn(Slot) -> Option + Sync + Send + Clone> AppendVecScan for Sc let balance = loaded_account.lamports(); let loaded_hash = loaded_account.loaded_hash(); - let new_hash = ExpectedRentCollection::maybe_rehash_skipped_rewrite( - loaded_account, - &loaded_hash, - pubkey, - self.current_slot, - self.config.epoch_schedule, - self.config.rent_collector, - self.stats, - &self.max_slot_info, - self.find_unskipped_slot, - self.filler_account_suffix, - ); + let new_hash = self + .config + .enable_rehashing + .then(|| { + ExpectedRentCollection::maybe_rehash_skipped_rewrite( + loaded_account, + &loaded_hash, + pubkey, + self.current_slot, + self.config.epoch_schedule, + self.config.rent_collector, + self.stats, + &self.max_slot_info, + self.find_unskipped_slot, + self.filler_account_suffix, + ) + }) + .flatten(); let loaded_hash = new_hash.unwrap_or(loaded_hash); let source_item = CalculateHashIntermediate::new(loaded_hash, balance, *pubkey); @@ -6433,18 +6439,19 @@ impl AccountsDb { self.find_unskipped_slot(slot, config.ancestors) }; let loaded_hash = loaded_account.loaded_hash(); - let new_hash = ExpectedRentCollection::maybe_rehash_skipped_rewrite( - &loaded_account, - &loaded_hash, - pubkey, - *slot, - config.epoch_schedule, - config.rent_collector, - &stats, - &max_slot_info, - find_unskipped_slot, - self.filler_account_suffix.as_ref(), - ); + let new_hash = config.enable_rehashing + .then(|| ExpectedRentCollection::maybe_rehash_skipped_rewrite( + &loaded_account, + &loaded_hash, + pubkey, + *slot, + config.epoch_schedule, + config.rent_collector, + &stats, + &max_slot_info, + find_unskipped_slot, + self.filler_account_suffix.as_ref(), + )).flatten(); let loaded_hash = new_hash.unwrap_or(loaded_hash); let balance = loaded_account.lamports(); if config.check_hash && !self.is_filler_account(pubkey) { // this will not be supported anymore @@ -6997,6 +7004,7 @@ impl AccountsDb { rent_collector, store_detailed_debug_info_on_failure: false, full_snapshot: None, + enable_rehashing: true, }, expected_capitalization, ) @@ -7295,6 +7303,7 @@ impl AccountsDb { rent_collector, store_detailed_debug_info_on_failure: store_hash_raw_data_for_debug, full_snapshot: None, + enable_rehashing: true, }, None, )?; @@ -11911,6 +11920,7 @@ pub mod tests { rent_collector: &RENT_COLLECTOR, store_detailed_debug_info_on_failure: false, full_snapshot: None, + enable_rehashing: true, } } } diff --git a/runtime/src/accounts_hash.rs b/runtime/src/accounts_hash.rs index c86e07eae..58b1ab4ef 100644 --- a/runtime/src/accounts_hash.rs +++ b/runtime/src/accounts_hash.rs @@ -54,6 +54,8 @@ pub struct CalcAccountsHashConfig<'a> { pub rent_collector: &'a RentCollector, /// used for tracking down hash mismatches after the fact pub store_detailed_debug_info_on_failure: bool, + /// true if hash calculation can rehash based on skipped rewrites + pub enable_rehashing: bool, /// `Some` if this is an incremental snapshot which only hashes slots since the base full snapshot pub full_snapshot: Option, }