diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index e89d4678166756..bcf0b8e0556625 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -571,7 +571,6 @@ impl PartialEq for Bank { fee_rate_governor, collected_rent, rent_collector, - epoch_schedule, inflation, stakes_cache, epoch_stakes, @@ -628,7 +627,7 @@ impl PartialEq for Bank { && fee_rate_governor == &other.fee_rate_governor && collected_rent.load(Relaxed) == other.collected_rent.load(Relaxed) && rent_collector == &other.rent_collector - && epoch_schedule == &other.epoch_schedule + && self.epoch_schedule() == other.epoch_schedule() && *inflation.read().unwrap() == *other.inflation.read().unwrap() && *stakes_cache.stakes() == *other.stakes_cache.stakes() && epoch_stakes == &other.epoch_stakes @@ -808,9 +807,6 @@ pub struct Bank { /// latest rent collector, knows the epoch rent_collector: RentCollector, - /// initialized from genesis - pub(crate) epoch_schedule: EpochSchedule, - /// inflation specs inflation: Arc>, @@ -974,7 +970,6 @@ impl Bank { fee_rate_governor: FeeRateGovernor::default(), collected_rent: AtomicU64::default(), rent_collector: RentCollector::default(), - epoch_schedule: EpochSchedule::default(), inflation: Arc::>::default(), stakes_cache: StakesCache::default(), epoch_stakes: HashMap::::default(), @@ -1004,12 +999,8 @@ impl Bank { transaction_account_lock_limit: None, }; - bank.transaction_processor = TransactionBatchProcessor::new( - bank.slot, - bank.epoch, - bank.epoch_schedule.clone(), - HashSet::default(), - ); + bank.transaction_processor = + TransactionBatchProcessor::new(bank.slot, bank.epoch, HashSet::default()); let accounts_data_size_initial = bank.get_total_accounts_stats().unwrap().data_len as u64; bank.accounts_data_size_initial = accounts_data_size_initial; @@ -1193,7 +1184,6 @@ impl Bank { ns_per_slot: parent.ns_per_slot, genesis_creation_time: parent.genesis_creation_time, slots_per_year: parent.slots_per_year, - epoch_schedule, collected_rent: AtomicU64::new(0), rent_collector: Self::get_rent_collector_from(&parent.rent_collector, epoch), max_tick_height: (slot + 1) * parent.ticks_per_slot, @@ -1375,7 +1365,7 @@ impl Bank { /// Epoch in which the new cooldown warmup rate for stake was activated pub fn new_warmup_cooldown_rate_epoch(&self) -> Option { self.feature_set - .new_warmup_cooldown_rate_epoch(&self.epoch_schedule) + .new_warmup_cooldown_rate_epoch(self.epoch_schedule()) } /// process for the start of a new epoch @@ -1414,7 +1404,7 @@ impl Bank { ); // Save a snapshot of stakes for use in consensus and stake weighted networking - let leader_schedule_epoch = self.epoch_schedule.get_leader_schedule_epoch(slot); + let leader_schedule_epoch = self.epoch_schedule().get_leader_schedule_epoch(slot); let (_, update_epoch_stakes_time) = measure!( self.update_epoch_stakes(leader_schedule_epoch), "update_epoch_stakes", @@ -1608,7 +1598,6 @@ impl Bank { collected_rent: AtomicU64::new(fields.collected_rent), // clone()-ing is needed to consider a gated behavior in rent_collector rent_collector: Self::get_rent_collector_from(&fields.rent_collector, fields.epoch), - epoch_schedule: fields.epoch_schedule, inflation: Arc::new(RwLock::new(fields.inflation)), stakes_cache: StakesCache::new(stakes), epoch_stakes: fields.epoch_stakes, @@ -1639,12 +1628,11 @@ impl Bank { transaction_account_lock_limit: runtime_config.transaction_account_lock_limit, }; - bank.transaction_processor = TransactionBatchProcessor::new( - bank.slot, - bank.epoch, - bank.epoch_schedule.clone(), - HashSet::default(), - ); + bank.transaction_processor = + TransactionBatchProcessor::new(bank.slot, bank.epoch, HashSet::default()); + + bank.transaction_processor + .set_epoch_schedule(&fields.epoch_schedule); let thread_pool = ThreadPoolBuilder::new() .thread_name(|i| format!("solBnkNewFlds{i:02}")) @@ -1685,8 +1673,8 @@ impl Bank { bank.ticks_per_slot, ) ); - assert_eq!(bank.epoch_schedule, genesis_config.epoch_schedule); - assert_eq!(bank.epoch, bank.epoch_schedule.get_epoch(bank.slot)); + assert_eq!(bank.epoch_schedule(), &genesis_config.epoch_schedule); + assert_eq!(bank.epoch, bank.epoch_schedule().get_epoch(bank.slot)); datapoint_info!( "bank-new-from-fields", @@ -1736,7 +1724,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.clone(), + epoch_schedule: self.epoch_schedule().clone(), inflation: *self.inflation.read().unwrap(), stakes: StakesEnum::from(self.stakes_cache.stakes().clone()), epoch_stakes: self.epoch_stakes.clone(), @@ -2856,7 +2844,7 @@ impl Bank { } pub fn epoch_schedule(&self) -> &EpochSchedule { - &self.epoch_schedule + self.transaction_processor.epoch_schedule() } /// squash the parent's state up into this Bank, @@ -2968,8 +2956,8 @@ 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.clone(); - self.transaction_processor.epoch_schedule = genesis_config.epoch_schedule.clone(); + self.transaction_processor + .set_epoch_schedule(&genesis_config.epoch_schedule); self.inflation = Arc::new(RwLock::new(genesis_config.inflation)); @@ -4504,7 +4492,7 @@ impl Bank { if !rent_paying_pubkeys.contains(pubkey) { let partition_from_pubkey = accounts_partition::partition_from_pubkey( pubkey, - self.epoch_schedule.slots_per_epoch, + self.epoch_schedule().slots_per_epoch, ); // Submit datapoint instead of assert while we verify this is correct datapoint_warn!( @@ -6016,7 +6004,7 @@ impl Bank { let config = CalcAccountsHashConfig { use_bg_thread_pool: true, ancestors: None, // does not matter, will not be used - epoch_schedule: &self.epoch_schedule, + epoch_schedule: self.epoch_schedule(), rent_collector: &self.rent_collector, store_detailed_debug_info_on_failure: false, }; @@ -7141,7 +7129,7 @@ impl Bank { pub fn new_program_cache_for_tx_batch_for_slot(&self, slot: Slot) -> ProgramCacheForTxBatch { ProgramCacheForTxBatch::new_from_cache( slot, - self.epoch_schedule.get_epoch(slot), + self.epoch_schedule().get_epoch(slot), &self.transaction_processor.program_cache.read().unwrap(), ) } diff --git a/runtime/src/bank/partitioned_epoch_rewards/distribution.rs b/runtime/src/bank/partitioned_epoch_rewards/distribution.rs index c627da706b1a38..8d360ad7d2b6c9 100644 --- a/runtime/src/bank/partitioned_epoch_rewards/distribution.rs +++ b/runtime/src/bank/partitioned_epoch_rewards/distribution.rs @@ -49,7 +49,7 @@ impl Bank { let distribution_end_exclusive = distribution_starting_block_height + status.stake_rewards_by_partition.len() as u64; assert!( - self.epoch_schedule.get_slots_in_epoch(self.epoch) + self.epoch_schedule().get_slots_in_epoch(self.epoch) > distribution_end_exclusive.saturating_sub(distribution_starting_block_height) ); @@ -278,7 +278,7 @@ mod tests { } #[test] - #[should_panic(expected = "self.epoch_schedule.get_slots_in_epoch")] + #[should_panic(expected = "self.epoch_schedule().get_slots_in_epoch")] fn test_distribute_partitioned_epoch_rewards_too_many_partitions() { let (genesis_config, _mint_keypair) = create_genesis_config(1_000_000 * LAMPORTS_PER_SOL); let mut bank = Bank::new_for_tests(&genesis_config); diff --git a/runtime/src/bank/partitioned_epoch_rewards/mod.rs b/runtime/src/bank/partitioned_epoch_rewards/mod.rs index f374b127050aef..671e76a0e3c1af 100644 --- a/runtime/src/bank/partitioned_epoch_rewards/mod.rs +++ b/runtime/src/bank/partitioned_epoch_rewards/mod.rs @@ -187,7 +187,7 @@ impl Bank { rewards: &PartitionedStakeRewards, ) -> u64 { let total_stake_accounts = rewards.len(); - if self.epoch_schedule.warmup && self.epoch < self.first_normal_epoch() { + if self.epoch_schedule().warmup && self.epoch < self.first_normal_epoch() { 1 } else { const MAX_FACTOR_OF_REWARD_BLOCKS_IN_EPOCH: u64 = 10; @@ -199,7 +199,8 @@ impl Bank { // Limit the reward credit interval to 10% of the total number of slots in a epoch num_chunks.clamp( 1, - (self.epoch_schedule.slots_per_epoch / MAX_FACTOR_OF_REWARD_BLOCKS_IN_EPOCH).max(1), + (self.epoch_schedule().slots_per_epoch / MAX_FACTOR_OF_REWARD_BLOCKS_IN_EPOCH) + .max(1), ) } } diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index 46d36d38310049..d686c524fdae3b 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -8149,10 +8149,10 @@ fn test_update_clock_timestamp() { } fn poh_estimate_offset(bank: &Bank) -> Duration { - let mut epoch_start_slot = bank.epoch_schedule.get_first_slot_in_epoch(bank.epoch()); + let mut epoch_start_slot = bank.epoch_schedule().get_first_slot_in_epoch(bank.epoch()); if epoch_start_slot == bank.slot() { epoch_start_slot = bank - .epoch_schedule + .epoch_schedule() .get_first_slot_in_epoch(bank.epoch() - 1); } bank.slot().saturating_sub(epoch_start_slot) as u32 @@ -9116,10 +9116,7 @@ fn test_epoch_schedule_from_genesis_config() { Arc::default(), )); - assert_eq!( - &bank.transaction_processor.epoch_schedule, - &genesis_config.epoch_schedule - ); + assert_eq!(bank.epoch_schedule(), &genesis_config.epoch_schedule); } fn check_stake_vote_account_validity(check_owner_change: bool, load_vote_and_stake_accounts: F) diff --git a/svm/src/program_loader.rs b/svm/src/program_loader.rs index 6060e8bb3db453..c1b2f5ade3c6a1 100644 --- a/svm/src/program_loader.rs +++ b/svm/src/program_loader.rs @@ -494,7 +494,7 @@ mod tests { &batch_processor.get_environments_for_epoch(50).unwrap(), &key, 500, - &batch_processor.epoch_schedule, + batch_processor.epoch_schedule(), false, ); assert!(result.is_none()); @@ -517,7 +517,7 @@ mod tests { &batch_processor.get_environments_for_epoch(20).unwrap(), &key, 0, // Slot 0 - &batch_processor.epoch_schedule, + batch_processor.epoch_schedule(), false, ); @@ -552,7 +552,7 @@ mod tests { &batch_processor.get_environments_for_epoch(20).unwrap(), &key, 200, - &batch_processor.epoch_schedule, + batch_processor.epoch_schedule(), false, ); let loaded_program = ProgramCacheEntry::new_tombstone( @@ -580,7 +580,7 @@ mod tests { &batch_processor.get_environments_for_epoch(20).unwrap(), &key, 200, - &batch_processor.epoch_schedule, + batch_processor.epoch_schedule(), false, ); @@ -634,7 +634,7 @@ mod tests { &batch_processor.get_environments_for_epoch(0).unwrap(), &key1, 0, - &batch_processor.epoch_schedule, + batch_processor.epoch_schedule(), false, ); let loaded_program = ProgramCacheEntry::new_tombstone( @@ -672,7 +672,7 @@ mod tests { &batch_processor.get_environments_for_epoch(20).unwrap(), &key1, 200, - &batch_processor.epoch_schedule, + batch_processor.epoch_schedule(), false, ); @@ -722,7 +722,7 @@ mod tests { &batch_processor.get_environments_for_epoch(0).unwrap(), &key, 0, - &batch_processor.epoch_schedule, + batch_processor.epoch_schedule(), false, ); let loaded_program = ProgramCacheEntry::new_tombstone( @@ -756,7 +756,7 @@ mod tests { &batch_processor.get_environments_for_epoch(20).unwrap(), &key, 200, - &batch_processor.epoch_schedule, + batch_processor.epoch_schedule(), false, ); @@ -807,7 +807,7 @@ mod tests { .unwrap(), &key, 200, - &batch_processor.epoch_schedule, + batch_processor.epoch_schedule(), false, ) .unwrap(); diff --git a/svm/src/transaction_processor.rs b/svm/src/transaction_processor.rs index cc0cbcdac5775e..b837159abf647e 100644 --- a/svm/src/transaction_processor.rs +++ b/svm/src/transaction_processor.rs @@ -147,7 +147,7 @@ pub struct TransactionBatchProcessor { epoch: Epoch, /// initialized from genesis - pub epoch_schedule: EpochSchedule, + epoch_schedule: EpochSchedule, /// Transaction fee structure pub fee_structure: FeeStructure, @@ -195,16 +195,11 @@ impl Default for TransactionBatchProcessor { } impl TransactionBatchProcessor { - pub fn new( - slot: Slot, - epoch: Epoch, - epoch_schedule: EpochSchedule, - builtin_program_ids: HashSet, - ) -> Self { + pub fn new(slot: Slot, epoch: Epoch, builtin_program_ids: HashSet) -> Self { Self { slot, epoch, - epoch_schedule, + epoch_schedule: EpochSchedule::default(), fee_structure: FeeStructure::default(), sysvar_cache: RwLock::::default(), program_cache: Arc::new(RwLock::new(ProgramCache::new(slot, epoch))), @@ -224,6 +219,14 @@ impl TransactionBatchProcessor { } } + pub fn set_epoch_schedule(&mut self, epoch_schedule: &EpochSchedule) { + self.epoch_schedule = epoch_schedule.clone() + } + + pub fn epoch_schedule(&self) -> &EpochSchedule { + &self.epoch_schedule + } + /// Returns the current environments depending on the given epoch /// Returns None if the call could result in a deadlock #[cfg_attr(feature = "dev-context-only-utils", qualifiers(pub))] @@ -1856,12 +1859,7 @@ mod tests { #[test] fn fast_concur_test() { let mut mock_bank = MockBankCallback::default(); - let batch_processor = TransactionBatchProcessor::::new( - 5, - 5, - EpochSchedule::default(), - HashSet::new(), - ); + let batch_processor = TransactionBatchProcessor::::new(5, 5, HashSet::new()); batch_processor.program_cache.write().unwrap().fork_graph = Some(Arc::new(RwLock::new(TestForkGraph {}))); diff --git a/svm/tests/conformance.rs b/svm/tests/conformance.rs index ec5bbe0c9fd529..7bea9144289bc3 100644 --- a/svm/tests/conformance.rs +++ b/svm/tests/conformance.rs @@ -21,7 +21,6 @@ use { solana_sdk::{ account::{AccountSharedData, ReadableAccount, WritableAccount}, bpf_loader_upgradeable, - epoch_schedule::EpochSchedule, feature_set::{FeatureSet, FEATURE_NAMES}, hash::Hash, instruction::AccountMeta, @@ -247,12 +246,7 @@ fn run_fixture(fixture: InstrFixture, filename: OsString, execute_as_instr: bool create_program_runtime_environment_v1(&feature_set, &compute_budget, false, false).unwrap(); mock_bank.override_feature_set(feature_set); - let batch_processor = TransactionBatchProcessor::::new( - 42, - 2, - EpochSchedule::default(), - HashSet::new(), - ); + let batch_processor = TransactionBatchProcessor::::new(42, 2, HashSet::new()); { let mut program_cache = batch_processor.program_cache.write().unwrap(); @@ -445,7 +439,7 @@ fn execute_fixture_as_instr( &batch_processor.get_environments_for_epoch(2).unwrap(), &program_id, 42, - &batch_processor.epoch_schedule, + batch_processor.epoch_schedule(), false, ) .unwrap(); diff --git a/svm/tests/integration_test.rs b/svm/tests/integration_test.rs index 9816d41cbc4dae..c47ce03af9b5a1 100644 --- a/svm/tests/integration_test.rs +++ b/svm/tests/integration_test.rs @@ -21,7 +21,6 @@ use { account::{AccountSharedData, ReadableAccount, WritableAccount}, bpf_loader_upgradeable::{self, UpgradeableLoaderState}, clock::{Clock, Epoch, Slot, UnixTimestamp}, - epoch_schedule::EpochSchedule, hash::Hash, instruction::AccountMeta, pubkey::Pubkey, @@ -445,7 +444,6 @@ fn svm_integration() { let batch_processor = TransactionBatchProcessor::::new( EXECUTION_SLOT, EXECUTION_EPOCH, - EpochSchedule::default(), HashSet::new(), );