AcctIdx: use ZeroLamport trait (#21552)

This commit is contained in:
Jeff Washington (jwash) 2021-12-02 12:10:11 -06:00 committed by GitHub
parent 314605e149
commit f0b32b75ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 7 deletions

View File

@ -312,6 +312,12 @@ impl ZeroLamport for AccountInfo {
}
}
impl ZeroLamport for AccountSharedData {
fn is_zero_lamport(&self) -> bool {
self.lamports() == 0
}
}
struct MultiThreadProgress<'a> {
last_update: Instant,
my_last_report_count: u64,
@ -833,8 +839,8 @@ pub struct BankHashStats {
}
impl BankHashStats {
pub fn update<T: ReadableAccount>(&mut self, account: &T) {
if account.lamports() == 0 {
pub fn update<T: ReadableAccount + ZeroLamport>(&mut self, account: &T) {
if account.is_zero_lamport() {
self.num_removed_accounts += 1;
} else {
self.num_updated_accounts += 1;
@ -1478,6 +1484,12 @@ impl solana_frozen_abi::abi_example::AbiExample for AccountsDb {
}
}
impl<'a> ZeroLamport for StoredAccountMeta<'a> {
fn is_zero_lamport(&self) -> bool {
self.lamports() == 0
}
}
impl<'a> ReadableAccount for StoredAccountMeta<'a> {
fn lamports(&self) -> u64 {
self.account_meta.lamports
@ -4893,7 +4905,7 @@ impl AccountsDb {
>(
&self,
slot: Slot,
accounts: &[(&Pubkey, &impl ReadableAccount)],
accounts: &[(&Pubkey, &(impl ReadableAccount + ZeroLamport))],
hashes: Option<&[impl Borrow<Hash>]>,
storage_finder: F,
mut write_version_producer: P,
@ -4907,7 +4919,7 @@ impl AccountsDb {
// this is the source of Some(Account) or None.
// Some(Account) = store 'Account'
// None = store a default/empty account with 0 lamports
let (account, data_len) = if account.lamports() == 0 {
let (account, data_len) = if account.is_zero_lamport() {
(None, 0)
} else {
(Some(*account), account.data().len() as u64)
@ -6381,7 +6393,7 @@ impl AccountsDb {
);
}
fn store_accounts_frozen<'a, T: ReadableAccount + Sync>(
fn store_accounts_frozen<'a, T: ReadableAccount + Sync + ZeroLamport>(
&'a self,
slot: Slot,
accounts: &[(&Pubkey, &T)],
@ -6405,7 +6417,7 @@ impl AccountsDb {
)
}
fn store_accounts_custom<'a, T: ReadableAccount + Sync>(
fn store_accounts_custom<'a, T: ReadableAccount + Sync + ZeroLamport>(
&'a self,
slot: Slot,
accounts: &[(&Pubkey, &T)],
@ -8349,7 +8361,7 @@ pub mod tests {
{
account.checked_add_lamports(1).unwrap();
accounts.store_uncached(slot, &[(&pubkeys[idx], &account)]);
if account.lamports() == 0 {
if account.is_zero_lamport() {
let ancestors = vec![(slot, 0)].into_iter().collect();
assert!(accounts
.load_without_fixed_root(&ancestors, &pubkeys[idx])