From 6bad80f454a3515f0f532ae10cd278c95f4d0248 Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Mon, 18 Sep 2023 20:56:10 +0000 Subject: [PATCH] do not derive Copy for Rent --- accounts-db/src/accounts_db.rs | 2 +- genesis/src/main.rs | 4 ++-- genesis/src/stakes.rs | 8 ++++---- programs/bpf_loader/src/syscalls/mod.rs | 2 +- runtime/src/bank.rs | 12 ++++++------ runtime/src/bank/tests.rs | 4 ++-- sdk/program/src/rent.rs | 2 +- sdk/src/transaction_context.rs | 3 ++- test-validator/src/lib.rs | 2 +- 9 files changed, 20 insertions(+), 19 deletions(-) diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index 75ced5bbf33970..7b02ea08c098c5 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -9130,7 +9130,7 @@ impl AccountsDb { schedule.get_epoch(max_slot), schedule.clone(), genesis_config.slots_per_year(), - genesis_config.rent, + genesis_config.rent.clone(), ); let accounts_data_len = AtomicU64::new(0); diff --git a/genesis/src/main.rs b/genesis/src/main.rs index c254975379c937..6b7efd5e664339 100644 --- a/genesis/src/main.rs +++ b/genesis/src/main.rs @@ -547,7 +547,7 @@ fn main() -> Result<(), Box> { identity_pubkey, identity_pubkey, commission, - VoteState::get_rent_exempt_reserve(&rent).max(1), + VoteState::get_rent_exempt_reserve(&genesis_config.rent).max(1), ); genesis_config.add_account( @@ -558,7 +558,7 @@ fn main() -> Result<(), Box> { .unwrap_or(identity_pubkey), vote_pubkey, &vote_account, - &rent, + &genesis_config.rent, bootstrap_validator_stake_lamports, ), ); diff --git a/genesis/src/stakes.rs b/genesis/src/stakes.rs index 1d7c18f3a034a9..133fdf57f4968b 100644 --- a/genesis/src/stakes.rs +++ b/genesis/src/stakes.rs @@ -246,7 +246,7 @@ mod tests { let total_lamports = staker_reserve + reserve * 2 + 1; create_and_check_stakes( &mut GenesisConfig { - rent, + rent: rent.clone(), ..GenesisConfig::default() }, &StakerInfo { @@ -272,7 +272,7 @@ mod tests { let total_lamports = staker_reserve + reserve * 2 + 1; create_and_check_stakes( &mut GenesisConfig { - rent, + rent: rent.clone(), ..GenesisConfig::default() }, &StakerInfo { @@ -298,7 +298,7 @@ mod tests { let total_lamports = staker_reserve + (granularity + reserve) * 2; create_and_check_stakes( &mut GenesisConfig { - rent, + rent: rent.clone(), ..GenesisConfig::default() }, &StakerInfo { @@ -323,7 +323,7 @@ mod tests { let total_lamports = staker_reserve + (granularity + reserve + 1) * 2; create_and_check_stakes( &mut GenesisConfig { - rent, + rent: rent.clone(), ..GenesisConfig::default() }, &StakerInfo { diff --git a/programs/bpf_loader/src/syscalls/mod.rs b/programs/bpf_loader/src/syscalls/mod.rs index ea1d03c3b3635a..8948593ec0baf6 100644 --- a/programs/bpf_loader/src/syscalls/mod.rs +++ b/programs/bpf_loader/src/syscalls/mod.rs @@ -3446,7 +3446,7 @@ mod tests { sysvar_cache.set_clock(src_clock.clone()); sysvar_cache.set_epoch_schedule(src_epochschedule.clone()); sysvar_cache.set_fees(src_fees.clone()); - sysvar_cache.set_rent(src_rent); + sysvar_cache.set_rent(src_rent.clone()); sysvar_cache.set_epoch_rewards(src_rewards); let transaction_accounts = vec![ diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 4348680541f2b3..e2708ef53d301a 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -3883,7 +3883,7 @@ impl Bank { self.epoch, self.epoch_schedule().clone(), self.slots_per_year, - genesis_config.rent, + genesis_config.rent.clone(), ); // Add additional builtin programs specified in the genesis config @@ -4830,7 +4830,7 @@ impl Bank { .feature_set .is_active(&enable_early_verification_of_account_modifications::id()) { - Some(self.rent_collector.rent) + Some(self.rent_collector.rent.clone()) } else { None }, @@ -4883,7 +4883,7 @@ impl Bank { tx.message(), &loaded_transaction.program_indices, &mut transaction_context, - self.rent_collector.rent, + self.rent_collector.rent.clone(), log_collector.clone(), programs_loaded_for_tx_batch, &mut programs_modified_by_tx, @@ -5763,10 +5763,10 @@ impl Bank { let mut account = self .get_account_with_fixed_root(&pubkey) .unwrap_or_default(); - let rent = self.rent_collector().rent; - let recipient_pre_rent_state = RentState::from_account(&account, &rent); + let rent = &self.rent_collector().rent; + let recipient_pre_rent_state = RentState::from_account(&account, rent); let distribution = account.checked_add_lamports(rent_to_be_paid); - let recipient_post_rent_state = RentState::from_account(&account, &rent); + let recipient_post_rent_state = RentState::from_account(&account, rent); let rent_state_transition_allowed = recipient_post_rent_state .transition_allowed_from(&recipient_pre_rent_state); if !rent_state_transition_allowed { diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index 3263eb9c41db7c..d630b071825ff6 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -1046,7 +1046,7 @@ fn test_distribute_rent_to_validators_rent_paying() { .unwrap(); } let bank = Bank::new_for_tests(&genesis_config); - let rent = bank.rent_collector().rent; + let rent = &bank.rent_collector().rent; let rent_exempt_minimum = rent.minimum_balance(0); // Make one validator have an empty identity account @@ -1084,7 +1084,7 @@ fn test_distribute_rent_to_validators_rent_paying() { let account = bank .get_account_with_fixed_root(address) .unwrap_or_default(); - RentState::from_account(&account, &rent) + RentState::from_account(&account, rent) }; // Assert starting RentStates diff --git a/sdk/program/src/rent.rs b/sdk/program/src/rent.rs index 7257b9a2073ec7..f2c52a4d5a98ee 100644 --- a/sdk/program/src/rent.rs +++ b/sdk/program/src/rent.rs @@ -8,7 +8,7 @@ use {crate::clock::DEFAULT_SLOTS_PER_EPOCH, solana_sdk_macro::CloneZeroed}; /// Configuration of network rent. #[repr(C)] -#[derive(Serialize, Deserialize, PartialEq, CloneZeroed, Copy, Debug, AbiExample)] +#[derive(Serialize, Deserialize, PartialEq, CloneZeroed, Debug, AbiExample)] pub struct Rent { /// Rental rate in lamports/byte-year. pub lamports_per_byte_year: u64, diff --git a/sdk/src/transaction_context.rs b/sdk/src/transaction_context.rs index cdfb162fc475a1..5ee99f26d8766a 100644 --- a/sdk/src/transaction_context.rs +++ b/sdk/src/transaction_context.rs @@ -1034,6 +1034,7 @@ impl<'a> BorrowedAccount<'a> { pub fn is_rent_exempt_at_data_length(&self, data_length: usize) -> bool { self.transaction_context .rent + .clone() .unwrap_or_default() .is_exempt(self.get_lamports(), data_length) } @@ -1047,7 +1048,7 @@ impl<'a> BorrowedAccount<'a> { /// Configures whether this account is executable (transaction wide) #[cfg(not(target_os = "solana"))] pub fn set_executable(&mut self, is_executable: bool) -> Result<(), InstructionError> { - if let Some(rent) = self.transaction_context.rent { + if let Some(rent) = &self.transaction_context.rent { // To become executable an account must be rent exempt if !rent.is_exempt(self.get_lamports(), self.get_data().len()) { return Err(InstructionError::ExecutableAccountNotRentExempt); diff --git a/test-validator/src/lib.rs b/test-validator/src/lib.rs index 2f1eb895dd2fac..9f994eee9a19df 100644 --- a/test-validator/src/lib.rs +++ b/test-validator/src/lib.rs @@ -777,7 +777,7 @@ impl TestValidator { validator_stake_lamports, validator_identity_lamports, config.fee_rate_governor.clone(), - config.rent, + config.rent.clone(), solana_sdk::genesis_config::ClusterType::Development, accounts.into_iter().collect(), );