Skip to content

Commit

Permalink
feature: set rent_epoch to Epoch::MAX (solana-labs#28690)
Browse files Browse the repository at this point in the history
* check android builds

* feature: set rent_epoch to Epoch::MAX

* tweaks

* Update runtime/src/rent_collector.rs

Co-authored-by: Brooks Prumo <[email protected]>

* simplify changes to tests

* back out some test changes

* calculate_rent_result passes through Exempt

* move calc outside loop

* if rent epoch is already max, use 'NoRentCollectionNow'

Co-authored-by: Brooks Prumo <[email protected]>
  • Loading branch information
2 people authored and nickfrosty committed Jan 4, 2023
1 parent 73b5d5b commit bb97507
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 152 deletions.
6 changes: 3 additions & 3 deletions programs/sbf/c/src/invoked/invoked.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extern uint64_t entrypoint(const uint8_t *input) {
sol_assert(accounts[ARGUMENT_INDEX].data_len == 100);
sol_assert(accounts[ARGUMENT_INDEX].is_signer);
sol_assert(accounts[ARGUMENT_INDEX].is_writable);
sol_assert(accounts[ARGUMENT_INDEX].rent_epoch == 0);
sol_assert(accounts[ARGUMENT_INDEX].rent_epoch == UINT64_MAX);
sol_assert(!accounts[ARGUMENT_INDEX].executable);
for (int i = 0; i < accounts[ARGUMENT_INDEX].data_len; i++) {
sol_assert(accounts[ARGUMENT_INDEX].data[i] == i);
Expand All @@ -57,7 +57,7 @@ extern uint64_t entrypoint(const uint8_t *input) {
sol_assert(accounts[INVOKED_ARGUMENT_INDEX].data_len == 10);
sol_assert(accounts[INVOKED_ARGUMENT_INDEX].is_signer);
sol_assert(accounts[INVOKED_ARGUMENT_INDEX].is_writable);
sol_assert(accounts[INVOKED_ARGUMENT_INDEX].rent_epoch == 0);
sol_assert(accounts[INVOKED_ARGUMENT_INDEX].rent_epoch == UINT64_MAX);
sol_assert(!accounts[INVOKED_ARGUMENT_INDEX].executable);

sol_assert(
Expand All @@ -66,7 +66,7 @@ extern uint64_t entrypoint(const uint8_t *input) {
&sbf_loader_id));
sol_assert(!accounts[INVOKED_PROGRAM_INDEX].is_signer);
sol_assert(!accounts[INVOKED_PROGRAM_INDEX].is_writable);
sol_assert(accounts[INVOKED_PROGRAM_INDEX].rent_epoch == 0);
sol_assert(accounts[INVOKED_PROGRAM_INDEX].rent_epoch == UINT64_MAX);
sol_assert(accounts[INVOKED_PROGRAM_INDEX].executable);

sol_assert(SolPubkey_same(accounts[INVOKED_PROGRAM_INDEX].key,
Expand Down
6 changes: 3 additions & 3 deletions programs/sbf/rust/invoked/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn process_instruction(
assert_eq!(accounts[ARGUMENT_INDEX].data_len(), 100);
assert!(accounts[ARGUMENT_INDEX].is_signer);
assert!(accounts[ARGUMENT_INDEX].is_writable);
assert_eq!(accounts[ARGUMENT_INDEX].rent_epoch, 0);
assert_eq!(accounts[ARGUMENT_INDEX].rent_epoch, u64::MAX);
assert!(!accounts[ARGUMENT_INDEX].executable);
{
let data = accounts[ARGUMENT_INDEX].try_borrow_data()?;
Expand All @@ -65,14 +65,14 @@ fn process_instruction(
assert_eq!(accounts[INVOKED_ARGUMENT_INDEX].data_len(), 10);
assert!(accounts[INVOKED_ARGUMENT_INDEX].is_signer);
assert!(accounts[INVOKED_ARGUMENT_INDEX].is_writable);
assert_eq!(accounts[INVOKED_ARGUMENT_INDEX].rent_epoch, 0);
assert_eq!(accounts[INVOKED_ARGUMENT_INDEX].rent_epoch, u64::MAX);
assert!(!accounts[INVOKED_ARGUMENT_INDEX].executable);

assert_eq!(accounts[INVOKED_PROGRAM_INDEX].key, program_id);
assert_eq!(accounts[INVOKED_PROGRAM_INDEX].owner, &bpf_loader::id());
assert!(!accounts[INVOKED_PROGRAM_INDEX].is_signer);
assert!(!accounts[INVOKED_PROGRAM_INDEX].is_writable);
assert_eq!(accounts[INVOKED_PROGRAM_INDEX].rent_epoch, 0);
assert_eq!(accounts[INVOKED_PROGRAM_INDEX].rent_epoch, u64::MAX);
assert!(accounts[INVOKED_PROGRAM_INDEX].executable);

assert_eq!(
Expand Down
3 changes: 3 additions & 0 deletions runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ impl Accounts {
};
let mut accumulated_accounts_data_size: usize = 0;

let set_exempt_rent_epoch_max =
feature_set.is_active(&solana_sdk::feature_set::set_exempt_rent_epoch_max::id());
let mut accounts = account_keys
.iter()
.enumerate()
Expand Down Expand Up @@ -309,6 +311,7 @@ impl Accounts {
key,
&mut account,
self.accounts_db.filler_account_suffix.as_ref(),
set_exempt_rent_epoch_max,
)
.rent_amount;
(account, rent_due)
Expand Down
20 changes: 16 additions & 4 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5338,12 +5338,16 @@ 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;
let set_exempt_rent_epoch_max: bool = self
.feature_set
.is_active(&solana_sdk::feature_set::set_exempt_rent_epoch_max::id());
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(),
set_exempt_rent_epoch_max,
));
time_collecting_rent_us += measure.as_us();

Expand Down Expand Up @@ -7974,11 +7978,12 @@ pub(crate) mod tests {
ancestors::Ancestors,
bank_client::BankClient,
genesis_utils::{
self, activate_all_features, bootstrap_validator_stake_lamports,
self, activate_all_features, activate_feature, bootstrap_validator_stake_lamports,
create_genesis_config_with_leader, create_genesis_config_with_vote_accounts,
genesis_sysvar_and_builtin_program_lamports, GenesisConfigInfo,
ValidatorVoteKeypairs,
},
rent_collector::TEST_SET_EXEMPT_RENT_EPOCH_MAX,
rent_paying_accounts_by_partition::RentPayingAccountsByPartition,
status_cache::MAX_CACHE_ENTRIES,
},
Expand Down Expand Up @@ -8436,6 +8441,7 @@ pub(crate) mod tests {
&keypairs[4].pubkey(),
&mut account_copy,
None,
TEST_SET_EXEMPT_RENT_EPOCH_MAX,
);
assert_eq!(expected_rent.rent_amount, too_few_lamports);
assert_eq!(account_copy.lamports(), 0);
Expand Down Expand Up @@ -9900,12 +9906,15 @@ pub(crate) mod tests {
solana_logger::setup();

let (mut genesis_config, _mint_keypair) = create_genesis_config(1_000_000);
activate_all_features(&mut genesis_config);
for feature_id in FeatureSet::default().inactive {
if feature_id != solana_sdk::feature_set::set_exempt_rent_epoch_max::id() {
activate_feature(&mut genesis_config, feature_id);
}
}

let zero_lamport_pubkey = solana_sdk::pubkey::new_rand();
let rent_due_pubkey = solana_sdk::pubkey::new_rand();
let rent_exempt_pubkey = solana_sdk::pubkey::new_rand();

let mut bank = Arc::new(Bank::new_for_tests(&genesis_config));
let zero_lamports = 0;
let little_lamports = 1234;
Expand Down Expand Up @@ -11942,7 +11951,9 @@ pub(crate) mod tests {
let mut expected_next_slot = expected_previous_slot + 1;

// First, initialize the clock sysvar
activate_all_features(&mut genesis_config);
for feature_id in FeatureSet::default().inactive {
activate_feature(&mut genesis_config, feature_id);
}
let bank1 = Arc::new(Bank::new_for_tests_with_config(
&genesis_config,
BankTestConfig::default(),
Expand Down Expand Up @@ -20033,6 +20044,7 @@ pub(crate) mod tests {
&keypair.pubkey(),
&mut account,
None,
TEST_SET_EXEMPT_RENT_EPOCH_MAX,
);
assert_eq!(info.account_data_len_reclaimed, data_size as u64);
}
Expand Down
Loading

0 comments on commit bb97507

Please sign in to comment.