Skip to content

Commit

Permalink
add data_len() to LoadedAccount (anza-xyz#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington authored Apr 9, 2024
1 parent 9d700b8 commit f62d79b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,11 @@ impl<'a> LoadedAccount<'a> {
LoadedAccount::Cached(_) => true,
}
}

/// data_len can be calculated without having access to `&data` in future implementations
pub fn data_len(&self) -> usize {
self.data().len()
}
}

impl<'a> ReadableAccount for LoadedAccount<'a> {
Expand Down Expand Up @@ -9118,11 +9123,12 @@ impl AccountsDb {
maybe_storage_entry.map(|entry| (entry, account_info.offset())),
);
let loaded_account = accessor.check_and_get_loaded_account();
accounts_data_len_from_duplicates += loaded_account.data().len();
let data_len = loaded_account.data_len();
accounts_data_len_from_duplicates += data_len;
if let Some(lamports_to_top_off) = Self::stats_for_rent_payers(
pubkey,
loaded_account.lamports(),
loaded_account.data().len(),
data_len,
loaded_account.rent_epoch(),
loaded_account.executable(),
rent_collector,
Expand Down

0 comments on commit f62d79b

Please sign in to comment.