Skip to content

Commit

Permalink
Adds loader-v3 built-in program.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Mar 9, 2023
1 parent f50bd3a commit fd6d018
Show file tree
Hide file tree
Showing 6 changed files with 573 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ members = [
"programs/compute-budget",
"programs/config",
"programs/ed25519-tests",
"programs/loader-v3",
"programs/stake",
"programs/vote",
"programs/zk-token-proof",
Expand Down
10 changes: 7 additions & 3 deletions program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use {
vm::{BuiltInProgram, VerifiedExecutable},
},
solana_sdk::{
bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, clock::Slot, pubkey::Pubkey,
saturating_add_assign,
bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, clock::Slot, loader_v3,
pubkey::Pubkey, saturating_add_assign,
},
std::{
collections::HashMap,
Expand Down Expand Up @@ -61,7 +61,7 @@ pub enum LoadedProgramType {
Invalid,
LegacyV0(VerifiedExecutable<RequisiteVerifier, InvokeContext<'static>>),
LegacyV1(VerifiedExecutable<RequisiteVerifier, InvokeContext<'static>>),
// Typed(TypedProgram<InvokeContext<'static>>),
Typed(VerifiedExecutable<RequisiteVerifier, InvokeContext<'static>>),
BuiltIn(BuiltInProgram<InvokeContext<'static>>),
}

Expand All @@ -71,6 +71,7 @@ impl Debug for LoadedProgramType {
LoadedProgramType::Invalid => write!(f, "LoadedProgramType::Invalid"),
LoadedProgramType::LegacyV0(_) => write!(f, "LoadedProgramType::LegacyV0"),
LoadedProgramType::LegacyV1(_) => write!(f, "LoadedProgramType::LegacyV1"),
LoadedProgramType::Typed(_) => write!(f, "LoadedProgramType::Typed"),
LoadedProgramType::BuiltIn(_) => write!(f, "LoadedProgramType::BuiltIn"),
}
}
Expand Down Expand Up @@ -143,6 +144,8 @@ impl LoadedProgram {
LoadedProgramType::LegacyV0(VerifiedExecutable::from_executable(executable)?)
} else if bpf_loader::check_id(loader_key) || bpf_loader_upgradeable::check_id(loader_key) {
LoadedProgramType::LegacyV1(VerifiedExecutable::from_executable(executable)?)
} else if loader_v3::check_id(loader_key) {
LoadedProgramType::Typed(VerifiedExecutable::from_executable(executable)?)
} else {
panic!();
};
Expand All @@ -156,6 +159,7 @@ impl LoadedProgram {
match &mut program {
LoadedProgramType::LegacyV0(executable) => executable.jit_compile(),
LoadedProgramType::LegacyV1(executable) => executable.jit_compile(),
LoadedProgramType::Typed(executable) => executable.jit_compile(),
_ => Err(EbpfError::JitNotCompiled),
}?;
jit_compile_time.stop();
Expand Down
2 changes: 1 addition & 1 deletion programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ fn process_instruction_common(
LoadedProgramType::Invalid => Err(InstructionError::InvalidAccountData),
LoadedProgramType::LegacyV0(executable) => execute(executable, invoke_context),
LoadedProgramType::LegacyV1(executable) => execute(executable, invoke_context),
LoadedProgramType::BuiltIn(_) => Err(InstructionError::IncorrectProgramId),
_ => Err(InstructionError::IncorrectProgramId),
}
}

Expand Down
25 changes: 25 additions & 0 deletions programs/loader-v3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "solana-loader-v3-program"
version = "1.16.0"
description = "Solana Loader v3"
authors = ["Solana Maintainers <[email protected]>"]
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
edition = "2021"
publish = false

[dependencies]
log = "0.4.17"
rand = "0.8.5"
solana-measure = { path = "../../measure", version = "=1.16.0" }
solana-program-runtime = { path = "../../program-runtime", version = "=1.16.0" }
solana-sdk = { path = "../../sdk", version = "=1.16.0" }
solana_rbpf = "=0.2.39"

[lib]
crate-type = ["lib"]
name = "solana_loader_v3_program"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
Loading

0 comments on commit fd6d018

Please sign in to comment.