Skip to content

Commit

Permalink
feature: set rent_epoch to Epoch::MAX
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed Dec 7, 2022
1 parent d4af5c7 commit 9b41c9d
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 32 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 == 18446744073709551615);
sol_assert(accounts[ARGUMENT_INDEX].rent_epoch == 18446744073709551615ul);
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 == 18446744073709551615);
sol_assert(accounts[INVOKED_ARGUMENT_INDEX].rent_epoch == 18446744073709551615ul);
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 == 18446744073709551615);
sol_assert(accounts[INVOKED_PROGRAM_INDEX].rent_epoch == 18446744073709551615ul);
sol_assert(accounts[INVOKED_PROGRAM_INDEX].executable);

sol_assert(SolPubkey_same(accounts[INVOKED_PROGRAM_INDEX].key,
Expand Down
109 changes: 93 additions & 16 deletions runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,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 @@ -316,6 +318,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 Expand Up @@ -1600,19 +1603,28 @@ mod tests {
)
}

fn all_features_except(exclude: Option<&[Pubkey]>) -> FeatureSet {
let mut features = FeatureSet::all_enabled();
if let Some(exclude) = exclude {
features.active.retain(|k, _v| !exclude.contains(k));
}
features
}

fn load_accounts_with_fee(
tx: Transaction,
ka: &[TransactionAccount],
lamports_per_signature: u64,
error_counters: &mut TransactionErrorMetrics,
exclude_features: Option<&[Pubkey]>,
) -> Vec<TransactionLoadResult> {
load_accounts_with_fee_and_rent(
tx,
ka,
lamports_per_signature,
&RentCollector::default(),
error_counters,
&FeatureSet::all_enabled(),
&all_features_except(exclude_features),
&FeeStructure::default(),
)
}
Expand All @@ -1622,7 +1634,16 @@ mod tests {
ka: &[TransactionAccount],
error_counters: &mut TransactionErrorMetrics,
) -> Vec<TransactionLoadResult> {
load_accounts_with_fee(tx, ka, 0, error_counters)
load_accounts_with_excluded_features(tx, ka, error_counters, None)
}

fn load_accounts_with_excluded_features(
tx: Transaction,
ka: &[TransactionAccount],
error_counters: &mut TransactionErrorMetrics,
exclude_features: Option<&[Pubkey]>,
) -> Vec<TransactionLoadResult> {
load_accounts_with_fee(tx, ka, 0, error_counters, exclude_features)
}

#[test]
Expand Down Expand Up @@ -1771,8 +1792,13 @@ mod tests {
);
assert_eq!(fee, lamports_per_signature);

let loaded_accounts =
load_accounts_with_fee(tx, &accounts, lamports_per_signature, &mut error_counters);
let loaded_accounts = load_accounts_with_fee(
tx,
&accounts,
lamports_per_signature,
&mut error_counters,
None,
);

assert_eq!(error_counters.insufficient_funds, 1);
assert_eq!(loaded_accounts.len(), 1);
Expand Down Expand Up @@ -1852,7 +1878,9 @@ mod tests {
lamports_per_signature,
&rent_collector,
&mut error_counters,
&FeatureSet::all_enabled(),
&all_features_except(Some(&[
solana_sdk::feature_set::set_exempt_rent_epoch_max::id(),
])),
&FeeStructure::default(),
);
assert_eq!(loaded_accounts.len(), 1);
Expand Down Expand Up @@ -1919,7 +1947,12 @@ mod tests {
instructions,
);

let loaded_accounts = load_accounts(tx, &accounts, &mut error_counters);
let loaded_accounts = load_accounts_with_excluded_features(
tx,
&accounts,
&mut error_counters,
Some(&[solana_sdk::feature_set::set_exempt_rent_epoch_max::id()]),
);

assert_eq!(error_counters.account_not_found, 0);
assert_eq!(loaded_accounts.len(), 1);
Expand Down Expand Up @@ -2107,7 +2140,12 @@ mod tests {
instructions,
);

let loaded_accounts = load_accounts(tx, &accounts, &mut error_counters);
let loaded_accounts = load_accounts_with_excluded_features(
tx,
&accounts,
&mut error_counters,
Some(&[solana_sdk::feature_set::set_exempt_rent_epoch_max::id()]),
);

assert_eq!(error_counters.account_not_found, 0);
assert_eq!(loaded_accounts.len(), 1);
Expand Down Expand Up @@ -2338,7 +2376,12 @@ mod tests {
instructions,
);
let tx = Transaction::new(&[&keypair], message.clone(), Hash::default());
let loaded_accounts = load_accounts(tx, &accounts, &mut error_counters);
let loaded_accounts = load_accounts_with_excluded_features(
tx,
&accounts,
&mut error_counters,
Some(&[solana_sdk::feature_set::set_exempt_rent_epoch_max::id()]),
);

assert_eq!(error_counters.invalid_writable_account, 1);
assert_eq!(loaded_accounts.len(), 1);
Expand All @@ -2351,7 +2394,12 @@ mod tests {
message.account_keys = vec![key0, key1, key2]; // revert key change
message.header.num_readonly_unsigned_accounts = 2; // mark both executables as readonly
let tx = Transaction::new(&[&keypair], message, Hash::default());
let loaded_accounts = load_accounts(tx, &accounts, &mut error_counters);
let loaded_accounts = load_accounts_with_excluded_features(
tx,
&accounts,
&mut error_counters,
Some(&[solana_sdk::feature_set::set_exempt_rent_epoch_max::id()]),
);

assert_eq!(error_counters.invalid_writable_account, 1);
assert_eq!(loaded_accounts.len(), 1);
Expand Down Expand Up @@ -2425,7 +2473,12 @@ mod tests {
instructions,
);
let tx = Transaction::new(&[&keypair], message.clone(), Hash::default());
let loaded_accounts = load_accounts(tx, &accounts, &mut error_counters);
let loaded_accounts = load_accounts_with_excluded_features(
tx,
&accounts,
&mut error_counters,
Some(&[solana_sdk::feature_set::set_exempt_rent_epoch_max::id()]),
);

assert_eq!(error_counters.invalid_writable_account, 1);
assert_eq!(loaded_accounts.len(), 1);
Expand All @@ -2437,7 +2490,12 @@ mod tests {
// Solution 1: include bpf_loader_upgradeable account
message.account_keys = vec![key0, key1, bpf_loader_upgradeable::id()];
let tx = Transaction::new(&[&keypair], message.clone(), Hash::default());
let loaded_accounts = load_accounts(tx, &accounts, &mut error_counters);
let loaded_accounts = load_accounts_with_excluded_features(
tx,
&accounts,
&mut error_counters,
Some(&[solana_sdk::feature_set::set_exempt_rent_epoch_max::id()]),
);

assert_eq!(error_counters.invalid_writable_account, 1);
assert_eq!(loaded_accounts.len(), 1);
Expand All @@ -2452,7 +2510,12 @@ mod tests {
message.account_keys = vec![key0, key1, key2]; // revert key change
message.header.num_readonly_unsigned_accounts = 2; // mark both executables as readonly
let tx = Transaction::new(&[&keypair], message, Hash::default());
let loaded_accounts = load_accounts(tx, &accounts, &mut error_counters);
let loaded_accounts = load_accounts_with_excluded_features(
tx,
&accounts,
&mut error_counters,
Some(&[solana_sdk::feature_set::set_exempt_rent_epoch_max::id()]),
);

assert_eq!(error_counters.invalid_writable_account, 1);
assert_eq!(loaded_accounts.len(), 1);
Expand Down Expand Up @@ -2510,7 +2573,12 @@ mod tests {
instructions,
);
let tx = Transaction::new(&[&keypair], message.clone(), Hash::default());
let loaded_accounts = load_accounts(tx, &accounts, &mut error_counters);
let loaded_accounts = load_accounts_with_excluded_features(
tx,
&accounts,
&mut error_counters,
Some(&[solana_sdk::feature_set::set_exempt_rent_epoch_max::id()]),
);

assert_eq!(error_counters.invalid_writable_account, 1);
assert_eq!(loaded_accounts.len(), 1);
Expand All @@ -2530,8 +2598,12 @@ mod tests {
];
message.account_keys = vec![key0, key1, bpf_loader_upgradeable::id()];
let tx = Transaction::new(&[&keypair], message.clone(), Hash::default());
let loaded_accounts =
load_accounts(tx, &accounts_with_upgradeable_loader, &mut error_counters);
let loaded_accounts = load_accounts_with_excluded_features(
tx,
&accounts_with_upgradeable_loader,
&mut error_counters,
Some(&[solana_sdk::feature_set::set_exempt_rent_epoch_max::id()]),
);

assert_eq!(error_counters.invalid_writable_account, 1);
assert_eq!(loaded_accounts.len(), 1);
Expand All @@ -2546,7 +2618,12 @@ mod tests {
message.account_keys = vec![key0, key1, key2]; // revert key change
message.header.num_readonly_unsigned_accounts = 2; // extend readonly set to include programdata
let tx = Transaction::new(&[&keypair], message, Hash::default());
let loaded_accounts = load_accounts(tx, &accounts, &mut error_counters);
let loaded_accounts = load_accounts_with_excluded_features(
tx,
&accounts,
&mut error_counters,
Some(&[solana_sdk::feature_set::set_exempt_rent_epoch_max::id()]),
);

assert_eq!(error_counters.invalid_writable_account, 1);
assert_eq!(loaded_accounts.len(), 1);
Expand Down
17 changes: 13 additions & 4 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5378,6 +5378,8 @@ impl Bank {
pubkey,
account,
self.rc.accounts.accounts_db.filler_account_suffix.as_ref(),
self.feature_set
.is_active(&solana_sdk::feature_set::set_exempt_rent_epoch_max::id()),
));
time_collecting_rent_us += measure.as_us();

Expand Down Expand Up @@ -8051,11 +8053,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 @@ -8513,6 +8516,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 @@ -9979,13 +9983,17 @@ 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 bank = Bank::new_for_tests(&genesis_config);
let mut bank = Arc::new(bank);
let zero_lamports = 0;
let little_lamports = 1234;
let large_lamports = 123_456_789;
Expand Down Expand Up @@ -20270,6 +20278,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 9b41c9d

Please sign in to comment.