Skip to content

Commit

Permalink
Do not derive Copy for EpochSchedule
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Oct 19, 2023
1 parent 0fcc0a0 commit 1d5d2e7
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 20 deletions.
6 changes: 3 additions & 3 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9160,17 +9160,17 @@ impl AccountsDb {
slots.truncate(limit); // get rid of the newer slots and keep just the older
}
let max_slot = slots.last().cloned().unwrap_or_default();
let schedule = genesis_config.epoch_schedule;
let schedule = &genesis_config.epoch_schedule;
let rent_collector = RentCollector::new(
schedule.get_epoch(max_slot),
schedule,
schedule.clone(),
genesis_config.slots_per_year(),
genesis_config.rent,
);
let accounts_data_len = AtomicU64::new(0);

let rent_paying_accounts_by_partition =
Mutex::new(RentPayingAccountsByPartition::new(&schedule));
Mutex::new(RentPayingAccountsByPartition::new(schedule));

// pass == 0 always runs and generates the index
// pass == 1 only runs if verify == true.
Expand Down
7 changes: 6 additions & 1 deletion core/src/repair/ancestor_hashes_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,12 @@ 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());
let epoch_schedule = *bank_forks.read().unwrap().root_bank().epoch_schedule();
let epoch_schedule = bank_forks
.read()
.unwrap()
.root_bank()
.epoch_schedule()
.clone();
let keypair = Keypair::new();
let requester_cluster_info = Arc::new(ClusterInfo::new(
Node::new_localhost_with_pubkey(&keypair.pubkey()).info,
Expand Down
2 changes: 1 addition & 1 deletion core/src/repair/repair_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2553,7 +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();
let mut epoch_schedule = *bank.epoch_schedule();
let mut epoch_schedule = bank.epoch_schedule().clone();

// Simulate epoch boundary at slot 10, where half of the stake deactivates
// Additional epoch boundary at slot 20, where 30% of the stake reactivates
Expand Down
7 changes: 6 additions & 1 deletion core/src/tvu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ impl Tvu {
let (dumped_slots_sender, dumped_slots_receiver) = unbounded();
let (popular_pruned_forks_sender, popular_pruned_forks_receiver) = unbounded();
let window_service = {
let epoch_schedule = *bank_forks.read().unwrap().working_bank().epoch_schedule();
let epoch_schedule = bank_forks
.read()
.unwrap()
.working_bank()
.epoch_schedule()
.clone();
let repair_info = RepairInfo {
bank_forks: bank_forks.clone(),
epoch_schedule,
Expand Down
2 changes: 1 addition & 1 deletion ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3766,7 +3766,7 @@ pub mod tests {
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
*bank.epoch_schedule()
bank.epoch_schedule().clone()
}

fn frozen_bank_slots(bank_forks: &BankForks) -> Vec<Slot> {
Expand Down
4 changes: 2 additions & 2 deletions ledger/src/leader_schedule_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ pub struct LeaderScheduleCache {

impl LeaderScheduleCache {
pub fn new_from_bank(bank: &Bank) -> Self {
Self::new(*bank.epoch_schedule(), bank)
Self::new(bank.epoch_schedule().clone(), bank)
}

pub fn new(epoch_schedule: EpochSchedule, root_bank: &Bank) -> Self {
let cache = Self {
cached_schedules: RwLock::new((HashMap::new(), VecDeque::new())),
epoch_schedule,
epoch_schedule: epoch_schedule.clone(),
max_epoch: RwLock::new(0),
max_schedules: CacheCapacity::default(),
fixed_schedule: None,
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 @@ -3440,7 +3440,7 @@ mod tests {

let mut sysvar_cache = SysvarCache::default();
sysvar_cache.set_clock(src_clock.clone());
sysvar_cache.set_epoch_schedule(src_epochschedule);
sysvar_cache.set_epoch_schedule(src_epochschedule.clone());
sysvar_cache.set_fees(src_fees.clone());
sysvar_cache.set_rent(src_rent);
sysvar_cache.set_epoch_rewards(src_rewards);
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,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()));
*bank.epoch_schedule()
bank.epoch_schedule().clone()
}

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

let epoch_schedule = parent.epoch_schedule;
let epoch_schedule = parent.epoch_schedule().clone();
let epoch = epoch_schedule.get_epoch(slot);

let (rc, bank_rc_creation_time_us) = measure_us!({
Expand Down Expand Up @@ -1447,7 +1447,7 @@ impl Bank {
);
} else {
// Save a snapshot of stakes for use in consensus and stake weighted networking
let leader_schedule_epoch = epoch_schedule.get_leader_schedule_epoch(slot);
let leader_schedule_epoch = new.epoch_schedule().get_leader_schedule_epoch(slot);
new.update_epoch_stakes(leader_schedule_epoch);
}
if new.is_partitioned_rewards_code_enabled() {
Expand Down Expand Up @@ -1946,7 +1946,7 @@ impl Bank {
fee_rate_governor: self.fee_rate_governor.clone(),
collected_rent: self.collected_rent.load(Relaxed),
rent_collector: self.rent_collector.clone(),
epoch_schedule: self.epoch_schedule,
epoch_schedule: self.epoch_schedule.clone(),
inflation: *self.inflation.read().unwrap(),
stakes: &self.stakes_cache,
epoch_stakes: &self.epoch_stakes,
Expand Down Expand Up @@ -3888,13 +3888,13 @@ impl Bank {
self.max_tick_height = (self.slot + 1) * self.ticks_per_slot;
self.slots_per_year = genesis_config.slots_per_year();

self.epoch_schedule = genesis_config.epoch_schedule;
self.epoch_schedule = genesis_config.epoch_schedule.clone();

self.inflation = Arc::new(RwLock::new(genesis_config.inflation));

self.rent_collector = RentCollector::new(
self.epoch,
*self.epoch_schedule(),
self.epoch_schedule().clone(),
self.slots_per_year,
genesis_config.rent,
);
Expand Down Expand Up @@ -7252,7 +7252,7 @@ impl Bank {
if config.run_in_background {
let ancestors = ancestors.clone();
let accounts = Arc::clone(accounts);
let epoch_schedule = *epoch_schedule;
let epoch_schedule = epoch_schedule.clone();
let rent_collector = rent_collector.clone();
let accounts_ = Arc::clone(&accounts);
accounts.accounts_db.verify_accounts_hash_in_bg.start(|| {
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/snapshot_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl AccountsPackage {
expected_capitalization: bank.capitalization(),
accounts_hash_for_testing,
accounts: bank.accounts(),
epoch_schedule: *bank.epoch_schedule(),
epoch_schedule: bank.epoch_schedule().clone(),
rent_collector: bank.rent_collector().clone(),
is_incremental_accounts_hash_feature_enabled,
include_slot_in_hash: bank.include_slot_in_hash(),
Expand Down
1 change: 0 additions & 1 deletion sdk/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ 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, Copy, PartialEq, Eq, Deserialize, Serialize, AbiExample)]
#[derive(Debug, CloneZeroed, PartialEq, Eq, Deserialize, Serialize, AbiExample)]
#[serde(rename_all = "camelCase")]
pub struct EpochSchedule {
/// The maximum number of slots in each epoch.
Expand Down
2 changes: 2 additions & 0 deletions test-validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,8 @@ impl TestValidator {
);
genesis_config.epoch_schedule = config
.epoch_schedule
.as_ref()
.cloned()
.unwrap_or_else(EpochSchedule::without_warmup);

if let Some(ticks_per_slot) = config.ticks_per_slot {
Expand Down

0 comments on commit 1d5d2e7

Please sign in to comment.