removes feature gate code preserving rent_epoch for rent exempt accounts (#28507)

* removes feature gate code preserving rent_epoch for rent exempt accounts

* update test expected hashes

Co-authored-by: jeff washington <jeff.washington@solana.com>
This commit is contained in:
behzad nouri 2022-11-01 13:36:59 +00:00 committed by GitHub
parent 4267a15292
commit 17680fe837
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 78 deletions

View File

@ -33,7 +33,7 @@ use {
account::{Account, AccountSharedData, ReadableAccount, WritableAccount}, account::{Account, AccountSharedData, ReadableAccount, WritableAccount},
account_utils::StateMut, account_utils::StateMut,
bpf_loader_upgradeable::{self, UpgradeableLoaderState}, bpf_loader_upgradeable::{self, UpgradeableLoaderState},
clock::{BankId, Slot, INITIAL_RENT_EPOCH}, clock::{BankId, Slot},
feature_set::{ feature_set::{
self, remove_deprecated_request_unit_ix, use_default_units_in_fee_calculation, self, remove_deprecated_request_unit_ix, use_default_units_in_fee_calculation,
FeatureSet, FeatureSet,
@ -272,8 +272,6 @@ impl Accounts {
let mut accounts = Vec::with_capacity(account_keys.len()); let mut accounts = Vec::with_capacity(account_keys.len());
let mut account_deps = Vec::with_capacity(account_keys.len()); let mut account_deps = Vec::with_capacity(account_keys.len());
let mut rent_debits = RentDebits::default(); let mut rent_debits = RentDebits::default();
let preserve_rent_epoch_for_rent_exempt_accounts = feature_set
.is_active(&feature_set::preserve_rent_epoch_for_rent_exempt_accounts::id());
for (i, key) in account_keys.iter().enumerate() { for (i, key) in account_keys.iter().enumerate() {
let account = if !message.is_non_loader_key(i) { let account = if !message.is_non_loader_key(i) {
// Fill in an empty account for the program slots. // Fill in an empty account for the program slots.
@ -301,7 +299,6 @@ impl Accounts {
key, key,
&mut account, &mut account,
self.accounts_db.filler_account_suffix.as_ref(), self.accounts_db.filler_account_suffix.as_ref(),
preserve_rent_epoch_for_rent_exempt_accounts,
) )
.rent_amount; .rent_amount;
(account, rent_due) (account, rent_due)
@ -1210,7 +1207,6 @@ impl Accounts {
rent_collector: &RentCollector, rent_collector: &RentCollector,
durable_nonce: &DurableNonce, durable_nonce: &DurableNonce,
lamports_per_signature: u64, lamports_per_signature: u64,
preserve_rent_epoch_for_rent_exempt_accounts: bool,
include_slot_in_hash: IncludeSlotInHash, include_slot_in_hash: IncludeSlotInHash,
) { ) {
let (accounts_to_store, txn_signatures) = self.collect_accounts_to_store( let (accounts_to_store, txn_signatures) = self.collect_accounts_to_store(
@ -1220,7 +1216,6 @@ impl Accounts {
rent_collector, rent_collector,
durable_nonce, durable_nonce,
lamports_per_signature, lamports_per_signature,
preserve_rent_epoch_for_rent_exempt_accounts,
); );
self.accounts_db.store_cached( self.accounts_db.store_cached(
(slot, &accounts_to_store[..], include_slot_in_hash), (slot, &accounts_to_store[..], include_slot_in_hash),
@ -1246,10 +1241,9 @@ impl Accounts {
txs: &'a [SanitizedTransaction], txs: &'a [SanitizedTransaction],
execution_results: &'a [TransactionExecutionResult], execution_results: &'a [TransactionExecutionResult],
load_results: &'a mut [TransactionLoadResult], load_results: &'a mut [TransactionLoadResult],
rent_collector: &RentCollector, _rent_collector: &RentCollector,
durable_nonce: &DurableNonce, durable_nonce: &DurableNonce,
lamports_per_signature: u64, lamports_per_signature: u64,
preserve_rent_epoch_for_rent_exempt_accounts: bool,
) -> ( ) -> (
Vec<(&'a Pubkey, &'a AccountSharedData)>, Vec<(&'a Pubkey, &'a AccountSharedData)>,
Vec<Option<&'a Signature>>, Vec<Option<&'a Signature>>,
@ -1303,24 +1297,6 @@ impl Accounts {
); );
if execution_status.is_ok() || is_nonce_account || is_fee_payer { if execution_status.is_ok() || is_nonce_account || is_fee_payer {
if !preserve_rent_epoch_for_rent_exempt_accounts
&& account.rent_epoch() == INITIAL_RENT_EPOCH
{
let rent = rent_collector
.collect_from_created_account(
address,
account,
preserve_rent_epoch_for_rent_exempt_accounts,
)
.rent_amount;
loaded_transaction.rent += rent;
loaded_transaction.rent_debits.insert(
address,
rent,
account.lamports(),
);
}
// Add to the accounts to store // Add to the accounts to store
accounts.push((&*address, &*account)); accounts.push((&*address, &*account));
signatures.push(Some(tx.signature())); signatures.push(Some(tx.signature()));
@ -3052,7 +3028,6 @@ mod tests {
&rent_collector, &rent_collector,
&DurableNonce::default(), &DurableNonce::default(),
0, 0,
true, // preserve_rent_epoch_for_rent_exempt_accounts
); );
assert_eq!(collected_accounts.len(), 2); assert_eq!(collected_accounts.len(), 2);
assert!(collected_accounts assert!(collected_accounts
@ -3536,7 +3511,6 @@ mod tests {
&rent_collector, &rent_collector,
&durable_nonce, &durable_nonce,
0, 0,
true, // preserve_rent_epoch_for_rent_exempt_accounts
); );
assert_eq!(collected_accounts.len(), 2); assert_eq!(collected_accounts.len(), 2);
assert_eq!( assert_eq!(
@ -3651,7 +3625,6 @@ mod tests {
&rent_collector, &rent_collector,
&durable_nonce, &durable_nonce,
0, 0,
true, // preserve_rent_epoch_for_rent_exempt_accounts
); );
assert_eq!(collected_accounts.len(), 1); assert_eq!(collected_accounts.len(), 1);
let collected_nonce_account = collected_accounts let collected_nonce_account = collected_accounts

View File

@ -4892,7 +4892,6 @@ impl Bank {
&self.rent_collector, &self.rent_collector,
&durable_nonce, &durable_nonce,
lamports_per_signature, lamports_per_signature,
self.preserve_rent_epoch_for_rent_exempt_accounts(),
self.include_slot_in_hash(), self.include_slot_in_hash(),
); );
let rent_debits = self.collect_rent(&execution_results, loaded_txs); let rent_debits = self.collect_rent(&execution_results, loaded_txs);
@ -5321,15 +5320,12 @@ impl Bank {
let mut time_hashing_skipped_rewrites_us = 0; let mut time_hashing_skipped_rewrites_us = 0;
let mut time_storing_accounts_us = 0; let mut time_storing_accounts_us = 0;
let can_skip_rewrites = self.rc.accounts.accounts_db.skip_rewrites || just_rewrites; let can_skip_rewrites = self.rc.accounts.accounts_db.skip_rewrites || just_rewrites;
let preserve_rent_epoch_for_rent_exempt_accounts =
self.preserve_rent_epoch_for_rent_exempt_accounts();
for (pubkey, account, _loaded_slot) in accounts.iter_mut() { for (pubkey, account, _loaded_slot) in accounts.iter_mut() {
let (rent_collected_info, measure) = let (rent_collected_info, measure) =
measure!(self.rent_collector.collect_from_existing_account( measure!(self.rent_collector.collect_from_existing_account(
pubkey, pubkey,
account, account,
self.rc.accounts.accounts_db.filler_account_suffix.as_ref(), self.rc.accounts.accounts_db.filler_account_suffix.as_ref(),
preserve_rent_epoch_for_rent_exempt_accounts,
)); ));
time_collecting_rent_us += measure.as_us(); time_collecting_rent_us += measure.as_us();
@ -7411,11 +7407,6 @@ impl Bank {
.is_active(&feature_set::send_to_tpu_vote_port::id()) .is_active(&feature_set::send_to_tpu_vote_port::id())
} }
fn preserve_rent_epoch_for_rent_exempt_accounts(&self) -> bool {
self.feature_set
.is_active(&feature_set::preserve_rent_epoch_for_rent_exempt_accounts::id())
}
pub fn read_cost_tracker(&self) -> LockResult<RwLockReadGuard<CostTracker>> { pub fn read_cost_tracker(&self) -> LockResult<RwLockReadGuard<CostTracker>> {
self.cost_tracker.read() self.cost_tracker.read()
} }
@ -8415,7 +8406,6 @@ pub(crate) mod tests {
&keypairs[4].pubkey(), &keypairs[4].pubkey(),
&mut account_copy, &mut account_copy,
None, None,
true, // preserve_rent_epoch_for_rent_exempt_accounts
); );
assert_eq!(expected_rent.rent_amount, too_few_lamports); assert_eq!(expected_rent.rent_amount, too_few_lamports);
assert_eq!(account_copy.lamports(), 0); assert_eq!(account_copy.lamports(), 0);
@ -14508,13 +14498,13 @@ pub(crate) mod tests {
if bank.slot == 64 { if bank.slot == 64 {
assert_eq!( assert_eq!(
bank.hash().to_string(), bank.hash().to_string(),
"4u8bxZRLYdQBkWRBwmpcwcQVMCJoEpzY7hCuAzxr3kCe" "Ddk6ouAvSSA1U3Cw6BoKdM5v5LdRc9ShruGDzci9fKbY"
); );
} }
if bank.slot == 128 { if bank.slot == 128 {
assert_eq!( assert_eq!(
bank.hash().to_string(), bank.hash().to_string(),
"4c5F8UbcDD8FM7qXcfv6BPPo6nHNYJQmN5gHiCMTdEzX" "ANodC5vnedLWqeAyhcoErzR3ptNansb5YX6UTQ9cfP7S"
); );
break; break;
} }
@ -19864,7 +19854,6 @@ pub(crate) mod tests {
&keypair.pubkey(), &keypair.pubkey(),
&mut account, &mut account,
None, None,
true, // preserve_rent_epoch_for_rent_exempt_accounts
); );
assert_eq!(info.account_data_len_reclaimed, data_size as u64); assert_eq!(info.account_data_len_reclaimed, data_size as u64);
} }

View File

@ -125,14 +125,8 @@ impl RentCollector {
address: &Pubkey, address: &Pubkey,
account: &mut AccountSharedData, account: &mut AccountSharedData,
filler_account_suffix: Option<&Pubkey>, filler_account_suffix: Option<&Pubkey>,
preserve_rent_epoch_for_rent_exempt_accounts: bool,
) -> CollectedInfo { ) -> CollectedInfo {
match self.calculate_rent_result( match self.calculate_rent_result(address, account, filler_account_suffix) {
address,
account,
filler_account_suffix,
preserve_rent_epoch_for_rent_exempt_accounts,
) {
RentResult::LeaveAloneNoRent => CollectedInfo::default(), RentResult::LeaveAloneNoRent => CollectedInfo::default(),
RentResult::CollectRent { RentResult::CollectRent {
new_rent_epoch, new_rent_epoch,
@ -164,7 +158,6 @@ impl RentCollector {
address: &Pubkey, address: &Pubkey,
account: &impl ReadableAccount, account: &impl ReadableAccount,
filler_account_suffix: Option<&Pubkey>, filler_account_suffix: Option<&Pubkey>,
preserve_rent_epoch_for_rent_exempt_accounts: bool,
) -> RentResult { ) -> RentResult {
if self.can_skip_rent_collection(address, account, filler_account_suffix) { if self.can_skip_rent_collection(address, account, filler_account_suffix) {
return RentResult::LeaveAloneNoRent; return RentResult::LeaveAloneNoRent;
@ -172,16 +165,7 @@ impl RentCollector {
match self.get_rent_due(account) { match self.get_rent_due(account) {
// Rent isn't collected for the next epoch. // Rent isn't collected for the next epoch.
// Make sure to check exempt status again later in current epoch. // Make sure to check exempt status again later in current epoch.
RentDue::Exempt => { RentDue::Exempt => RentResult::LeaveAloneNoRent,
if preserve_rent_epoch_for_rent_exempt_accounts {
RentResult::LeaveAloneNoRent
} else {
RentResult::CollectRent {
new_rent_epoch: self.epoch,
rent_due: 0,
}
}
}
// Maybe collect rent later, leave account alone. // Maybe collect rent later, leave account alone.
RentDue::Paying(0) => RentResult::LeaveAloneNoRent, RentDue::Paying(0) => RentResult::LeaveAloneNoRent,
// Rent is collected for next epoch. // Rent is collected for next epoch.
@ -193,20 +177,15 @@ impl RentCollector {
} }
#[must_use = "add to Bank::collected_rent"] #[must_use = "add to Bank::collected_rent"]
pub(crate) fn collect_from_created_account( #[cfg(test)]
fn collect_from_created_account(
&self, &self,
address: &Pubkey, address: &Pubkey,
account: &mut AccountSharedData, account: &mut AccountSharedData,
preserve_rent_epoch_for_rent_exempt_accounts: bool,
) -> CollectedInfo { ) -> CollectedInfo {
// initialize rent_epoch as created at this epoch // initialize rent_epoch as created at this epoch
account.set_rent_epoch(self.epoch); account.set_rent_epoch(self.epoch);
self.collect_from_existing_account( self.collect_from_existing_account(address, account, /*filler_account_suffix:*/ None)
address,
account,
None, // filler_account_suffix
preserve_rent_epoch_for_rent_exempt_accounts,
)
} }
/// Performs easy checks to see if rent collection can be skipped /// Performs easy checks to see if rent collection can be skipped
@ -281,11 +260,8 @@ mod tests {
let rent_collector = default_rent_collector_clone_with_epoch(new_epoch); let rent_collector = default_rent_collector_clone_with_epoch(new_epoch);
// collect rent on a newly-created account // collect rent on a newly-created account
let collected = rent_collector.collect_from_created_account( let collected = rent_collector
&solana_sdk::pubkey::new_rand(), .collect_from_created_account(&solana_sdk::pubkey::new_rand(), &mut created_account);
&mut created_account,
true, // preserve_rent_epoch_for_rent_exempt_accounts
);
assert!(created_account.lamports() < old_lamports); assert!(created_account.lamports() < old_lamports);
assert_eq!( assert_eq!(
created_account.lamports() + collected.rent_amount, created_account.lamports() + collected.rent_amount,
@ -299,7 +275,6 @@ mod tests {
&solana_sdk::pubkey::new_rand(), &solana_sdk::pubkey::new_rand(),
&mut existing_account, &mut existing_account,
None, // filler_account_suffix None, // filler_account_suffix
true, // preserve_rent_epoch_for_rent_exempt_accounts
); );
assert!(existing_account.lamports() < old_lamports); assert!(existing_account.lamports() < old_lamports);
assert_eq!( assert_eq!(
@ -333,7 +308,6 @@ mod tests {
&pubkey, &pubkey,
&mut account, &mut account,
None, // filler_account_suffix None, // filler_account_suffix
true, // preserve_rent_epoch_for_rent_exempt_accounts
); );
assert_eq!(account.lamports(), huge_lamports); assert_eq!(account.lamports(), huge_lamports);
assert_eq!(collected, CollectedInfo::default()); assert_eq!(collected, CollectedInfo::default());
@ -346,7 +320,6 @@ mod tests {
&pubkey, &pubkey,
&mut account, &mut account,
None, // filler_account_suffix None, // filler_account_suffix
true, // preserve_rent_epoch_for_rent_exempt_accounts
); );
assert_eq!(account.lamports(), tiny_lamports - collected.rent_amount); assert_eq!(account.lamports(), tiny_lamports - collected.rent_amount);
assert_ne!(collected, CollectedInfo::default()); assert_ne!(collected, CollectedInfo::default());
@ -370,7 +343,6 @@ mod tests {
&pubkey, &pubkey,
&mut account, &mut account,
None, // filler_account_suffix None, // filler_account_suffix
true, // preserve_rent_epoch_for_rent_exempt_accounts
); );
assert_eq!(account.lamports(), 0); assert_eq!(account.lamports(), 0);
assert_eq!(collected.rent_amount, 1); assert_eq!(collected.rent_amount, 1);
@ -395,7 +367,6 @@ mod tests {
&Pubkey::new_unique(), &Pubkey::new_unique(),
&mut account, &mut account,
None, // filler_account_suffix None, // filler_account_suffix
true, // preserve_rent_epoch_for_rent_exempt_accounts
); );
assert_eq!(collected.rent_amount, account_lamports); assert_eq!(collected.rent_amount, account_lamports);