private AccountSharedData.rent_epoch (#16877)

This commit is contained in:
Jeff Washington (jwash)
2021-04-28 08:52:20 -05:00
committed by GitHub
parent 6381ee38eb
commit da3342759b
5 changed files with 19 additions and 17 deletions

View File

@ -2105,7 +2105,7 @@ fn main() {
println!(" - owner: '{}'", account.owner());
println!(" - executable: {}", account.executable());
println!(" - slot: {}", slot);
println!(" - rent_epoch: {}", account.rent_epoch);
println!(" - rent_epoch: {}", account.rent_epoch());
if !exclude_account_data {
println!(" - data: '{}'", bs58::encode(account.data()).into_string());
}

View File

@ -976,7 +976,7 @@ impl Accounts {
_ => panic!("unexpected nonce_rollback condition"),
}
}
if account.rent_epoch == INITIAL_RENT_EPOCH {
if account.rent_epoch() == INITIAL_RENT_EPOCH {
loaded_transaction.rent +=
rent_collector.collect_from_created_account(&key, account);
}

View File

@ -183,7 +183,7 @@ impl PreAccount {
}
// No one modifies rent_epoch (yet).
let rent_epoch_changed = pre.rent_epoch != post.rent_epoch;
let rent_epoch_changed = pre.rent_epoch() != post.rent_epoch();
if rent_epoch_changed {
return Err(InstructionError::RentEpochModified);
}

View File

@ -1,6 +1,6 @@
//! calculate and collect rent from Accounts
use solana_sdk::{
account::{AccountSharedData, ReadableAccount},
account::{AccountSharedData, ReadableAccount, WritableAccount},
clock::Epoch,
epoch_schedule::EpochSchedule,
genesis_config::GenesisConfig,
@ -62,13 +62,13 @@ impl RentCollector {
account: &mut AccountSharedData,
) -> u64 {
if account.executable()
|| account.rent_epoch > self.epoch
|| account.rent_epoch() > self.epoch
|| sysvar::check_id(account.owner())
|| *address == incinerator::id()
{
0
} else {
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))
.sum();
@ -85,7 +85,8 @@ impl RentCollector {
if exempt || rent_due != 0 {
if account.lamports() > rent_due {
account.rent_epoch = self.epoch
account.set_rent_epoch(
self.epoch
+ if exempt {
// Rent isn't collected for the next epoch
// Make sure to check exempt status later in current epoch again
@ -93,7 +94,8 @@ impl RentCollector {
} else {
// Rent is collected for next epoch
1
};
},
);
account.lamports -= rent_due;
rent_due
} else {
@ -115,7 +117,7 @@ impl RentCollector {
account: &mut AccountSharedData,
) -> u64 {
// initialize rent_epoch as created at this epoch
account.rent_epoch = self.epoch;
account.set_rent_epoch(self.epoch);
self.collect_from_existing_account(address, account)
}
}

View File

@ -56,7 +56,7 @@ impl<'a> KeyedAccount<'a> {
}
pub fn rent_epoch(&self) -> Result<Epoch, InstructionError> {
Ok(self.try_borrow()?.rent_epoch)
Ok(self.try_borrow()?.rent_epoch())
}
pub fn try_account_ref(&'a self) -> Result<Ref<AccountSharedData>, InstructionError> {