Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.17: Set root slot/epoch in cache constructor (backport of #34447) #34460

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,21 +475,6 @@ pub struct LoadedPrograms<FG: ForkGraph> {
pub fork_graph: Option<Arc<RwLock<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 @@ -565,6 +550,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 @@ -983,7 +981,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 @@ -1015,7 +1013,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 @@ -1069,7 +1069,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 @@ -1918,7 +1921,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