Skip to content

Commit

Permalink
v1.18: sdk: Rederive Copy on Rent and EpochSchedule (#1744)
Browse files Browse the repository at this point in the history
sdk: Rederive Clone on Rent and EpochSchedule
  • Loading branch information
joncinque authored Jun 17, 2024
1 parent cb502b4 commit 6a36903
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8997,8 +8997,10 @@ impl AccountsDb {
let schedule = &genesis_config.epoch_schedule;
let rent_collector = RentCollector::new(
schedule.get_epoch(max_slot),
#[allow(clippy::clone_on_copy)]
schedule.clone(),
genesis_config.slots_per_year(),
#[allow(clippy::clone_on_copy)]
genesis_config.rent.clone(),
);
let accounts_data_len = AtomicU64::new(0);
Expand Down
1 change: 1 addition & 0 deletions core/src/repair/ancestor_hashes_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,7 @@ mod test {
fn new(bank_forks: Arc<RwLock<BankForks>>) -> Self {
let ancestor_hashes_request_statuses = Arc::new(DashMap::new());
let ancestor_hashes_request_socket = Arc::new(UdpSocket::bind("0.0.0.0:0").unwrap());
#[allow(clippy::clone_on_copy)]
let epoch_schedule = bank_forks
.read()
.unwrap()
Expand Down
1 change: 1 addition & 0 deletions core/src/repair/repair_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2553,6 +2553,7 @@ mod test {
let stake = 100;
let (bank, vote_pubkeys) = bank_utils::setup_bank_and_vote_pubkeys_for_tests(10, stake);
let mut epoch_stakes = bank.epoch_stakes_map().clone();
#[allow(clippy::clone_on_copy)]
let mut epoch_schedule = bank.epoch_schedule().clone();

// Simulate epoch boundary at slot 10, where half of the stake deactivates
Expand Down
1 change: 1 addition & 0 deletions core/src/shred_fetch_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub(crate) struct ShredFetchStage {

impl ShredFetchStage {
// updates packets received on a channel and sends them on another channel
#[allow(clippy::clone_on_copy)]
fn modify_packets(
recvr: PacketBatchReceiver,
sendr: Sender<PacketBatch>,
Expand Down
1 change: 1 addition & 0 deletions core/src/tvu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ impl Tvu {
let (dumped_slots_sender, dumped_slots_receiver) = unbounded();
let (popular_pruned_forks_sender, popular_pruned_forks_receiver) = unbounded();
let window_service = {
#[allow(clippy::clone_on_copy)]
let epoch_schedule = bank_forks
.read()
.unwrap()
Expand Down
4 changes: 4 additions & 0 deletions genesis/src/stakes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ mod tests {
let total_lamports = staker_reserve + reserve * 2 + 1;
create_and_check_stakes(
&mut GenesisConfig {
#[allow(clippy::clone_on_copy)]
rent: rent.clone(),
..GenesisConfig::default()
},
Expand All @@ -272,6 +273,7 @@ mod tests {
let total_lamports = staker_reserve + reserve * 2 + 1;
create_and_check_stakes(
&mut GenesisConfig {
#[allow(clippy::clone_on_copy)]
rent: rent.clone(),
..GenesisConfig::default()
},
Expand All @@ -298,6 +300,7 @@ mod tests {
let total_lamports = staker_reserve + (granularity + reserve) * 2;
create_and_check_stakes(
&mut GenesisConfig {
#[allow(clippy::clone_on_copy)]
rent: rent.clone(),
..GenesisConfig::default()
},
Expand All @@ -323,6 +326,7 @@ mod tests {
let total_lamports = staker_reserve + (granularity + reserve + 1) * 2;
create_and_check_stakes(
&mut GenesisConfig {
#[allow(clippy::clone_on_copy)]
rent: rent.clone(),
..GenesisConfig::default()
},
Expand Down
1 change: 1 addition & 0 deletions ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3887,6 +3887,7 @@ pub mod tests {
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
#[allow(clippy::clone_on_copy)]
bank.epoch_schedule().clone()
}

Expand Down
1 change: 1 addition & 0 deletions ledger/src/leader_schedule_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub struct LeaderScheduleCache {

impl LeaderScheduleCache {
pub fn new_from_bank(bank: &Bank) -> Self {
#[allow(clippy::clone_on_copy)]
Self::new(bank.epoch_schedule().clone(), bank)
}

Expand Down
2 changes: 2 additions & 0 deletions programs/bpf_loader/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3362,8 +3362,10 @@ mod tests {

let mut sysvar_cache = SysvarCache::default();
sysvar_cache.set_clock(src_clock.clone());
#[allow(clippy::clone_on_copy)]
sysvar_cache.set_epoch_schedule(src_epochschedule.clone());
sysvar_cache.set_fees(src_fees.clone());
#[allow(clippy::clone_on_copy)]
sysvar_cache.set_rent(src_rent.clone());
sysvar_cache.set_epoch_rewards(src_rewards);

Expand Down
1 change: 1 addition & 0 deletions programs/vote/src/vote_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,7 @@ mod tests {
let processor_account = AccountSharedData::new(0, 0, &solana_sdk::native_loader::id());
let transaction_context = TransactionContext::new(
vec![(id(), processor_account), (node_pubkey, vote_account)],
#[allow(clippy::clone_on_copy)]
rent.clone(),
0,
0,
Expand Down
1 change: 1 addition & 0 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ impl JsonRpcRequestProcessor {
// Since epoch schedule data comes from the genesis config, any commitment level should be
// fine
let bank = self.bank(Some(CommitmentConfig::finalized()));
#[allow(clippy::clone_on_copy)]
bank.epoch_schedule().clone()
}

Expand Down
5 changes: 5 additions & 0 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,7 @@ impl Bank {
parent.freeze();
assert_ne!(slot, parent.slot());

#[allow(clippy::clone_on_copy)]
let epoch_schedule = parent.epoch_schedule().clone();
let epoch = epoch_schedule.get_epoch(slot);

Expand Down Expand Up @@ -1920,6 +1921,7 @@ impl Bank {
fee_rate_governor: self.fee_rate_governor.clone(),
collected_rent: self.collected_rent.load(Relaxed),
rent_collector: self.rent_collector.clone(),
#[allow(clippy::clone_on_copy)]
epoch_schedule: self.epoch_schedule.clone(),
inflation: *self.inflation.read().unwrap(),
stakes: &self.stakes_cache,
Expand Down Expand Up @@ -3748,6 +3750,7 @@ impl Bank {
self.parent_hash
}

#[allow(clippy::clone_on_copy)]
fn process_genesis_config(
&mut self,
genesis_config: &GenesisConfig,
Expand Down Expand Up @@ -4781,6 +4784,7 @@ impl Bank {

let mut transaction_context = TransactionContext::new(
transaction_accounts,
#[allow(clippy::clone_on_copy)]
self.rent_collector.rent.clone(),
compute_budget.max_invoke_stack_height,
compute_budget.max_instruction_trace_length,
Expand Down Expand Up @@ -7076,6 +7080,7 @@ impl Bank {
if config.run_in_background {
let ancestors = ancestors.clone();
let accounts = Arc::clone(accounts);
#[allow(clippy::clone_on_copy)]
let epoch_schedule = epoch_schedule.clone();
let rent_collector = rent_collector.clone();
let accounts_ = Arc::clone(&accounts);
Expand Down
1 change: 1 addition & 0 deletions runtime/src/snapshot_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ impl AccountsPackage {
expected_capitalization: bank.capitalization(),
accounts_hash_for_testing,
accounts: bank.accounts(),
#[allow(clippy::clone_on_copy)]
epoch_schedule: bank.epoch_schedule().clone(),
rent_collector: bank.rent_collector().clone(),
is_incremental_accounts_hash_feature_enabled,
Expand Down
1 change: 1 addition & 0 deletions sdk/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ pub fn derive_clone_zeroed(input: proc_macro::TokenStream) -> proc_macro::TokenS
// implementations on `Copy` types are simply wrappers of `Copy`.
// This is not the case here, and intentionally so because we want to
// guarantee zeroed padding.
#[allow(clippy::incorrect_clone_impl_on_copy_type)]
fn clone(&self) -> Self {
let mut value = std::mem::MaybeUninit::<Self>::uninit();
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion sdk/program/src/epoch_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub const MAX_LEADER_SCHEDULE_EPOCH_OFFSET: u64 = 3;
pub const MINIMUM_SLOTS_PER_EPOCH: u64 = 32;

#[repr(C)]
#[derive(Debug, CloneZeroed, PartialEq, Eq, Deserialize, Serialize, AbiExample)]
#[derive(Debug, CloneZeroed, Copy, PartialEq, Eq, Deserialize, Serialize, AbiExample)]
#[serde(rename_all = "camelCase")]
pub struct EpochSchedule {
/// The maximum number of slots in each epoch.
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, Debug, AbiExample)]
#[derive(Serialize, Deserialize, PartialEq, CloneZeroed, Copy, Debug, AbiExample)]
pub struct Rent {
/// Rental rate in lamports/byte-year.
pub lamports_per_byte_year: u64,
Expand Down
1 change: 1 addition & 0 deletions test-validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ impl TestValidator {
validator_stake_lamports,
validator_identity_lamports,
config.fee_rate_governor.clone(),
#[allow(clippy::clone_on_copy)]
config.rent.clone(),
solana_sdk::genesis_config::ClusterType::Development,
accounts.into_iter().collect(),
Expand Down

0 comments on commit 6a36903

Please sign in to comment.