calculate_accounts_hash_helper uses config (#24003)

This commit is contained in:
Jeff Washington (jwash) 2022-03-31 09:29:45 -05:00 committed by GitHub
parent 88326533ed
commit da001d54e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 65 deletions

View File

@ -125,12 +125,12 @@ impl AccountsHashVerifier {
.accounts_db .accounts_db
.calculate_accounts_hash_without_index( .calculate_accounts_hash_without_index(
&CalcAccountsHashConfig { &CalcAccountsHashConfig {
storages: &sorted_storages,
use_bg_thread_pool: true, use_bg_thread_pool: true,
check_hash: false, check_hash: false,
ancestors: None, ancestors: None,
use_write_cache: false, use_write_cache: false,
}, },
&sorted_storages,
timings, timings,
) )
.unwrap(); .unwrap();

View File

@ -5483,15 +5483,12 @@ impl AccountsDb {
&self, &self,
use_index: bool, use_index: bool,
slot: Slot, slot: Slot,
ancestors: &Ancestors, config: &CalcAccountsHashConfig<'_>,
check_hash: bool, // this will not be supported anymore
can_cached_slot_be_unflushed: bool,
slots_per_epoch: Option<Slot>, slots_per_epoch: Option<Slot>,
is_startup: bool,
) -> Result<(Hash, u64), BankHashVerificationError> { ) -> Result<(Hash, u64), BankHashVerificationError> {
if !use_index { if !use_index {
let mut collect_time = Measure::start("collect"); let mut collect_time = Measure::start("collect");
let (combined_maps, slots) = self.get_snapshot_storages(slot, None, Some(ancestors)); let (combined_maps, slots) = self.get_snapshot_storages(slot, None, config.ancestors);
collect_time.stop(); collect_time.stop();
let mut sort_time = Measure::start("sort_storages"); let mut sort_time = Measure::start("sort_storages");
@ -5512,31 +5509,14 @@ impl AccountsDb {
}; };
timings.calc_storage_size_quartiles(&combined_maps); timings.calc_storage_size_quartiles(&combined_maps);
let result = self.calculate_accounts_hash_without_index( let result = self.calculate_accounts_hash_without_index(config, &storages, timings);
&CalcAccountsHashConfig {
storages: &storages,
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,
);
// now that calculate_accounts_hash_without_index is complete, we can remove old roots // now that calculate_accounts_hash_without_index is complete, we can remove old roots
self.remove_old_roots(slot); self.remove_old_roots(slot);
result result
} else { } else {
self.calculate_accounts_hash( self.calculate_accounts_hash(slot, config)
slot,
&CalcAccountsHashConfig {
storages: &SortedStorages::empty(), // unused
use_bg_thread_pool: !is_startup,
check_hash,
ancestors: Some(ancestors),
use_write_cache: can_cached_slot_be_unflushed,
},
)
} }
} }
@ -5546,34 +5526,17 @@ impl AccountsDb {
use_index: bool, use_index: bool,
debug_verify: bool, debug_verify: bool,
slot: Slot, slot: Slot,
ancestors: &Ancestors, config: CalcAccountsHashConfig<'_>,
expected_capitalization: Option<u64>, expected_capitalization: Option<u64>,
can_cached_slot_be_unflushed: bool,
check_hash: bool,
slots_per_epoch: Option<Slot>, slots_per_epoch: Option<Slot>,
is_startup: bool,
) -> Result<(Hash, u64), BankHashVerificationError> { ) -> Result<(Hash, u64), BankHashVerificationError> {
let _guard = self.active_stats.activate(ActiveStatItem::Hash); let _guard = self.active_stats.activate(ActiveStatItem::Hash);
let (hash, total_lamports) = self.calculate_accounts_hash_helper( let (hash, total_lamports) =
use_index, self.calculate_accounts_hash_helper(use_index, slot, &config, slots_per_epoch)?;
slot,
ancestors,
check_hash,
can_cached_slot_be_unflushed,
slots_per_epoch,
is_startup,
)?;
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) =
!use_index, self.calculate_accounts_hash_helper(!use_index, slot, &config, None)?;
slot,
ancestors,
check_hash,
can_cached_slot_be_unflushed,
None,
is_startup,
)?;
let success = hash == hash_other let success = hash == hash_other
&& total_lamports == total_lamports_other && total_lamports == total_lamports_other
@ -5603,12 +5566,14 @@ impl AccountsDb {
use_index, use_index,
debug_verify, debug_verify,
slot, slot,
ancestors, CalcAccountsHashConfig {
use_bg_thread_pool: !is_startup,
check_hash,
ancestors: Some(ancestors),
use_write_cache: can_cached_slot_be_unflushed,
},
expected_capitalization, expected_capitalization,
can_cached_slot_be_unflushed,
check_hash,
slots_per_epoch, slots_per_epoch,
is_startup,
) )
.unwrap(); // unwrap here will never fail since check_hash = false .unwrap(); // unwrap here will never fail since check_hash = false
let mut bank_hashes = self.bank_hashes.write().unwrap(); let mut bank_hashes = self.bank_hashes.write().unwrap();
@ -5731,6 +5696,7 @@ impl AccountsDb {
pub fn calculate_accounts_hash_without_index( pub fn calculate_accounts_hash_without_index(
&self, &self,
config: &CalcAccountsHashConfig<'_>, config: &CalcAccountsHashConfig<'_>,
storages: &SortedStorages<'_>,
mut stats: HashStats, mut stats: HashStats,
) -> Result<(Hash, u64), BankHashVerificationError> { ) -> Result<(Hash, u64), BankHashVerificationError> {
let (num_hash_scan_passes, bins_per_pass) = Self::bins_per_pass(self.num_hash_scan_passes); let (num_hash_scan_passes, bins_per_pass) = Self::bins_per_pass(self.num_hash_scan_passes);
@ -5757,7 +5723,7 @@ impl AccountsDb {
let result = Self::scan_snapshot_stores_with_cache( let result = Self::scan_snapshot_stores_with_cache(
&cache_hash_data, &cache_hash_data,
config.storages, storages,
&mut stats, &mut stats,
PUBKEY_BINS_FOR_CALCULATING_HASHES, PUBKEY_BINS_FOR_CALCULATING_HASHES,
&bounds, &bounds,
@ -5787,7 +5753,7 @@ impl AccountsDb {
info!( info!(
"calculate_accounts_hash_without_index: slot (exclusive): {} {:?}", "calculate_accounts_hash_without_index: slot (exclusive): {} {:?}",
config.storages.range().end, storages.range().end,
final_result final_result
); );
Ok(final_result) Ok(final_result)
@ -5850,12 +5816,14 @@ impl AccountsDb {
use_index, use_index,
test_hash_calculation, test_hash_calculation,
slot, slot,
ancestors, CalcAccountsHashConfig {
use_bg_thread_pool: !is_startup,
check_hash,
ancestors: Some(ancestors),
use_write_cache: can_cached_slot_be_unflushed,
},
None, None,
can_cached_slot_be_unflushed,
check_hash,
None, // could use epoch_schedule.slots_per_epoch here None, // could use epoch_schedule.slots_per_epoch here
is_startup,
)?; )?;
if calculated_lamports != total_lamports { if calculated_lamports != total_lamports {
@ -7953,12 +7921,12 @@ pub mod tests {
let result = db let result = db
.calculate_accounts_hash_without_index( .calculate_accounts_hash_without_index(
&CalcAccountsHashConfig { &CalcAccountsHashConfig {
storages: &get_storage_refs(&storages),
use_bg_thread_pool: false, use_bg_thread_pool: false,
check_hash: false, check_hash: false,
ancestors: None, ancestors: None,
use_write_cache: false, use_write_cache: false,
}, },
&get_storage_refs(&storages),
HashStats::default(), HashStats::default(),
) )
.unwrap(); .unwrap();
@ -7980,12 +7948,12 @@ pub mod tests {
let result = db let result = db
.calculate_accounts_hash_without_index( .calculate_accounts_hash_without_index(
&CalcAccountsHashConfig { &CalcAccountsHashConfig {
storages: &get_storage_refs(&storages),
use_bg_thread_pool: false, use_bg_thread_pool: false,
check_hash: false, check_hash: false,
ancestors: None, ancestors: None,
use_write_cache: false, use_write_cache: false,
}, },
&get_storage_refs(&storages),
HashStats::default(), HashStats::default(),
) )
.unwrap(); .unwrap();
@ -9998,7 +9966,15 @@ pub mod tests {
for use_index in [true, false] { for use_index in [true, false] {
assert!(db assert!(db
.calculate_accounts_hash_helper( .calculate_accounts_hash_helper(
use_index, some_slot, &ancestors, check_hash, false, None, false, use_index,
some_slot,
&CalcAccountsHashConfig {
use_bg_thread_pool: true, // is_startup used to be false
check_hash,
ancestors: Some(&ancestors),
use_write_cache: false,
},
None
) )
.is_err()); .is_err());
} }
@ -10021,11 +9997,27 @@ pub mod tests {
let check_hash = true; let check_hash = true;
assert_eq!( assert_eq!(
db.calculate_accounts_hash_helper( db.calculate_accounts_hash_helper(
false, some_slot, &ancestors, check_hash, false, None, false, false,
some_slot,
&CalcAccountsHashConfig {
use_bg_thread_pool: true, // is_startup used to be false
check_hash,
ancestors: Some(&ancestors),
use_write_cache: false,
},
None,
) )
.unwrap(), .unwrap(),
db.calculate_accounts_hash_helper( db.calculate_accounts_hash_helper(
true, some_slot, &ancestors, check_hash, false, None, false, true,
some_slot,
&CalcAccountsHashConfig {
use_bg_thread_pool: true, // is_startup used to be false
check_hash,
ancestors: Some(&ancestors),
use_write_cache: false,
},
None,
) )
.unwrap(), .unwrap(),
); );

View File

@ -1,5 +1,5 @@
use { use {
crate::{accounts_db::SnapshotStorages, ancestors::Ancestors, sorted_storages::SortedStorages}, crate::{accounts_db::SnapshotStorages, ancestors::Ancestors},
log::*, log::*,
rayon::prelude::*, rayon::prelude::*,
solana_measure::measure::Measure, solana_measure::measure::Measure,
@ -20,8 +20,8 @@ pub struct PreviousPass {
} }
/// parameters to calculate accounts hash /// parameters to calculate accounts hash
#[derive(Debug)]
pub struct CalcAccountsHashConfig<'a> { pub struct CalcAccountsHashConfig<'a> {
pub storages: &'a SortedStorages<'a>,
/// true to use a thread pool dedicated to bg operations /// true to use a thread pool dedicated to bg operations
pub use_bg_thread_pool: bool, pub use_bg_thread_pool: bool,
/// verify every hash in append vec/write cache with a recalculated hash /// verify every hash in append vec/write cache with a recalculated hash