Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Calculate accounts hash async in accounts background service (#12852)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakridge authored Oct 19, 2020
1 parent d5163c5 commit 456eae6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 6 additions & 1 deletion runtime/src/accounts_background_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ impl SnapshotRequestHandler {
status_cache_slot_deltas,
} = 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");
snapshot_root_bank.process_stale_slot_with_budget(0, SHRUNKEN_ACCOUNT_PER_INTERVAL);
shrink_time.stop();
Expand Down Expand Up @@ -97,7 +101,8 @@ impl SnapshotRequestHandler {
"purge_old_snapshots_time",
purge_old_snapshots_time.as_us(),
i64
)
),
("hash_time", hash_time.as_us(), i64),
);
snapshot_root_bank.block_height()
})
Expand Down
10 changes: 7 additions & 3 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,7 @@ impl AccountsDB {

fn calculate_accounts_hash(
&self,
slot: Slot,
ancestors: &Ancestors,
check_hash: bool,
) -> Result<(Hash, u64), BankHashVerificationError> {
Expand All @@ -1964,7 +1965,8 @@ impl AccountsDB {
let hashes: Vec<_> = keys
.par_iter()
.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];
if account_info.lamports != 0 {
self.storage
Expand Down Expand Up @@ -2032,7 +2034,9 @@ impl AccountsDB {
}

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_hash_info = bank_hashes.get_mut(&slot).unwrap();
bank_hash_info.snapshot_hash = hash;
Expand All @@ -2048,7 +2052,7 @@ impl AccountsDB {
use BankHashVerificationError::*;

let (calculated_hash, calculated_lamports) =
self.calculate_accounts_hash(ancestors, true)?;
self.calculate_accounts_hash(slot, ancestors, true)?;

if calculated_lamports != total_lamports {
warn!(
Expand Down
2 changes: 0 additions & 2 deletions runtime/src/bank_forks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ impl BankForks {
bank.squash();
is_root_bank_squashed = bank_slot == root;

bank.update_accounts_hash();

if self.snapshot_config.is_some() && snapshot_request_sender.is_some() {
let snapshot_root_bank = self.root_bank().clone();
let root_slot = snapshot_root_bank.slot();
Expand Down

0 comments on commit 456eae6

Please sign in to comment.