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 Nov 1, 2022
1 parent 17680fe commit bc7e38a
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 51 deletions.
3 changes: 0 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,6 @@ 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].executable);
for (int i = 0; i < accounts[ARGUMENT_INDEX].data_len; i++) {
sol_assert(accounts[ARGUMENT_INDEX].data[i] == i);
Expand All @@ -57,7 +56,6 @@ 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].executable);

sol_assert(
Expand All @@ -66,7 +64,6 @@ 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].executable);

sol_assert(SolPubkey_same(accounts[INVOKED_PROGRAM_INDEX].key,
Expand Down
3 changes: 0 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,6 @@ 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!(!accounts[ARGUMENT_INDEX].executable);
{
let data = accounts[ARGUMENT_INDEX].try_borrow_data()?;
Expand All @@ -65,14 +64,12 @@ 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!(!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!(accounts[INVOKED_PROGRAM_INDEX].executable);

assert_eq!(
Expand Down
113 changes: 91 additions & 22 deletions runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ 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 set_exempt_rent_epoch_max =
feature_set.is_active(&solana_sdk::feature_set::set_exempt_rent_epoch_max::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 @@ -299,6 +301,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 @@ -1492,19 +1495,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 @@ -1513,8 +1525,9 @@ mod tests {
tx: Transaction,
ka: &[TransactionAccount],
error_counters: &mut TransactionErrorMetrics,
exclude_features: Option<&[Pubkey]>,
) -> Vec<TransactionLoadResult> {
load_accounts_with_fee(tx, ka, 0, error_counters)
load_accounts_with_fee(tx, ka, 0, error_counters, exclude_features)
}

#[test]
Expand Down Expand Up @@ -1588,7 +1601,7 @@ mod tests {
instructions,
);

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

assert_eq!(error_counters.account_not_found, 1);
assert_eq!(loaded_accounts.len(), 1);
Expand Down Expand Up @@ -1622,7 +1635,7 @@ mod tests {
instructions,
);

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

assert_eq!(error_counters.account_not_found, 1);
assert_eq!(loaded_accounts.len(), 1);
Expand Down Expand Up @@ -1662,8 +1675,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 @@ -1693,7 +1711,7 @@ mod tests {
instructions,
);

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

assert_eq!(error_counters.invalid_account_for_fee, 1);
assert_eq!(loaded_accounts.len(), 1);
Expand Down Expand Up @@ -1743,7 +1761,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 @@ -1810,7 +1830,12 @@ mod tests {
instructions,
);

let loaded_accounts = load_accounts(tx, &accounts, &mut error_counters);
let loaded_accounts = load_accounts(
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 @@ -1881,7 +1906,7 @@ mod tests {
instructions,
);

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

assert_eq!(error_counters.call_chain_too_deep, 1);
assert_eq!(loaded_accounts.len(), 1);
Expand Down Expand Up @@ -1916,7 +1941,7 @@ mod tests {
instructions,
);

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

assert_eq!(error_counters.account_not_found, 1);
assert_eq!(loaded_accounts.len(), 1);
Expand Down Expand Up @@ -1950,7 +1975,7 @@ mod tests {
instructions,
);

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

assert_eq!(error_counters.invalid_program_for_execution, 1);
assert_eq!(loaded_accounts.len(), 1);
Expand Down Expand Up @@ -1998,7 +2023,12 @@ mod tests {
instructions,
);

let loaded_accounts = load_accounts(tx, &accounts, &mut error_counters);
let loaded_accounts = load_accounts(
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 @@ -2229,7 +2259,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(
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 @@ -2242,7 +2277,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(
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 @@ -2316,7 +2356,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(
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 @@ -2328,7 +2373,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(
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 @@ -2343,7 +2393,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(
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 @@ -2401,7 +2456,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(
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 @@ -2421,8 +2481,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(
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 @@ -2437,7 +2501,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(
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
15 changes: 12 additions & 3 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5326,6 +5326,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 @@ -7943,11 +7945,13 @@ pub(crate) mod tests {
ancestors::Ancestors,
bank_client::BankClient,
genesis_utils::{
self, activate_all_features, bootstrap_validator_stake_lamports,
create_genesis_config_with_leader, create_genesis_config_with_vote_accounts,
self, activate_all_features, activate_all_features_except,
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 @@ -8406,6 +8410,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 @@ -9848,7 +9853,10 @@ 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);
activate_all_features_except(
&mut genesis_config,
&[solana_sdk::feature_set::set_exempt_rent_epoch_max::id()],
);

let zero_lamport_pubkey = solana_sdk::pubkey::new_rand();
let rent_due_pubkey = solana_sdk::pubkey::new_rand();
Expand Down Expand Up @@ -19854,6 +19862,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
9 changes: 9 additions & 0 deletions runtime/src/genesis_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ pub fn activate_all_features(genesis_config: &mut GenesisConfig) {
}
}

pub fn activate_all_features_except(genesis_config: &mut GenesisConfig, except: &[Pubkey]) {
// Activate all features at genesis in development mode
for feature_id in FeatureSet::default().inactive {
if !except.contains(&feature_id) {
activate_feature(genesis_config, feature_id);
}
}
}

pub fn activate_feature(genesis_config: &mut GenesisConfig, feature_id: Pubkey) {
genesis_config.accounts.insert(
feature_id,
Expand Down
Loading

0 comments on commit bc7e38a

Please sign in to comment.