Skip to content

Commit

Permalink
AcctIdx: use ZeroLamport trait (solana-labs#21552)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington authored Dec 2, 2021
1 parent 314605e commit f0b32b7
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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)],
Expand All @@ -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)],
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit f0b32b7

Please sign in to comment.