Skip to content

Commit

Permalink
log ancient zero lamport accounts in hash of all accounts (anza-xyz#2353
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jeffwashington authored Jul 30, 2024
1 parent e964ce3 commit 44469cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
23 changes: 18 additions & 5 deletions accounts-db/src/accounts_db/scan_account_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ trait AppendVecScan: Send + Sync + Clone {
/// return true if this pubkey should be included
fn filter(&mut self, pubkey: &Pubkey) -> bool;
/// set current slot of the scan
fn set_slot(&mut self, slot: Slot);
fn set_slot(&mut self, slot: Slot, is_ancient: bool);
/// found `account` in the append vec
fn found_account(&mut self, account: &LoadedAccount);
/// scanning is done
Expand All @@ -51,11 +51,14 @@ struct ScanState<'a> {
range: usize,
sort_time: Arc<AtomicU64>,
pubkey_to_bin_index: usize,
is_ancient: bool,
stats_num_zero_lamport_accounts_ancient: Arc<AtomicU64>,
}

impl<'a> AppendVecScan for ScanState<'a> {
fn set_slot(&mut self, slot: Slot) {
fn set_slot(&mut self, slot: Slot, is_ancient: bool) {
self.current_slot = slot;
self.is_ancient = is_ancient;
}
fn filter(&mut self, pubkey: &Pubkey) -> bool {
self.pubkey_to_bin_index = self.bin_calculator.bin_from_pubkey(pubkey);
Expand All @@ -82,6 +85,12 @@ impl<'a> AppendVecScan for ScanState<'a> {
let computed_hash = AccountsDb::hash_account(loaded_account, loaded_account.pubkey());
account_hash = computed_hash;
}

if balance == 0 && self.is_ancient {
self.stats_num_zero_lamport_accounts_ancient
.fetch_add(1, Ordering::Relaxed);
}

let source_item = CalculateHashIntermediate {
hash: account_hash,
lamports: balance,
Expand Down Expand Up @@ -135,6 +144,10 @@ impl AccountsDb {
bin_range,
sort_time: sort_time.clone(),
pubkey_to_bin_index: 0,
is_ancient: false,
stats_num_zero_lamport_accounts_ancient: Arc::clone(
&stats.num_zero_lamport_accounts_ancient,
),
};

let result = self.scan_account_storage_no_bank(
Expand Down Expand Up @@ -295,7 +308,7 @@ impl AccountsDb {
scanner.init_accum(range);
init_accum = false;
}
scanner.set_slot(slot);
scanner.set_slot(slot, ancient);

Self::scan_single_account_storage(storage, &mut scanner);
});
Expand Down Expand Up @@ -404,7 +417,7 @@ mod tests {
fn filter(&mut self, _pubkey: &Pubkey) -> bool {
true
}
fn set_slot(&mut self, slot: Slot) {
fn set_slot(&mut self, slot: Slot, _is_ancient: bool) {
self.current_slot = slot;
}
fn init_accum(&mut self, _count: usize) {}
Expand Down Expand Up @@ -434,7 +447,7 @@ mod tests {
}

impl AppendVecScan for TestScanSimple {
fn set_slot(&mut self, slot: Slot) {
fn set_slot(&mut self, slot: Slot, _is_ancient: bool) {
self.current_slot = slot;
}
fn filter(&mut self, _pubkey: &Pubkey) -> bool {
Expand Down
7 changes: 7 additions & 0 deletions accounts-db/src/accounts_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ pub struct HashStats {
pub count_ancient_scans: AtomicU64,
pub pubkey_bin_search_us: AtomicU64,
pub num_zero_lamport_accounts: AtomicU64,
pub num_zero_lamport_accounts_ancient: Arc<AtomicU64>,
}
impl HashStats {
pub fn calc_storage_size_quartiles(&mut self, storages: &[Arc<AccountStorageEntry>]) {
Expand Down Expand Up @@ -313,6 +314,12 @@ impl HashStats {
self.num_zero_lamport_accounts.load(Ordering::Relaxed),
i64
),
(
"num_zero_lamport_accounts_ancient",
self.num_zero_lamport_accounts_ancient
.load(Ordering::Relaxed),
i64
),
);
}
}
Expand Down

0 comments on commit 44469cd

Please sign in to comment.