new counter data point for unexpected rent_epoch (#23449)

This commit is contained in:
Jeff Washington (jwash) 2022-03-03 09:09:31 -06:00 committed by GitHub
parent ddfd4f86f3
commit 7f608965ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 10 deletions

View File

@ -1,12 +1,15 @@
//! calculate and collect rent from Accounts //! calculate and collect rent from Accounts
use solana_sdk::{ use {
account::{AccountSharedData, ReadableAccount, WritableAccount}, log::*,
clock::Epoch, solana_sdk::{
epoch_schedule::EpochSchedule, account::{AccountSharedData, ReadableAccount, WritableAccount},
genesis_config::GenesisConfig, clock::Epoch,
incinerator, epoch_schedule::EpochSchedule,
pubkey::Pubkey, genesis_config::GenesisConfig,
rent::{Rent, RentDue}, incinerator,
pubkey::Pubkey,
rent::{Rent, RentDue},
},
}; };
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, AbiExample)] #[derive(Serialize, Deserialize, Clone, PartialEq, Debug, AbiExample)]
@ -89,7 +92,8 @@ impl RentCollector {
{ {
RentDue::Exempt RentDue::Exempt
} else { } else {
let slots_elapsed: u64 = (account.rent_epoch()..=self.epoch) let account_rent_epoch = account.rent_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))
.sum(); .sum();
@ -101,7 +105,21 @@ impl RentCollector {
}; };
// we know this account is not exempt // we know this account is not exempt
RentDue::Paying(self.rent.due_amount(account.data().len(), years_elapsed)) let due = self.rent.due_amount(account.data().len(), years_elapsed);
// we expect rent_epoch to always be one of: {0, self.epoch-1, self.epoch, self.epoch+1}
if account_rent_epoch != 0
&& (account_rent_epoch + 1 < self.epoch || account_rent_epoch > self.epoch + 1)
{
// this should not occur in a running validator
if due == 0 {
inc_new_counter_info!("rent-collector-rent-epoch-range-large-exempt", 1);
} else {
inc_new_counter_info!("rent-collector-rent-epoch-range-large-paying", 1);
}
}
RentDue::Paying(due)
} }
} }