Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pgarg66 committed Mar 9, 2024
1 parent c24aaa2 commit ff5995a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl<'a> InvokeContext<'a> {
.or_else(|| self.programs_loaded_for_tx_batch.find(pubkey))
}

pub fn get_runtime_environments_for_slot(
pub fn get_environments_for_slot(
&self,
slot: Slot,
) -> Result<&ProgramRuntimeEnvironments, InstructionError> {
Expand Down
4 changes: 3 additions & 1 deletion program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,13 @@ pub struct LoadedProgramsForTxBatch {
entries: HashMap<Pubkey, Arc<LoadedProgram>>,
slot: Slot,
pub environments: ProgramRuntimeEnvironments,
/// Anticipated replacement for `environments` at the next epoch
/// Anticipated replacement for `environments` at the next epoch.
///
/// This is `None` during most of an epoch, and only `Some` around the boundaries (at the end and beginning of an epoch).
/// More precisely, it starts with the recompilation phase a few hundred slots before the epoch boundary,
/// and it ends with the first rerooting after the epoch boundary.
/// Needed when a program is deployed at the last slot of an epoch, becomes effective in the next epoch.
/// So needs to be compiled with the environment for the next epoch.
pub upcoming_environments: Option<ProgramRuntimeEnvironments>,
/// The epoch of the last rerooting
pub latest_root_epoch: Epoch,
Expand Down
8 changes: 4 additions & 4 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use {
rc::Rc,
sync::{atomic::Ordering, Arc},
},
syscalls::{create_program_runtime_environment_v1, morph_program_runtime_environment_v1},
syscalls::{create_program_runtime_environment_v1, morph_into_deployment_environment_v1},
};

pub const DEFAULT_LOADER_COMPUTE_UNITS: u64 = 570;
Expand Down Expand Up @@ -108,15 +108,15 @@ macro_rules! deploy_program {
let mut load_program_metrics = LoadProgramMetrics::default();
let mut register_syscalls_time = Measure::start("register_syscalls_time");
let deployment_slot: Slot = $slot;
let environments = $invoke_context.get_runtime_environments_for_slot(
let environments = $invoke_context.get_environments_for_slot(
deployment_slot.saturating_add(DELAY_VISIBILITY_SLOT_OFFSET)
).map_err(|e| {
// This will never fail since the epoch schedule is already configured.
ic_msg!($invoke_context, "Failed to get runtime environment: {}", e);
InstructionError::ProgramEnvironmentSetupFailure
})?;
let deployment_program_runtime_environment = morph_program_runtime_environment_v1(
let deployment_program_runtime_environment = morph_into_deployment_environment_v1(
environments.program_runtime_v1.clone(),
true, /* deployment */
).map_err(|e| {
ic_msg!($invoke_context, "Failed to register syscalls: {}", e);
InstructionError::ProgramEnvironmentSetupFailure
Expand Down
5 changes: 2 additions & 3 deletions programs/bpf_loader/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,11 @@ macro_rules! register_feature_gated_function {
};
}

pub fn morph_program_runtime_environment_v1(
pub fn morph_into_deployment_environment_v1(
from: Arc<BuiltinProgram<InvokeContext>>,
reject_deployment_of_broken_elfs: bool,
) -> Result<BuiltinProgram<InvokeContext>, Error> {
let mut config = *from.get_config();
config.reject_broken_elfs = reject_deployment_of_broken_elfs;
config.reject_broken_elfs = true;

let mut result = FunctionRegistry::<BuiltinFunction<InvokeContext>>::default();

Expand Down
3 changes: 2 additions & 1 deletion programs/loader-v4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,9 @@ pub fn process_instruction_deploy(
let effective_slot = deployment_slot.saturating_add(DELAY_VISIBILITY_SLOT_OFFSET);

let environments = invoke_context
.get_runtime_environments_for_slot(effective_slot)
.get_environments_for_slot(effective_slot)
.map_err(|err| {
// This will never fail since the epoch schedule is already configured.
ic_logger_msg!(log_collector, "Failed to get runtime environment {}", err);
InstructionError::InvalidArgument
})?;
Expand Down

0 comments on commit ff5995a

Please sign in to comment.