Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 2 additions & 29 deletions runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use {
account::{Account, AccountSharedData, ReadableAccount, WritableAccount},
account_utils::StateMut,
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
clock::{BankId, Slot, INITIAL_RENT_EPOCH},
clock::{BankId, Slot},
feature_set::{
self, remove_deprecated_request_unit_ix, use_default_units_in_fee_calculation,
FeatureSet,
Expand Down Expand Up @@ -272,8 +272,6 @@ impl Accounts {
let mut accounts = Vec::with_capacity(account_keys.len());
let mut account_deps = Vec::with_capacity(account_keys.len());
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() {
let account = if !message.is_non_loader_key(i) {
// Fill in an empty account for the program slots.
Expand Down Expand Up @@ -301,7 +299,6 @@ impl Accounts {
key,
&mut account,
self.accounts_db.filler_account_suffix.as_ref(),
preserve_rent_epoch_for_rent_exempt_accounts,
)
.rent_amount;
(account, rent_due)
Expand Down Expand Up @@ -1210,7 +1207,6 @@ impl Accounts {
rent_collector: &RentCollector,
durable_nonce: &DurableNonce,
lamports_per_signature: u64,
preserve_rent_epoch_for_rent_exempt_accounts: bool,
include_slot_in_hash: IncludeSlotInHash,
) {
let (accounts_to_store, txn_signatures) = self.collect_accounts_to_store(
Expand All @@ -1220,7 +1216,6 @@ impl Accounts {
rent_collector,
durable_nonce,
lamports_per_signature,
preserve_rent_epoch_for_rent_exempt_accounts,
);
self.accounts_db.store_cached(
(slot, &accounts_to_store[..], include_slot_in_hash),
Expand All @@ -1246,10 +1241,9 @@ impl Accounts {
txs: &'a [SanitizedTransaction],
execution_results: &'a [TransactionExecutionResult],
load_results: &'a mut [TransactionLoadResult],
rent_collector: &RentCollector,
_rent_collector: &RentCollector,
durable_nonce: &DurableNonce,
lamports_per_signature: u64,
preserve_rent_epoch_for_rent_exempt_accounts: bool,
) -> (
Vec<(&'a Pubkey, &'a AccountSharedData)>,
Vec<Option<&'a Signature>>,
Expand Down Expand Up @@ -1303,24 +1297,6 @@ impl Accounts {
);

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@behzadnouri
This PR looks like it is correctly removing the feature.
I am not entirely sure what this code here is doing. Is this code gone because we aren't allowed to create rent paying accounts anymore so the only side effect was updating rent_epoch?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for posterity, from behzad:

that branch was added separately in:
#26851
the PR has some context

.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
accounts.push((&*address, &*account));
signatures.push(Some(tx.signature()));
Expand Down Expand Up @@ -3052,7 +3028,6 @@ mod tests {
&rent_collector,
&DurableNonce::default(),
0,
true, // preserve_rent_epoch_for_rent_exempt_accounts
);
assert_eq!(collected_accounts.len(), 2);
assert!(collected_accounts
Expand Down Expand Up @@ -3536,7 +3511,6 @@ mod tests {
&rent_collector,
&durable_nonce,
0,
true, // preserve_rent_epoch_for_rent_exempt_accounts
);
assert_eq!(collected_accounts.len(), 2);
assert_eq!(
Expand Down Expand Up @@ -3651,7 +3625,6 @@ mod tests {
&rent_collector,
&durable_nonce,
0,
true, // preserve_rent_epoch_for_rent_exempt_accounts
);
assert_eq!(collected_accounts.len(), 1);
let collected_nonce_account = collected_accounts
Expand Down
15 changes: 2 additions & 13 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4892,7 +4892,6 @@ impl Bank {
&self.rent_collector,
&durable_nonce,
lamports_per_signature,
self.preserve_rent_epoch_for_rent_exempt_accounts(),
self.include_slot_in_hash(),
);
let rent_debits = self.collect_rent(&execution_results, loaded_txs);
Expand Down Expand Up @@ -5321,15 +5320,12 @@ impl Bank {
let mut time_hashing_skipped_rewrites_us = 0;
let mut time_storing_accounts_us = 0;
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() {
let (rent_collected_info, measure) =
measure!(self.rent_collector.collect_from_existing_account(
pubkey,
account,
self.rc.accounts.accounts_db.filler_account_suffix.as_ref(),
preserve_rent_epoch_for_rent_exempt_accounts,
));
time_collecting_rent_us += measure.as_us();

Expand Down Expand Up @@ -7411,11 +7407,6 @@ impl Bank {
.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>> {
self.cost_tracker.read()
}
Expand Down Expand Up @@ -8415,7 +8406,6 @@ pub(crate) mod tests {
&keypairs[4].pubkey(),
&mut account_copy,
None,
true, // preserve_rent_epoch_for_rent_exempt_accounts
);
assert_eq!(expected_rent.rent_amount, too_few_lamports);
assert_eq!(account_copy.lamports(), 0);
Expand Down Expand Up @@ -14508,13 +14498,13 @@ pub(crate) mod tests {
if bank.slot == 64 {
assert_eq!(
bank.hash().to_string(),
"4u8bxZRLYdQBkWRBwmpcwcQVMCJoEpzY7hCuAzxr3kCe"
"Ddk6ouAvSSA1U3Cw6BoKdM5v5LdRc9ShruGDzci9fKbY"
);
}
if bank.slot == 128 {
assert_eq!(
bank.hash().to_string(),
"4c5F8UbcDD8FM7qXcfv6BPPo6nHNYJQmN5gHiCMTdEzX"
"ANodC5vnedLWqeAyhcoErzR3ptNansb5YX6UTQ9cfP7S"
);
break;
}
Expand Down Expand Up @@ -19864,7 +19854,6 @@ pub(crate) mod tests {
&keypair.pubkey(),
&mut account,
None,
true, // preserve_rent_epoch_for_rent_exempt_accounts
);
assert_eq!(info.account_data_len_reclaimed, data_size as u64);
}
Expand Down
43 changes: 7 additions & 36 deletions runtime/src/rent_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,8 @@ impl RentCollector {
address: &Pubkey,
account: &mut AccountSharedData,
filler_account_suffix: Option<&Pubkey>,
preserve_rent_epoch_for_rent_exempt_accounts: bool,
) -> CollectedInfo {
match self.calculate_rent_result(
address,
account,
filler_account_suffix,
preserve_rent_epoch_for_rent_exempt_accounts,
) {
match self.calculate_rent_result(address, account, filler_account_suffix) {
RentResult::LeaveAloneNoRent => CollectedInfo::default(),
RentResult::CollectRent {
new_rent_epoch,
Expand Down Expand Up @@ -164,24 +158,14 @@ impl RentCollector {
address: &Pubkey,
account: &impl ReadableAccount,
filler_account_suffix: Option<&Pubkey>,
preserve_rent_epoch_for_rent_exempt_accounts: bool,
) -> RentResult {
if self.can_skip_rent_collection(address, account, filler_account_suffix) {
return RentResult::LeaveAloneNoRent;
}
match self.get_rent_due(account) {
// Rent isn't collected for the next epoch.
// Make sure to check exempt status again later in current epoch.
RentDue::Exempt => {
if preserve_rent_epoch_for_rent_exempt_accounts {
RentResult::LeaveAloneNoRent
} else {
RentResult::CollectRent {
new_rent_epoch: self.epoch,
rent_due: 0,
}
}
}
RentDue::Exempt => RentResult::LeaveAloneNoRent,
// Maybe collect rent later, leave account alone.
RentDue::Paying(0) => RentResult::LeaveAloneNoRent,
// Rent is collected for next epoch.
Expand All @@ -193,20 +177,15 @@ impl RentCollector {
}

#[must_use = "add to Bank::collected_rent"]
pub(crate) fn collect_from_created_account(
#[cfg(test)]
fn collect_from_created_account(
&self,
address: &Pubkey,
account: &mut AccountSharedData,
preserve_rent_epoch_for_rent_exempt_accounts: bool,
) -> CollectedInfo {
// initialize rent_epoch as created at this epoch
account.set_rent_epoch(self.epoch);
self.collect_from_existing_account(
address,
account,
None, // filler_account_suffix
preserve_rent_epoch_for_rent_exempt_accounts,
)
self.collect_from_existing_account(address, account, /*filler_account_suffix:*/ None)
}

/// Performs easy checks to see if rent collection can be skipped
Expand Down Expand Up @@ -281,11 +260,8 @@ mod tests {
let rent_collector = default_rent_collector_clone_with_epoch(new_epoch);

// collect rent on a newly-created account
let collected = rent_collector.collect_from_created_account(
&solana_sdk::pubkey::new_rand(),
&mut created_account,
true, // preserve_rent_epoch_for_rent_exempt_accounts
);
let collected = rent_collector
.collect_from_created_account(&solana_sdk::pubkey::new_rand(), &mut created_account);
assert!(created_account.lamports() < old_lamports);
assert_eq!(
created_account.lamports() + collected.rent_amount,
Expand All @@ -299,7 +275,6 @@ mod tests {
&solana_sdk::pubkey::new_rand(),
&mut existing_account,
None, // filler_account_suffix
true, // preserve_rent_epoch_for_rent_exempt_accounts
);
assert!(existing_account.lamports() < old_lamports);
assert_eq!(
Expand Down Expand Up @@ -333,7 +308,6 @@ mod tests {
&pubkey,
&mut account,
None, // filler_account_suffix
true, // preserve_rent_epoch_for_rent_exempt_accounts
);
assert_eq!(account.lamports(), huge_lamports);
assert_eq!(collected, CollectedInfo::default());
Expand All @@ -346,7 +320,6 @@ mod tests {
&pubkey,
&mut account,
None, // filler_account_suffix
true, // preserve_rent_epoch_for_rent_exempt_accounts
);
assert_eq!(account.lamports(), tiny_lamports - collected.rent_amount);
assert_ne!(collected, CollectedInfo::default());
Expand All @@ -370,7 +343,6 @@ mod tests {
&pubkey,
&mut account,
None, // filler_account_suffix
true, // preserve_rent_epoch_for_rent_exempt_accounts
);
assert_eq!(account.lamports(), 0);
assert_eq!(collected.rent_amount, 1);
Expand All @@ -395,7 +367,6 @@ mod tests {
&Pubkey::new_unique(),
&mut account,
None, // filler_account_suffix
true, // preserve_rent_epoch_for_rent_exempt_accounts
);

assert_eq!(collected.rent_amount, account_lamports);
Expand Down