refactor rent collector and logs (#21155)
This commit is contained in:
committed by
GitHub
parent
29ad081555
commit
b1e3a82c11
@ -6713,7 +6713,7 @@ impl AccountsDb {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if rent_collector.no_rent(&pubkey, &stored_account, false) || {
|
if !rent_collector.should_collect_rent(&pubkey, &stored_account, false) || {
|
||||||
let (_rent_due, exempt) = rent_collector.get_rent_due(&stored_account);
|
let (_rent_due, exempt) = rent_collector.get_rent_due(&stored_account);
|
||||||
exempt
|
exempt
|
||||||
} {
|
} {
|
||||||
@ -6980,6 +6980,7 @@ impl AccountsDb {
|
|||||||
.sum();
|
.sum();
|
||||||
index_time.stop();
|
index_time.stop();
|
||||||
|
|
||||||
|
info!("rent_collector: {:?}", rent_collector);
|
||||||
let mut min_bin_size = usize::MAX;
|
let mut min_bin_size = usize::MAX;
|
||||||
let mut max_bin_size = usize::MIN;
|
let mut max_bin_size = usize::MIN;
|
||||||
let total_items = self
|
let total_items = self
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
//! calculate and collect rent from Accounts
|
//! calculate and collect rent from Accounts
|
||||||
use log::*;
|
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{AccountSharedData, ReadableAccount, WritableAccount},
|
account::{AccountSharedData, ReadableAccount, WritableAccount},
|
||||||
clock::Epoch,
|
clock::Epoch,
|
||||||
@ -38,11 +37,6 @@ impl RentCollector {
|
|||||||
slots_per_year: f64,
|
slots_per_year: f64,
|
||||||
rent: &Rent,
|
rent: &Rent,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
info!(
|
|
||||||
"creating RentCollector, epoch: {}, slots_per_year: {}, rent: {:?}",
|
|
||||||
epoch, slots_per_year, rent
|
|
||||||
);
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
epoch,
|
epoch,
|
||||||
epoch_schedule: *epoch_schedule,
|
epoch_schedule: *epoch_schedule,
|
||||||
@ -58,20 +52,21 @@ impl RentCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// true if it is easy to determine this account should not have rent collected from it
|
/// true if it is easy to determine this account should consider having rent collected from it
|
||||||
pub fn no_rent(
|
pub fn should_collect_rent(
|
||||||
&self,
|
&self,
|
||||||
address: &Pubkey,
|
address: &Pubkey,
|
||||||
account: &impl ReadableAccount,
|
account: &impl ReadableAccount,
|
||||||
rent_for_sysvars: bool,
|
rent_for_sysvars: bool,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
account.executable() // executable accounts must be rent-exempt balance
|
!(account.executable() // executable accounts must be rent-exempt balance
|
||||||
|| account.rent_epoch() > self.epoch
|
|| account.rent_epoch() > self.epoch
|
||||||
|| (!rent_for_sysvars && sysvar::check_id(account.owner()))
|
|| (!rent_for_sysvars && sysvar::check_id(account.owner()))
|
||||||
|| *address == incinerator::id()
|
|| *address == incinerator::id())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// true if it is easy to determine this account should not have rent collected from it
|
/// given an account that 'should_collect_rent'
|
||||||
|
/// returns (amount rent due, is_exempt_from_rent)
|
||||||
pub fn get_rent_due(&self, account: &impl ReadableAccount) -> (u64, bool) {
|
pub fn get_rent_due(&self, account: &impl ReadableAccount) -> (u64, bool) {
|
||||||
let slots_elapsed: u64 = (account.rent_epoch()..=self.epoch)
|
let slots_elapsed: u64 = (account.rent_epoch()..=self.epoch)
|
||||||
.map(|epoch| self.epoch_schedule.get_slots_in_epoch(epoch + 1))
|
.map(|epoch| self.epoch_schedule.get_slots_in_epoch(epoch + 1))
|
||||||
@ -99,7 +94,7 @@ impl RentCollector {
|
|||||||
rent_for_sysvars: bool,
|
rent_for_sysvars: bool,
|
||||||
filler_account_suffix: Option<&Pubkey>,
|
filler_account_suffix: Option<&Pubkey>,
|
||||||
) -> u64 {
|
) -> u64 {
|
||||||
if self.no_rent(address, account, rent_for_sysvars)
|
if !self.should_collect_rent(address, account, rent_for_sysvars)
|
||||||
|| crate::accounts_db::AccountsDb::is_filler_account_helper(
|
|| crate::accounts_db::AccountsDb::is_filler_account_helper(
|
||||||
address,
|
address,
|
||||||
filler_account_suffix,
|
filler_account_suffix,
|
||||||
|
@ -374,6 +374,8 @@ where
|
|||||||
debug_do_not_add_builtins,
|
debug_do_not_add_builtins,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
info!("rent_collector: {:?}", bank.rent_collector());
|
||||||
|
|
||||||
Ok(bank)
|
Ok(bank)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user