Skip to content

Commit

Permalink
Runtime: Core BPF Migration: Path to migrate a builtin to Core BPF (s…
Browse files Browse the repository at this point in the history
…olana-labs#408)

* runtime: core_bpf_migration: add migration path

* runtime: core_bpf_migration: add tests for migration path

* comments

* function name

* rent lamports

* bank operations ordering

* make migration method a bank method

* update deployment slot to current slot

* invoke loader deploy directly
  • Loading branch information
buffalojoec authored Apr 1, 2024
1 parent b47a4ec commit 3f17532
Show file tree
Hide file tree
Showing 3 changed files with 577 additions and 1 deletion.
23 changes: 23 additions & 0 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,29 @@ macro_rules! deploy_program {
}};
}

/// 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.
pub fn direct_deploy_program(
invoke_context: &mut InvokeContext,
program_id: &Pubkey,
loader_key: &Pubkey,
account_size: usize,
elf: &[u8],
slot: Slot,
) -> Result<(), InstructionError> {
deploy_program!(
invoke_context,
*program_id,
loader_key,
account_size,
slot,
{},
elf,
);
Ok(())
}

fn write_program_data(
program_data_offset: usize,
bytes: &[u8],
Expand Down
8 changes: 7 additions & 1 deletion runtime/src/bank/builtins/core_bpf_migration/error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
use {solana_sdk::pubkey::Pubkey, thiserror::Error};
use {
solana_sdk::{instruction::InstructionError, pubkey::Pubkey},
thiserror::Error,
};

/// Errors returned by a Core BPF migration.
#[derive(Debug, Error)]
pub enum CoreBpfMigrationError {
/// Solana instruction error
#[error("Solana instruction error: {0:?}")]
InstructionError(#[from] InstructionError),
/// Bincode serialization error
#[error("Bincode serialization error: {0:?}")]
BincodeError(#[from] bincode::Error),
Expand Down
Loading

0 comments on commit 3f17532

Please sign in to comment.