Skip to content

Commit

Permalink
Set root slot/epoch in cache constructor (#34447)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgarg66 authored Dec 14, 2023
1 parent fe7970c commit 47dab26
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
33 changes: 16 additions & 17 deletions program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,21 +473,6 @@ impl<FG: ForkGraph> Debug for LoadedPrograms<FG> {
}
}

impl<FG: ForkGraph> Default for LoadedPrograms<FG> {
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.
Expand Down Expand Up @@ -562,6 +547,19 @@ pub enum LoadedProgramMatchCriteria {
}

impl<FG: ForkGraph> LoadedPrograms<FG> {
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<RwLock<FG>>) {
self.fork_graph = Some(fork_graph);
}
Expand Down Expand Up @@ -969,7 +967,7 @@ impl solana_frozen_abi::abi_example::AbiExample for LoadedProgram {
impl<FG: ForkGraph> solana_frozen_abi::abi_example::AbiExample for LoadedPrograms<FG> {
fn example() -> Self {
// LoadedPrograms isn't serializable by definition.
Self::default()
Self::new(Slot::default(), Epoch::default())
}
}

Expand Down Expand Up @@ -998,7 +996,8 @@ mod tests {
std::sync::OnceLock::<ProgramRuntimeEnvironment>::new();

fn new_mock_cache<FG: ForkGraph>() -> LoadedPrograms<FG> {
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();
Expand Down
10 changes: 8 additions & 2 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<RwLock<LoadedPrograms<BankForks>>>::default(),
loaded_programs_cache: Arc::new(RwLock::new(LoadedPrograms::new(
Slot::default(),
Epoch::default(),
))),
check_program_modification_slot: false,
epoch_reward_status: EpochRewardStatus::default(),
};
Expand Down Expand Up @@ -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::<RwLock<LoadedPrograms<BankForks>>>::default(),
loaded_programs_cache: Arc::new(RwLock::new(LoadedPrograms::new(
fields.slot,
fields.epoch,
))),
check_program_modification_slot: false,
epoch_reward_status: EpochRewardStatus::default(),
};
Expand Down

0 comments on commit 47dab26

Please sign in to comment.