some ReadableAccount changes (#16688)

* some ReadableAccount changes

* deref
This commit is contained in:
Jeff Washington (jwash)
2021-04-21 12:20:37 -05:00
committed by GitHub
parent 189d2121e6
commit 69cbad0869
3 changed files with 21 additions and 21 deletions

View File

@ -635,8 +635,8 @@ pub struct BankHashStats {
} }
impl BankHashStats { impl BankHashStats {
pub fn update(&mut self, account: &AccountSharedData) { pub fn update<T: ReadableAccount>(&mut self, account: &T) {
if account.lamports == 0 { if account.lamports() == 0 {
self.num_removed_accounts += 1; self.num_removed_accounts += 1;
} else { } else {
self.num_updated_accounts += 1; self.num_updated_accounts += 1;
@ -644,10 +644,10 @@ impl BankHashStats {
self.total_data_len = self self.total_data_len = self
.total_data_len .total_data_len
.wrapping_add(account.data().len() as u64); .wrapping_add(account.data().len() as u64);
if account.executable { if account.executable() {
self.num_executable_accounts += 1; self.num_executable_accounts += 1;
} }
self.num_lamports_stored = self.num_lamports_stored.wrapping_add(account.lamports); self.num_lamports_stored = self.num_lamports_stored.wrapping_add(account.lamports());
} }
pub fn merge(&mut self, other: &BankHashStats) { pub fn merge(&mut self, other: &BankHashStats) {
@ -3221,13 +3221,13 @@ impl AccountsDb {
) )
} }
pub fn hash_account(slot: Slot, account: &AccountSharedData, pubkey: &Pubkey) -> Hash { pub fn hash_account<T: ReadableAccount>(slot: Slot, account: &T, pubkey: &Pubkey) -> Hash {
Self::hash_account_data( Self::hash_account_data(
slot, slot,
account.lamports, account.lamports(),
&account.owner, &account.owner(),
account.executable, account.executable(),
account.rent_epoch, account.rent_epoch(),
&account.data(), &account.data(),
pubkey, pubkey,
) )
@ -3350,7 +3350,7 @@ impl AccountsDb {
store_id: storage.append_vec_id(), store_id: storage.append_vec_id(),
offset: offsets[0], offset: offsets[0],
stored_size, stored_size,
lamports: account.lamports, lamports: account.lamports(),
}); });
} }
// restore the state to available // restore the state to available
@ -3706,7 +3706,7 @@ impl AccountsDb {
store_id: CACHE_VIRTUAL_STORAGE_ID, store_id: CACHE_VIRTUAL_STORAGE_ID,
offset: CACHE_VIRTUAL_OFFSET, offset: CACHE_VIRTUAL_OFFSET,
stored_size: CACHE_VIRTUAL_STORED_SIZE, stored_size: CACHE_VIRTUAL_STORED_SIZE,
lamports: account.lamports, lamports: account.lamports(),
} }
}) })
.collect() .collect()
@ -3729,7 +3729,7 @@ impl AccountsDb {
.iter() .iter()
.map(|(pubkey, account)| { .map(|(pubkey, account)| {
self.read_only_accounts_cache.remove(pubkey, slot); self.read_only_accounts_cache.remove(pubkey, slot);
let account = if account.lamports == 0 { let account = if account.lamports() == 0 {
&default_account &default_account
} else { } else {
*account *account
@ -4280,7 +4280,7 @@ impl AccountsDb {
self.accounts_index.upsert( self.accounts_index.upsert(
slot, slot,
pubkey, pubkey,
&pubkey_account.1.owner, &pubkey_account.1.owner(),
&pubkey_account.1.data(), &pubkey_account.1.data(),
&self.account_indexes, &self.account_indexes,
info, info,
@ -4522,7 +4522,7 @@ impl AccountsDb {
let mut total_data = 0; let mut total_data = 0;
accounts.iter().for_each(|(_pubkey, account)| { accounts.iter().for_each(|(_pubkey, account)| {
total_data += account.data().len(); total_data += account.data().len();
stats.update(account); stats.update(*account);
}); });
self.stats self.stats

View File

@ -57,13 +57,13 @@ pub struct AccountMeta {
pub rent_epoch: Epoch, pub rent_epoch: Epoch,
} }
impl<'a> From<&'a AccountSharedData> for AccountMeta { impl<'a, T: ReadableAccount> From<&'a T> for AccountMeta {
fn from(account: &'a AccountSharedData) -> Self { fn from(account: &'a T) -> Self {
Self { Self {
lamports: account.lamports, lamports: account.lamports(),
owner: account.owner, owner: *account.owner(),
executable: account.executable, executable: account.executable(),
rent_epoch: account.rent_epoch, rent_epoch: account.rent_epoch(),
} }
} }
} }

View File

@ -117,7 +117,7 @@ fn test_bad_bank_hash() {
assert_eq!( assert_eq!(
db.load_account_hash(&ancestors, &key, None, LoadHint::Unspecified) db.load_account_hash(&ancestors, &key, None, LoadHint::Unspecified)
.unwrap(), .unwrap(),
AccountsDb::hash_account(some_slot, &account, &key) AccountsDb::hash_account(some_slot, *account, &key)
); );
} }
existing.clear(); existing.clear();