Skip to content

Commit

Permalink
Feature - Loader built-in program v3 (#30464)
Browse files Browse the repository at this point in the history
* Adds loader-v3 in SDK.

* Adds loader-v3 built-in program.

* Adds tests.
  • Loading branch information
Lichtso authored Mar 23, 2023
1 parent 0291e8c commit c10f337
Show file tree
Hide file tree
Showing 13 changed files with 1,635 additions and 9 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 @@ -578,7 +578,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
28 changes: 28 additions & 0 deletions programs/loader-v3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[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 = { workspace = true }
rand = { workspace = true }
solana-measure = { workspace = true }
solana-program-runtime = { workspace = true }
solana-sdk = { workspace = true }
solana_rbpf = { workspace = true }

[dev-dependencies]
bincode = { workspace = true }

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

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

0 comments on commit c10f337

Please sign in to comment.