From adaae455e73fbdbb4f0e66cb0a04c8e92b1ef5b1 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Thu, 16 Jan 2025 03:18:49 +0400 Subject: [PATCH 1/2] extract loader-instruction crate --- Cargo.lock | 13 ++++++++ Cargo.toml | 2 ++ programs/sbf/Cargo.lock | 15 ++++++++- sdk/loader-instruction/Cargo.toml | 31 +++++++++++++++++++ .../src/lib.rs} | 24 ++++++++------ sdk/program/Cargo.toml | 1 + sdk/program/src/lib.rs | 6 +++- svm/examples/Cargo.lock | 15 ++++++++- 8 files changed, 95 insertions(+), 12 deletions(-) create mode 100644 sdk/loader-instruction/Cargo.toml rename sdk/{program/src/loader_instruction.rs => loader-instruction/src/lib.rs} (72%) diff --git a/Cargo.lock b/Cargo.lock index 76a375728a5342..a623b042c1ea52 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7733,6 +7733,18 @@ dependencies = [ "trees", ] +[[package]] +name = "solana-loader-instruction" +version = "2.2.0" +dependencies = [ + "serde", + "serde_bytes", + "serde_derive", + "solana-instruction", + "solana-pubkey", + "solana-sdk-ids", +] + [[package]] name = "solana-loader-v4-program" version = "2.2.0" @@ -8243,6 +8255,7 @@ dependencies = [ "solana-instructions-sysvar", "solana-keccak-hasher", "solana-last-restart-slot", + "solana-loader-instruction", "solana-logger", "solana-message", "solana-msg", diff --git a/Cargo.toml b/Cargo.toml index 7e1fa38779f382..4732674dad6d8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -143,6 +143,7 @@ members = [ "sdk/instructions-sysvar", "sdk/keccak-hasher", "sdk/keypair", + "sdk/loader-instruction", "sdk/logger", "sdk/macro", "sdk/message", @@ -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" } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 316adbe52bce1c..9183b2a0e7c6ae 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "Inflector" @@ -6188,6 +6188,18 @@ dependencies = [ "trees", ] +[[package]] +name = "solana-loader-instruction" +version = "2.2.0" +dependencies = [ + "serde", + "serde_bytes", + "serde_derive", + "solana-instruction", + "solana-pubkey", + "solana-sdk-ids", +] + [[package]] name = "solana-loader-v4-program" version = "2.2.0" @@ -6498,6 +6510,7 @@ dependencies = [ "solana-instructions-sysvar", "solana-keccak-hasher", "solana-last-restart-slot", + "solana-loader-instruction", "solana-message", "solana-msg", "solana-native-token", diff --git a/sdk/loader-instruction/Cargo.toml b/sdk/loader-instruction/Cargo.toml new file mode 100644 index 00000000000000..42bf204bf64333 --- /dev/null +++ b/sdk/loader-instruction/Cargo.toml @@ -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 diff --git a/sdk/program/src/loader_instruction.rs b/sdk/loader-instruction/src/lib.rs similarity index 72% rename from sdk/program/src/loader_instruction.rs rename to sdk/loader-instruction/src/lib.rs index a4c1360f94981a..b435792bdc3db8 100644 --- a/sdk/program/src/loader_instruction.rs +++ b/sdk/loader-instruction/src/lib.rs @@ -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 /// @@ -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, }, @@ -34,6 +38,7 @@ pub enum LoaderInstruction { Finalize, } +#[cfg(feature = "bincode")] pub fn write( account_pubkey: &Pubkey, program_id: &Pubkey, @@ -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), diff --git a/sdk/program/Cargo.toml b/sdk/program/Cargo.toml index 7ac275aa4a70b9..8b34e041961d41 100644 --- a/sdk/program/Cargo.toml +++ b/sdk/program/Cargo.toml @@ -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 } diff --git a/sdk/program/src/lib.rs b/sdk/program/src/lib.rs index 6ba5230302fd7b..c8b2da108e20e5 100644 --- a/sdk/program/src/lib.rs +++ b/sdk/program/src/lib.rs @@ -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; @@ -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")] diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index ec51f4a2312caa..ab6897635b1a57 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "Inflector" @@ -6018,6 +6018,18 @@ dependencies = [ "trees", ] +[[package]] +name = "solana-loader-instruction" +version = "2.2.0" +dependencies = [ + "serde", + "serde_bytes", + "serde_derive", + "solana-instruction", + "solana-pubkey", + "solana-sdk-ids", +] + [[package]] name = "solana-loader-v4-program" version = "2.2.0" @@ -6328,6 +6340,7 @@ dependencies = [ "solana-instructions-sysvar", "solana-keccak-hasher", "solana-last-restart-slot", + "solana-loader-instruction", "solana-message", "solana-msg", "solana-native-token", From f35686a4141d2a15c228a110fbd655d8e0c51d32 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Thu, 16 Jan 2025 03:35:34 +0400 Subject: [PATCH 2/2] use loader-instruction crate in transaction-status --- Cargo.lock | 1 + programs/sbf/Cargo.lock | 1 + svm/examples/Cargo.lock | 1 + transaction-status/Cargo.toml | 1 + transaction-status/src/parse_bpf_loader.rs | 17 +++++------------ 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a623b042c1ea52..9200932bab2065 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10037,6 +10037,7 @@ dependencies = [ "solana-clock", "solana-hash", "solana-instruction", + "solana-loader-instruction", "solana-message", "solana-program", "solana-pubkey", diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 9183b2a0e7c6ae..65c035a1f9bb48 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -8347,6 +8347,7 @@ dependencies = [ "solana-clock", "solana-hash", "solana-instruction", + "solana-loader-instruction", "solana-message", "solana-program", "solana-pubkey", diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index ab6897635b1a57..e64aedba80d523 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -7693,6 +7693,7 @@ dependencies = [ "solana-clock", "solana-hash", "solana-instruction", + "solana-loader-instruction", "solana-message", "solana-program", "solana-pubkey", diff --git a/transaction-status/Cargo.toml b/transaction-status/Cargo.toml index aa503324e1b270..2fc6ad2959fd9e 100644 --- a/transaction-status/Cargo.toml +++ b/transaction-status/Cargo.toml @@ -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 } diff --git a/transaction-status/src/parse_bpf_loader.rs b/transaction-status/src/parse_bpf_loader.rs index 4849fd0d94fb52..9432c08eb31350 100644 --- a/transaction-status/src/parse_bpf_loader.rs +++ b/transaction-status/src/parse_bpf_loader.rs @@ -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( @@ -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( @@ -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(