private AccountSharedData.rent_epoch (#16877)
This commit is contained in:
committed by
GitHub
parent
6381ee38eb
commit
da3342759b
@ -2105,7 +2105,7 @@ fn main() {
|
|||||||
println!(" - owner: '{}'", account.owner());
|
println!(" - owner: '{}'", account.owner());
|
||||||
println!(" - executable: {}", account.executable());
|
println!(" - executable: {}", account.executable());
|
||||||
println!(" - slot: {}", slot);
|
println!(" - slot: {}", slot);
|
||||||
println!(" - rent_epoch: {}", account.rent_epoch);
|
println!(" - rent_epoch: {}", account.rent_epoch());
|
||||||
if !exclude_account_data {
|
if !exclude_account_data {
|
||||||
println!(" - data: '{}'", bs58::encode(account.data()).into_string());
|
println!(" - data: '{}'", bs58::encode(account.data()).into_string());
|
||||||
}
|
}
|
||||||
|
@ -976,7 +976,7 @@ impl Accounts {
|
|||||||
_ => panic!("unexpected nonce_rollback condition"),
|
_ => panic!("unexpected nonce_rollback condition"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if account.rent_epoch == INITIAL_RENT_EPOCH {
|
if account.rent_epoch() == INITIAL_RENT_EPOCH {
|
||||||
loaded_transaction.rent +=
|
loaded_transaction.rent +=
|
||||||
rent_collector.collect_from_created_account(&key, account);
|
rent_collector.collect_from_created_account(&key, account);
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ impl PreAccount {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No one modifies rent_epoch (yet).
|
// 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 {
|
if rent_epoch_changed {
|
||||||
return Err(InstructionError::RentEpochModified);
|
return Err(InstructionError::RentEpochModified);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! calculate and collect rent from Accounts
|
//! calculate and collect rent from Accounts
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{AccountSharedData, ReadableAccount},
|
account::{AccountSharedData, ReadableAccount, WritableAccount},
|
||||||
clock::Epoch,
|
clock::Epoch,
|
||||||
epoch_schedule::EpochSchedule,
|
epoch_schedule::EpochSchedule,
|
||||||
genesis_config::GenesisConfig,
|
genesis_config::GenesisConfig,
|
||||||
@ -62,13 +62,13 @@ impl RentCollector {
|
|||||||
account: &mut AccountSharedData,
|
account: &mut AccountSharedData,
|
||||||
) -> u64 {
|
) -> u64 {
|
||||||
if account.executable()
|
if account.executable()
|
||||||
|| account.rent_epoch > self.epoch
|
|| account.rent_epoch() > self.epoch
|
||||||
|| sysvar::check_id(account.owner())
|
|| sysvar::check_id(account.owner())
|
||||||
|| *address == incinerator::id()
|
|| *address == incinerator::id()
|
||||||
{
|
{
|
||||||
0
|
0
|
||||||
} else {
|
} 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))
|
.map(|epoch| self.epoch_schedule.get_slots_in_epoch(epoch + 1))
|
||||||
.sum();
|
.sum();
|
||||||
|
|
||||||
@ -85,15 +85,17 @@ impl RentCollector {
|
|||||||
|
|
||||||
if exempt || rent_due != 0 {
|
if exempt || rent_due != 0 {
|
||||||
if account.lamports() > rent_due {
|
if account.lamports() > rent_due {
|
||||||
account.rent_epoch = self.epoch
|
account.set_rent_epoch(
|
||||||
+ if exempt {
|
self.epoch
|
||||||
// Rent isn't collected for the next epoch
|
+ if exempt {
|
||||||
// Make sure to check exempt status later in current epoch again
|
// Rent isn't collected for the next epoch
|
||||||
0
|
// Make sure to check exempt status later in current epoch again
|
||||||
} else {
|
0
|
||||||
// Rent is collected for next epoch
|
} else {
|
||||||
1
|
// Rent is collected for next epoch
|
||||||
};
|
1
|
||||||
|
},
|
||||||
|
);
|
||||||
account.lamports -= rent_due;
|
account.lamports -= rent_due;
|
||||||
rent_due
|
rent_due
|
||||||
} else {
|
} else {
|
||||||
@ -115,7 +117,7 @@ impl RentCollector {
|
|||||||
account: &mut AccountSharedData,
|
account: &mut AccountSharedData,
|
||||||
) -> u64 {
|
) -> u64 {
|
||||||
// initialize rent_epoch as created at this epoch
|
// 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)
|
self.collect_from_existing_account(address, account)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ impl<'a> KeyedAccount<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn rent_epoch(&self) -> Result<Epoch, InstructionError> {
|
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> {
|
pub fn try_account_ref(&'a self) -> Result<Ref<AccountSharedData>, InstructionError> {
|
||||||
|
Reference in New Issue
Block a user