diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 38af3072f3..96d0192f56 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -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(&mut self, account: &T) { - if account.lamports() == 0 { + pub fn update(&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]>, 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])