Calculate accounts hash async in accounts background service (#12852)

This commit is contained in:
sakridge
2020-10-19 09:48:29 -07:00
committed by GitHub
parent d5163c5786
commit 456eae6ccb
3 changed files with 13 additions and 6 deletions

View File

@ -51,6 +51,10 @@ impl SnapshotRequestHandler {
status_cache_slot_deltas, status_cache_slot_deltas,
} = snapshot_request; } = snapshot_request;
let mut hash_time = Measure::start("hash_time");
snapshot_root_bank.update_accounts_hash();
hash_time.stop();
let mut shrink_time = Measure::start("shrink_time"); let mut shrink_time = Measure::start("shrink_time");
snapshot_root_bank.process_stale_slot_with_budget(0, SHRUNKEN_ACCOUNT_PER_INTERVAL); snapshot_root_bank.process_stale_slot_with_budget(0, SHRUNKEN_ACCOUNT_PER_INTERVAL);
shrink_time.stop(); shrink_time.stop();
@ -97,7 +101,8 @@ impl SnapshotRequestHandler {
"purge_old_snapshots_time", "purge_old_snapshots_time",
purge_old_snapshots_time.as_us(), purge_old_snapshots_time.as_us(),
i64 i64
) ),
("hash_time", hash_time.as_us(), i64),
); );
snapshot_root_bank.block_height() snapshot_root_bank.block_height()
}) })

View File

@ -1953,6 +1953,7 @@ impl AccountsDB {
fn calculate_accounts_hash( fn calculate_accounts_hash(
&self, &self,
slot: Slot,
ancestors: &Ancestors, ancestors: &Ancestors,
check_hash: bool, check_hash: bool,
) -> Result<(Hash, u64), BankHashVerificationError> { ) -> Result<(Hash, u64), BankHashVerificationError> {
@ -1964,7 +1965,8 @@ impl AccountsDB {
let hashes: Vec<_> = keys let hashes: Vec<_> = keys
.par_iter() .par_iter()
.filter_map(|pubkey| { .filter_map(|pubkey| {
if let Some((list, index)) = accounts_index.get(pubkey, Some(ancestors), None) { if let Some((list, index)) = accounts_index.get(pubkey, Some(ancestors), Some(slot))
{
let (slot, account_info) = &list[index]; let (slot, account_info) = &list[index];
if account_info.lamports != 0 { if account_info.lamports != 0 {
self.storage self.storage
@ -2032,7 +2034,9 @@ impl AccountsDB {
} }
pub fn update_accounts_hash(&self, slot: Slot, ancestors: &Ancestors) -> (Hash, u64) { pub fn update_accounts_hash(&self, slot: Slot, ancestors: &Ancestors) -> (Hash, u64) {
let (hash, total_lamports) = self.calculate_accounts_hash(ancestors, false).unwrap(); let (hash, total_lamports) = self
.calculate_accounts_hash(slot, ancestors, false)
.unwrap();
let mut bank_hashes = self.bank_hashes.write().unwrap(); let mut bank_hashes = self.bank_hashes.write().unwrap();
let mut bank_hash_info = bank_hashes.get_mut(&slot).unwrap(); let mut bank_hash_info = bank_hashes.get_mut(&slot).unwrap();
bank_hash_info.snapshot_hash = hash; bank_hash_info.snapshot_hash = hash;
@ -2048,7 +2052,7 @@ impl AccountsDB {
use BankHashVerificationError::*; use BankHashVerificationError::*;
let (calculated_hash, calculated_lamports) = let (calculated_hash, calculated_lamports) =
self.calculate_accounts_hash(ancestors, true)?; self.calculate_accounts_hash(slot, ancestors, true)?;
if calculated_lamports != total_lamports { if calculated_lamports != total_lamports {
warn!( warn!(

View File

@ -216,8 +216,6 @@ impl BankForks {
bank.squash(); bank.squash();
is_root_bank_squashed = bank_slot == root; is_root_bank_squashed = bank_slot == root;
bank.update_accounts_hash();
if self.snapshot_config.is_some() && snapshot_request_sender.is_some() { if self.snapshot_config.is_some() && snapshot_request_sender.is_some() {
let snapshot_root_bank = self.root_bank().clone(); let snapshot_root_bank = self.root_bank().clone();
let root_slot = snapshot_root_bank.slot(); let root_slot = snapshot_root_bank.slot();