AcctIdx: use ZeroLamport trait (#21552)
This commit is contained in:
parent
314605e149
commit
f0b32b75ab
|
@ -312,6 +312,12 @@ impl ZeroLamport for AccountInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ZeroLamport for AccountSharedData {
|
||||||
|
fn is_zero_lamport(&self) -> bool {
|
||||||
|
self.lamports() == 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct MultiThreadProgress<'a> {
|
struct MultiThreadProgress<'a> {
|
||||||
last_update: Instant,
|
last_update: Instant,
|
||||||
my_last_report_count: u64,
|
my_last_report_count: u64,
|
||||||
|
@ -833,8 +839,8 @@ pub struct BankHashStats {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BankHashStats {
|
impl BankHashStats {
|
||||||
pub fn update<T: ReadableAccount>(&mut self, account: &T) {
|
pub fn update<T: ReadableAccount + ZeroLamport>(&mut self, account: &T) {
|
||||||
if account.lamports() == 0 {
|
if account.is_zero_lamport() {
|
||||||
self.num_removed_accounts += 1;
|
self.num_removed_accounts += 1;
|
||||||
} else {
|
} else {
|
||||||
self.num_updated_accounts += 1;
|
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> {
|
impl<'a> ReadableAccount for StoredAccountMeta<'a> {
|
||||||
fn lamports(&self) -> u64 {
|
fn lamports(&self) -> u64 {
|
||||||
self.account_meta.lamports
|
self.account_meta.lamports
|
||||||
|
@ -4893,7 +4905,7 @@ impl AccountsDb {
|
||||||
>(
|
>(
|
||||||
&self,
|
&self,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
accounts: &[(&Pubkey, &impl ReadableAccount)],
|
accounts: &[(&Pubkey, &(impl ReadableAccount + ZeroLamport))],
|
||||||
hashes: Option<&[impl Borrow<Hash>]>,
|
hashes: Option<&[impl Borrow<Hash>]>,
|
||||||
storage_finder: F,
|
storage_finder: F,
|
||||||
mut write_version_producer: P,
|
mut write_version_producer: P,
|
||||||
|
@ -4907,7 +4919,7 @@ impl AccountsDb {
|
||||||
// this is the source of Some(Account) or None.
|
// this is the source of Some(Account) or None.
|
||||||
// Some(Account) = store 'Account'
|
// Some(Account) = store 'Account'
|
||||||
// None = store a default/empty account with 0 lamports
|
// 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)
|
(None, 0)
|
||||||
} else {
|
} else {
|
||||||
(Some(*account), account.data().len() as u64)
|
(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,
|
&'a self,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
accounts: &[(&Pubkey, &T)],
|
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,
|
&'a self,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
accounts: &[(&Pubkey, &T)],
|
accounts: &[(&Pubkey, &T)],
|
||||||
|
@ -8349,7 +8361,7 @@ pub mod tests {
|
||||||
{
|
{
|
||||||
account.checked_add_lamports(1).unwrap();
|
account.checked_add_lamports(1).unwrap();
|
||||||
accounts.store_uncached(slot, &[(&pubkeys[idx], &account)]);
|
accounts.store_uncached(slot, &[(&pubkeys[idx], &account)]);
|
||||||
if account.lamports() == 0 {
|
if account.is_zero_lamport() {
|
||||||
let ancestors = vec![(slot, 0)].into_iter().collect();
|
let ancestors = vec![(slot, 0)].into_iter().collect();
|
||||||
assert!(accounts
|
assert!(accounts
|
||||||
.load_without_fixed_root(&ancestors, &pubkeys[idx])
|
.load_without_fixed_root(&ancestors, &pubkeys[idx])
|
||||||
|
|
Loading…
Reference in New Issue