Skip to content

Commit

Permalink
Extract loader-v2-interface crate (#4487)
Browse files Browse the repository at this point in the history
* extract loader-instruction crate

* use loader-instruction crate in transaction-status

* rename to solana-loader-v2-interface

* remove unused feature
  • Loading branch information
kevinheavey authored Jan 22, 2025
1 parent 00d71f9 commit 30735d7
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 22 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ members = [
"sdk/instructions-sysvar",
"sdk/keccak-hasher",
"sdk/keypair",
"sdk/loader-v2-interface",
"sdk/loader-v3-interface",
"sdk/logger",
"sdk/macro",
Expand Down Expand Up @@ -527,6 +528,7 @@ solana-keypair = { path = "sdk/keypair", version = "=2.2.0" }
solana-last-restart-slot = { path = "sdk/last-restart-slot", version = "=2.2.0" }
solana-lattice-hash = { path = "lattice-hash", version = "=2.2.0" }
solana-ledger = { path = "ledger", version = "=2.2.0" }
solana-loader-v2-interface = { path = "sdk/loader-v2-interface", version = "=2.2.0" }
solana-loader-v3-interface = { path = "sdk/loader-v3-interface", version = "=2.2.0" }
solana-loader-v4-program = { path = "programs/loader-v4", version = "=2.2.0" }
solana-local-cluster = { path = "local-cluster", version = "=2.2.0" }
Expand Down
14 changes: 14 additions & 0 deletions programs/sbf/Cargo.lock

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

30 changes: 30 additions & 0 deletions sdk/loader-v2-interface/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "solana-loader-v2-interface"
description = "Solana non-upgradable BPF loader v2 instructions."
documentation = "https://docs.rs/solana-loader-v2-interface"
version = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
edition = { workspace = true }

[dependencies]
serde = { workspace = true, optional = true }
serde_bytes = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }
solana-instruction = { workspace = true, features = ["bincode", "std"], optional = true }
solana-pubkey = { workspace = true }
solana-sdk-ids = { workspace = true }

[features]
bincode = ["dep:solana-instruction", "serde"]
serde = ["dep:serde", "dep:serde_bytes", "dep:serde_derive"]

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
all-features = true
rustdoc-args = ["--cfg=docsrs"]

[lints]
workspace = true
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
//! Instructions for the [non-upgradable BPF loader][nubpfl].
//!
//! [nubpfl]: crate::bpf_loader
//! Instructions for the non-upgradable BPF loader.
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

use crate::{
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
sysvar::rent,
#[cfg(feature = "bincode")]
use {
solana_instruction::{AccountMeta, Instruction},
solana_pubkey::Pubkey,
solana_sdk_ids::sysvar::rent,
};

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Deserialize, serde_derive::Serialize)
)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum LoaderInstruction {
/// Write program data into an account
///
Expand All @@ -19,7 +23,7 @@ pub enum LoaderInstruction {
offset: u32,

/// Serialized program data
#[serde(with = "serde_bytes")]
#[cfg_attr(feature = "serde", serde(with = "serde_bytes"))]
bytes: Vec<u8>,
},

Expand All @@ -34,6 +38,7 @@ pub enum LoaderInstruction {
Finalize,
}

#[cfg(feature = "bincode")]
pub fn write(
account_pubkey: &Pubkey,
program_id: &Pubkey,
Expand All @@ -48,6 +53,7 @@ pub fn write(
)
}

#[cfg(feature = "bincode")]
pub fn finalize(account_pubkey: &Pubkey, program_id: &Pubkey) -> Instruction {
let account_metas = vec![
AccountMeta::new(*account_pubkey, true),
Expand Down
1 change: 1 addition & 0 deletions sdk/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ solana-instruction = { workspace = true, default-features = false, features = [
solana-instructions-sysvar = { workspace = true }
solana-keccak-hasher = { workspace = true, features = ["sha3"] }
solana-last-restart-slot = { workspace = true, features = ["serde", "sysvar"] }
solana-loader-v2-interface = { workspace = true, features = ["bincode"] }
solana-loader-v3-interface = { workspace = true, features = ["bincode"] }
solana-message = { workspace = true, features = ["bincode", "blake3"] }
solana-msg = { workspace = true }
Expand Down
6 changes: 5 additions & 1 deletion sdk/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ pub mod hash;
pub mod incinerator;
pub mod instruction;
pub mod lamports;
pub mod loader_instruction;
pub mod loader_upgradeable_instruction {
#[deprecated(
since = "2.2.0",
Expand Down Expand Up @@ -534,6 +533,11 @@ pub use solana_fee_calculator as fee_calculator;
pub use solana_keccak_hasher as keccak;
#[deprecated(since = "2.1.0", note = "Use `solana-last-restart-slot` crate instead")]
pub use solana_last_restart_slot as last_restart_slot;
#[deprecated(
since = "2.2.0",
note = "Use `solana-loader-v2-interface` crate instead"
)]
pub use solana_loader_v2_interface as loader_instruction;
#[deprecated(since = "2.2.0", note = "Use `solana-message` crate instead")]
pub use solana_message as message;
#[deprecated(since = "2.1.0", note = "Use `solana-program-memory` crate instead")]
Expand Down
14 changes: 14 additions & 0 deletions svm/examples/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 transaction-status/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ solana-account-decoder = { workspace = true }
solana-clock = { workspace = true }
solana-hash = { workspace = true }
solana-instruction = { workspace = true }
solana-loader-v2-interface = { workspace = true, features = ["bincode"] }
solana-message = { workspace = true }
solana-program = { workspace = true }
solana-pubkey = { workspace = true }
Expand Down
17 changes: 5 additions & 12 deletions transaction-status/src/parse_bpf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ use {
base64::{prelude::BASE64_STANDARD, Engine},
bincode::deserialize,
serde_json::json,
solana_loader_v2_interface::LoaderInstruction,
solana_message::{compiled_instruction::CompiledInstruction, AccountKeys},
solana_program::{
loader_instruction::LoaderInstruction,
loader_upgradeable_instruction::UpgradeableLoaderInstruction,
},
solana_program::loader_upgradeable_instruction::UpgradeableLoaderInstruction,
};

pub fn parse_bpf_loader(
Expand Down Expand Up @@ -224,12 +222,8 @@ mod test {
let account_keys = vec![fee_payer, account_pubkey];
let missing_account_keys = vec![account_pubkey];

let instruction = solana_program::loader_instruction::write(
&account_pubkey,
&program_id,
offset,
bytes.clone(),
);
let instruction =
solana_loader_v2_interface::write(&account_pubkey, &program_id, offset, bytes.clone());
let mut message = Message::new(&[instruction], Some(&fee_payer));
assert_eq!(
parse_bpf_loader(
Expand Down Expand Up @@ -258,8 +252,7 @@ mod test {
)
.is_err());

let instruction =
solana_program::loader_instruction::finalize(&account_pubkey, &program_id);
let instruction = solana_loader_v2_interface::finalize(&account_pubkey, &program_id);
let mut message = Message::new(&[instruction], Some(&fee_payer));
assert_eq!(
parse_bpf_loader(
Expand Down

0 comments on commit 30735d7

Please sign in to comment.