From 171243a370220f593bb0405bbcf68efeff55267a Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" <75863576+jeffwashington@users.noreply.github.com> Date: Thu, 4 Nov 2021 11:17:19 -0500 Subject: [PATCH] add rent exempt count to get_total_accounts_stats (#21153) --- runtime/src/accounts_db.rs | 2 +- runtime/src/bank.rs | 13 ++++++++++++- runtime/src/rent_collector.rs | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 7ac71a7b78..d92f643e17 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -264,7 +264,7 @@ impl GenerateIndexTimings { ), ("index_flush_us", self.index_flush_us as i64, i64), ( - "total_not_rent_exempt_with_duplicates", + "total_rent_paying_with_duplicates", self.total_duplicates.saturating_sub(self.rent_exempt) as i64, i64 ), diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 583a35965c..467f425570 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -6362,11 +6362,12 @@ impl Bank { /// Scan all the accounts for this bank and collect stats pub fn get_total_accounts_stats(bank: &Bank) -> ScanResult { + let rent_collector = bank.rent_collector(); bank.rc.accounts.accounts_db.scan_accounts( &Ancestors::default(), bank.bank_id(), |total_accounts_stats: &mut TotalAccountsStats, item| { - if let Some((_pubkey, account, _slot)) = item { + if let Some((pubkey, account, _slot)) = item { total_accounts_stats.num_accounts += 1; total_accounts_stats.data_len += account.data().len(); @@ -6374,6 +6375,13 @@ pub fn get_total_accounts_stats(bank: &Bank) -> ScanResult { total_accounts_stats.num_executable_accounts += 1; total_accounts_stats.executable_data_len += account.data().len(); } + + if !rent_collector.should_collect_rent(pubkey, &account, false) || { + let (_rent_due, exempt) = rent_collector.get_rent_due(&account); + exempt + } { + total_accounts_stats.num_rent_exempt_accounts += 1; + } } }, ) @@ -6391,6 +6399,9 @@ pub struct TotalAccountsStats { pub num_executable_accounts: usize, /// Total data size of executable accounts pub executable_data_len: usize, + + /// Total number of rent exempt accounts + pub num_rent_exempt_accounts: usize, } impl Drop for Bank { diff --git a/runtime/src/rent_collector.rs b/runtime/src/rent_collector.rs index b109e98e5c..0c8706c734 100644 --- a/runtime/src/rent_collector.rs +++ b/runtime/src/rent_collector.rs @@ -60,7 +60,6 @@ impl RentCollector { rent_for_sysvars: bool, ) -> bool { !(account.executable() // executable accounts must be rent-exempt balance - || account.rent_epoch() > self.epoch || (!rent_for_sysvars && sysvar::check_id(account.owner())) || *address == incinerator::id()) } @@ -95,6 +94,7 @@ impl RentCollector { filler_account_suffix: Option<&Pubkey>, ) -> u64 { if !self.should_collect_rent(address, account, rent_for_sysvars) + || account.rent_epoch() > self.epoch || crate::accounts_db::AccountsDb::is_filler_account_helper( address, filler_account_suffix,