bank: factor accumulation out to helper on `TotalAccountsStats`
This commit is contained in:
parent
0c6883e9b5
commit
cb7fe87abb
|
@ -7716,26 +7716,7 @@ impl Bank {
|
|||
let rent_collector = self.rent_collector();
|
||||
let mut total_accounts_stats = TotalAccountsStats::default();
|
||||
accounts.for_each(|(pubkey, account)| {
|
||||
let data_len = account.data().len();
|
||||
total_accounts_stats.num_accounts += 1;
|
||||
total_accounts_stats.data_len += data_len;
|
||||
|
||||
if account.executable() {
|
||||
total_accounts_stats.num_executable_accounts += 1;
|
||||
total_accounts_stats.executable_data_len += data_len;
|
||||
}
|
||||
|
||||
if !rent_collector.should_collect_rent(pubkey, account)
|
||||
|| rent_collector.get_rent_due(account).is_exempt()
|
||||
{
|
||||
total_accounts_stats.num_rent_exempt_accounts += 1;
|
||||
} else {
|
||||
total_accounts_stats.num_rent_paying_accounts += 1;
|
||||
total_accounts_stats.lamports_in_rent_paying_accounts += account.lamports();
|
||||
if data_len == 0 {
|
||||
total_accounts_stats.num_rent_paying_accounts_without_data += 1;
|
||||
}
|
||||
}
|
||||
total_accounts_stats.accumulate_account(pubkey, account, rent_collector);
|
||||
});
|
||||
|
||||
total_accounts_stats
|
||||
|
@ -7879,6 +7860,36 @@ pub struct TotalAccountsStats {
|
|||
pub lamports_in_rent_paying_accounts: u64,
|
||||
}
|
||||
|
||||
impl TotalAccountsStats {
|
||||
pub fn accumulate_account(
|
||||
&mut self,
|
||||
address: &Pubkey,
|
||||
account: &AccountSharedData,
|
||||
rent_collector: &RentCollector,
|
||||
) {
|
||||
let data_len = account.data().len();
|
||||
self.num_accounts += 1;
|
||||
self.data_len += data_len;
|
||||
|
||||
if account.executable() {
|
||||
self.num_executable_accounts += 1;
|
||||
self.executable_data_len += data_len;
|
||||
}
|
||||
|
||||
if !rent_collector.should_collect_rent(address, account)
|
||||
|| rent_collector.get_rent_due(account).is_exempt()
|
||||
{
|
||||
self.num_rent_exempt_accounts += 1;
|
||||
} else {
|
||||
self.num_rent_paying_accounts += 1;
|
||||
self.lamports_in_rent_paying_accounts += account.lamports();
|
||||
if data_len == 0 {
|
||||
self.num_rent_paying_accounts_without_data += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Bank {
|
||||
fn drop(&mut self) {
|
||||
if let Some(drop_callback) = self.drop_callback.read().unwrap().0.as_ref() {
|
||||
|
|
Loading…
Reference in New Issue