Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract loader-instruction crate #4487

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -143,6 +143,7 @@ members = [
"sdk/instructions-sysvar",
"sdk/keccak-hasher",
"sdk/keypair",
"sdk/loader-instruction",
"sdk/logger",
"sdk/macro",
"sdk/message",
Expand Down Expand Up @@ -514,6 +515,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-instruction = { path = "sdk/loader-instruction", 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" }
solana-log-collector = { path = "log-collector", version = "=2.2.0" }
Expand Down
16 changes: 15 additions & 1 deletion programs/sbf/Cargo.lock

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

31 changes: 31 additions & 0 deletions sdk/loader-instruction/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "solana-loader-instruction"
description = "Solana non-upgradable BPF loader instructions."
documentation = "https://docs.rs/solana-loader-instruction"
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"]
dev-context-only-utils = ["bincode"]
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 @@ -52,6 +52,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-instruction = { workspace = true, features = ["bincode"] }
solana-message = { workspace = true, features = ["bincode", "blake3"] }
solana-msg = { workspace = true }
solana-native-token = { 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 @@ -485,7 +485,6 @@ pub mod hash;
pub mod incinerator;
pub mod instruction;
pub mod lamports;
pub mod loader_instruction;
pub mod loader_upgradeable_instruction;
pub mod loader_v4;
pub mod loader_v4_instruction;
Expand Down Expand Up @@ -528,6 +527,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-instruction` crate instead"
)]
pub use solana_loader_instruction 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
16 changes: 15 additions & 1 deletion 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-instruction = { 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_instruction::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_instruction::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_instruction::finalize(&account_pubkey, &program_id);
let mut message = Message::new(&[instruction], Some(&fee_payer));
assert_eq!(
parse_bpf_loader(
Expand Down
Loading