diff --git a/program-runtime/src/loaded_programs.rs b/program-runtime/src/loaded_programs.rs index 1d3ed4deadb44c..75bf3a3c0f2ea7 100644 --- a/program-runtime/src/loaded_programs.rs +++ b/program-runtime/src/loaded_programs.rs @@ -473,21 +473,6 @@ impl Debug for LoadedPrograms { } } -impl Default for LoadedPrograms { - fn default() -> Self { - Self { - entries: HashMap::new(), - latest_root_slot: 0, - latest_root_epoch: 0, - environments: ProgramRuntimeEnvironments::default(), - upcoming_environments: None, - programs_to_recompile: Vec::default(), - stats: Stats::default(), - fork_graph: None, - } - } -} - #[derive(Clone, Debug, Default)] pub struct LoadedProgramsForTxBatch { /// Pubkey is the address of a program. @@ -562,6 +547,19 @@ pub enum LoadedProgramMatchCriteria { } impl LoadedPrograms { + pub fn new(root_slot: Slot, root_epoch: Epoch) -> Self { + Self { + entries: HashMap::new(), + latest_root_slot: root_slot, + latest_root_epoch: root_epoch, + environments: ProgramRuntimeEnvironments::default(), + upcoming_environments: None, + programs_to_recompile: Vec::default(), + stats: Stats::default(), + fork_graph: None, + } + } + pub fn set_fork_graph(&mut self, fork_graph: Arc>) { self.fork_graph = Some(fork_graph); } @@ -969,7 +967,7 @@ impl solana_frozen_abi::abi_example::AbiExample for LoadedProgram { impl solana_frozen_abi::abi_example::AbiExample for LoadedPrograms { fn example() -> Self { // LoadedPrograms isn't serializable by definition. - Self::default() + Self::new(Slot::default(), Epoch::default()) } } @@ -998,7 +996,8 @@ mod tests { std::sync::OnceLock::::new(); fn new_mock_cache() -> LoadedPrograms { - let mut cache = LoadedPrograms::default(); + let mut cache = LoadedPrograms::new(0, 0); + cache.environments.program_runtime_v1 = MOCK_ENVIRONMENT .get_or_init(|| Arc::new(BuiltinProgram::new_mock())) .clone(); diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 42c7414be4f129..1b1c0cefbd6504 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -1032,7 +1032,10 @@ impl Bank { accounts_data_size_delta_on_chain: AtomicI64::new(0), accounts_data_size_delta_off_chain: AtomicI64::new(0), fee_structure: FeeStructure::default(), - loaded_programs_cache: Arc::>>::default(), + loaded_programs_cache: Arc::new(RwLock::new(LoadedPrograms::new( + Slot::default(), + Epoch::default(), + ))), check_program_modification_slot: false, epoch_reward_status: EpochRewardStatus::default(), }; @@ -1880,7 +1883,10 @@ impl Bank { accounts_data_size_delta_on_chain: AtomicI64::new(0), accounts_data_size_delta_off_chain: AtomicI64::new(0), fee_structure: FeeStructure::default(), - loaded_programs_cache: Arc::>>::default(), + loaded_programs_cache: Arc::new(RwLock::new(LoadedPrograms::new( + fields.slot, + fields.epoch, + ))), check_program_modification_slot: false, epoch_reward_status: EpochRewardStatus::default(), };