Skip to content

Commit

Permalink
do not derive Copy for Rent
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Sep 25, 2023
1 parent 3f83275 commit 6bad80f
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions genesis/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
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(
Expand All @@ -558,7 +558,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.unwrap_or(identity_pubkey),
vote_pubkey,
&vote_account,
&rent,
&genesis_config.rent,
bootstrap_validator_stake_lamports,
),
);
Expand Down
8 changes: 4 additions & 4 deletions genesis/src/stakes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion programs/bpf_loader/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand Down
12 changes: 6 additions & 6 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sdk/program/src/rent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion sdk/src/transaction_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test-validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
Expand Down

0 comments on commit 6bad80f

Please sign in to comment.