diff --git a/core/src/accounts_hash_verifier.rs b/core/src/accounts_hash_verifier.rs index 477de718e9..457b48faf2 100644 --- a/core/src/accounts_hash_verifier.rs +++ b/core/src/accounts_hash_verifier.rs @@ -129,6 +129,7 @@ impl AccountsHashVerifier { use_bg_thread_pool: true, check_hash: false, ancestors: None, + use_write_cache: false, }, timings, ) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 0be3cb1278..3afc8ab618 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -5518,6 +5518,7 @@ impl AccountsDb { use_bg_thread_pool: !is_startup, check_hash, ancestors: can_cached_slot_be_unflushed.then(|| ancestors), + use_write_cache: can_cached_slot_be_unflushed, }, timings, ); @@ -5533,6 +5534,7 @@ impl AccountsDb { use_bg_thread_pool: !is_startup, check_hash, ancestors: Some(ancestors), + use_write_cache: can_cached_slot_be_unflushed, }, ) } @@ -5760,9 +5762,15 @@ impl AccountsDb { PUBKEY_BINS_FOR_CALCULATING_HASHES, &bounds, config.check_hash, - config - .ancestors - .map(|a| (&self.accounts_cache, a, &self.accounts_index)), + // if we can use write cache, then pass Some(write cache, ancestors, index) + // otherwise, ancestors is irrelevant because storages were accumulated using ancestors already + (config.use_write_cache && config.ancestors.is_some()).then(|| { + ( + &self.accounts_cache, + config.ancestors.unwrap(), + &self.accounts_index, + ) + }), hash.filler_account_suffix.as_ref(), )?; @@ -7949,6 +7957,7 @@ pub mod tests { use_bg_thread_pool: false, check_hash: false, ancestors: None, + use_write_cache: false, }, HashStats::default(), ) @@ -7975,6 +7984,7 @@ pub mod tests { use_bg_thread_pool: false, check_hash: false, ancestors: None, + use_write_cache: false, }, HashStats::default(), ) diff --git a/runtime/src/accounts_hash.rs b/runtime/src/accounts_hash.rs index 8eeed4eeda..372b349a69 100644 --- a/runtime/src/accounts_hash.rs +++ b/runtime/src/accounts_hash.rs @@ -22,14 +22,17 @@ pub struct PreviousPass { /// parameters to calculate accounts hash pub struct CalcAccountsHashConfig<'a> { pub storages: &'a SortedStorages<'a>, + /// true to use a thread pool dedicated to bg operations pub use_bg_thread_pool: bool, + /// verify every hash in append vec/write cache with a recalculated hash + /// this option will be removed pub check_hash: bool, + /// 'ancestors' is used to get storages and also used if 'use_write_cache' is true to + /// get account data from the write cache pub ancestors: Option<&'a Ancestors>, - // to come soon - /* - pub rent_collector: RentCollector, - pub epoch_schedule: EpochSchedule, - */ + /// does hash calc need to consider account data that exists in the write cache? + /// if so, 'ancestors' will be used for this purpose as well as storages. + pub use_write_cache: bool, } // smallest, 3 quartiles, largest, average