Skip to content

Commit

Permalink
change deploy_program_internal -> deploy_program
Browse files Browse the repository at this point in the history
  • Loading branch information
pgarg66 committed Jan 14, 2025
1 parent 1a2f777 commit 8c879f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 28 deletions.
31 changes: 5 additions & 26 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ pub fn load_program_from_bytes(
/// Directly deploy a program using a provided invoke context.
/// This function should only be invoked from the runtime, since it does not
/// provide any account loads or checks.
#[cfg_attr(feature = "svm-internal", qualifiers(pub))]
fn deploy_program_internal(
pub fn deploy_program(
log_collector: Option<Rc<RefCell<LogCollector>>>,
program_cache_for_tx_batch: &mut ProgramCacheForTxBatch,
program_runtime_environment: ProgramRuntimeEnvironment,
Expand Down Expand Up @@ -185,7 +184,7 @@ macro_rules! deploy_program {
// This will never fail since the epoch schedule is already configured.
InstructionError::ProgramEnvironmentSetupFailure
})?;
let load_program_metrics = $crate::deploy_program_internal(
let load_program_metrics = $crate::deploy_program(
$invoke_context.get_log_collector(),
$invoke_context.program_cache_for_tx_batch,
environments.program_runtime_v1.clone(),
Expand All @@ -199,27 +198,6 @@ macro_rules! deploy_program {
};
}

// This function/wrapper is added specifically for non "svm-internal" users. It enables the reducing
// of public visibility of some internal APIs.
pub fn deploy_program(
invoke_context: &mut InvokeContext,
program_id: &Pubkey,
loader_key: &Pubkey,
account_size: usize,
programdata: &[u8],
deployment_slot: Slot,
) -> Result<(), InstructionError> {
deploy_program!(
invoke_context,
program_id,
loader_key,
account_size,
programdata,
deployment_slot
);
Ok(())
}

fn write_program_data(
program_data_offset: usize,
bytes: &[u8],
Expand Down Expand Up @@ -3868,14 +3846,15 @@ mod tests {
let mut file = File::open("test_elfs/out/sbpfv3_return_ok.so").expect("file open failed");
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
deploy_program(
deploy_program!(
invoke_context,
&program_id,
&bpf_loader_upgradeable::id(),
elf.len(),
&elf,
2_u64,
)
);
Ok(())
}

#[test]
Expand Down
16 changes: 14 additions & 2 deletions runtime/src/bank/builtins/core_bpf_migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,26 @@ impl Bank {
compute_budget,
);

solana_bpf_loader_program::deploy_program(
&mut dummy_invoke_context,
let environments = dummy_invoke_context
.get_environments_for_slot(self.slot.saturating_add(
solana_program_runtime::loaded_programs::DELAY_VISIBILITY_SLOT_OFFSET,
))
.map_err(|_err| {
// This will never fail since the epoch schedule is already configured.
InstructionError::ProgramEnvironmentSetupFailure
})?;

let load_program_metrics = solana_bpf_loader_program::deploy_program(
dummy_invoke_context.get_log_collector(),
dummy_invoke_context.program_cache_for_tx_batch,
environments.program_runtime_v1.clone(),
program_id,
&bpf_loader_upgradeable::id(),
data_len,
elf,
self.slot,
)?;
load_program_metrics.submit_datapoint(&mut dummy_invoke_context.timings);
}

// Update the program cache by merging with `programs_modified`, which
Expand Down

0 comments on commit 8c879f8

Please sign in to comment.