From 8b0db58e45153435fd0b8e16ac9e2c82a429fec5 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Tue, 3 Dec 2024 18:07:57 +0400 Subject: [PATCH] remove solana-program (except for dev deps) --- Cargo.lock | 2 + programs/sbf/Cargo.lock | 3 +- sdk/Cargo.toml | 2 +- sdk/transaction/Cargo.toml | 17 +++++++-- sdk/transaction/src/lib.rs | 38 ++++++++++++------- sdk/transaction/src/sanitized.rs | 32 +++++++++------- .../src/simple_vote_transaction_checker.rs | 4 +- sdk/transaction/src/versioned/mod.rs | 23 +++++------ sdk/transaction/src/versioned/sanitized.rs | 10 ++--- sdk/transaction/src/wasm.rs | 7 +--- svm/examples/Cargo.lock | 3 +- 11 files changed, 81 insertions(+), 60 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a44d4f4c645df7..8427b071807e22 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9276,6 +9276,7 @@ dependencies = [ "solana-instruction", "solana-keypair", "solana-logger", + "solana-message", "solana-nonce", "solana-packet", "solana-precompiles", @@ -9290,6 +9291,7 @@ dependencies = [ "solana-short-vec", "solana-signature", "solana-signer", + "solana-system-interface", "solana-transaction", "solana-transaction-error", "static_assertions", diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 99c02b7926d71a..e87db20ac825fb 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -7782,8 +7782,8 @@ dependencies = [ "solana-hash", "solana-instruction", "solana-keypair", + "solana-message", "solana-precompiles", - "solana-program", "solana-pubkey", "solana-reserved-account-keys", "solana-sanitize", @@ -7791,6 +7791,7 @@ dependencies = [ "solana-short-vec", "solana-signature", "solana-signer", + "solana-system-interface", "solana-transaction-error", "wasm-bindgen", ] diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index a7f2a3da3c8ef6..d645e470a37825 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -177,7 +177,7 @@ solana-signature = { workspace = true, features = [ solana-signer = { workspace = true, optional = true } solana-time-utils = { workspace = true } solana-transaction = { workspace = true, features = [ - "bincode", + "blake3", "precompiles", "serde", "verify" diff --git a/sdk/transaction/Cargo.toml b/sdk/transaction/Cargo.toml index 1a013ad1ede569..bfa31b15454f80 100644 --- a/sdk/transaction/Cargo.toml +++ b/sdk/transaction/Cargo.toml @@ -20,8 +20,8 @@ solana-frozen-abi-macro = { workspace = true, optional = true } solana-hash = { workspace = true } solana-instruction = { workspace = true } solana-logger = { workspace = true, optional = true } +solana-message = { workspace = true } solana-precompiles = { workspace = true, optional = true } -solana-program = { workspace = true } solana-pubkey = { workspace = true } solana-reserved-account-keys = { workspace = true } solana-sanitize = { workspace = true } @@ -29,6 +29,7 @@ solana-sdk-ids = { workspace = true } solana-short-vec = { workspace = true, optional = true } solana-signature = { workspace = true } solana-signer = { workspace = true } +solana-system-interface = { workspace = true, optional = true, features = ["bincode"] } solana-transaction-error = { workspace = true } [target.'cfg(target_arch = "wasm32")'.dependencies] @@ -53,8 +54,15 @@ solana-transaction = { path = ".", features = ["dev-context-only-utils"] } static_assertions = { workspace = true } [features] -bincode = ["dep:bincode", "dep:solana-bincode", "serde"] -dev-context-only-utils = ["bincode", "precompiles", "serde", "verify"] +bincode = [ + "dep:bincode", + "dep:solana-bincode", + "dep:solana-system-interface", + "serde", + "solana-message/bincode", +] +blake3 = ["bincode", "solana-message/blake3"] +dev-context-only-utils = ["blake3", "precompiles", "serde", "verify"] frozen-abi = [ "dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", @@ -65,9 +73,10 @@ serde = [ "dep:serde", "dep:serde_derive", "dep:solana-short-vec", + "solana-message/serde", "solana-signature/serde", ] -verify = ["solana-signature/verify"] +verify = ["blake3", "solana-signature/verify"] [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/sdk/transaction/src/lib.rs b/sdk/transaction/src/lib.rs index ad9812330fd1c3..de4b9be21904b3 100644 --- a/sdk/transaction/src/lib.rs +++ b/sdk/transaction/src/lib.rs @@ -60,7 +60,7 @@ //! use borsh::{BorshSerialize, BorshDeserialize}; //! use solana_instruction::Instruction; //! use solana_keypair::Keypair; -//! use solana_program::message::Message; +//! use solana_message::Message; //! use solana_pubkey::Pubkey; //! use solana_rpc_client::rpc_client::RpcClient; //! use solana_signer::Signer; @@ -120,16 +120,18 @@ use { #[cfg(feature = "bincode")] use { solana_bincode::limited_deserialize, - solana_program::{system_instruction::SystemInstruction, system_program}, + solana_hash::Hash, + solana_message::compiled_instruction::CompiledInstruction, + solana_sdk_ids::system_program, + solana_signer::{signers::Signers, SignerError}, + solana_system_interface::instruction::SystemInstruction, }; use { - solana_hash::Hash, solana_instruction::Instruction, - solana_program::{instruction::CompiledInstruction, message::Message}, + solana_message::Message, solana_pubkey::Pubkey, solana_sanitize::{Sanitize, SanitizeError}, solana_signature::Signature, - solana_signer::{signers::Signers, SignerError}, solana_transaction_error::{TransactionError, TransactionResult as Result}, std::result, }; @@ -227,7 +229,7 @@ pub struct Transaction { } impl Sanitize for Transaction { - fn sanitize(&self) -> std::result::Result<(), SanitizeError> { + fn sanitize(&self) -> result::Result<(), SanitizeError> { if self.message.header.num_required_signatures as usize > self.signatures.len() { return Err(SanitizeError::IndexOutOfBounds); } @@ -254,7 +256,7 @@ impl Transaction { /// use borsh::{BorshSerialize, BorshDeserialize}; /// use solana_instruction::Instruction; /// use solana_keypair::Keypair; - /// use solana_program::message::Message; + /// use solana_message::Message; /// use solana_pubkey::Pubkey; /// use solana_rpc_client::rpc_client::RpcClient; /// use solana_signer::Signer; @@ -332,7 +334,7 @@ impl Transaction { /// use borsh::{BorshSerialize, BorshDeserialize}; /// use solana_instruction::Instruction; /// use solana_keypair::Keypair; - /// use solana_program::message::Message; + /// use solana_message::Message; /// use solana_pubkey::Pubkey; /// use solana_rpc_client::rpc_client::RpcClient; /// use solana_signer::Signer; @@ -381,6 +383,7 @@ impl Transaction { /// # /// # Ok::<(), anyhow::Error>(()) /// ``` + #[cfg(feature = "bincode")] pub fn new( from_keypairs: &T, message: Message, @@ -410,7 +413,7 @@ impl Transaction { /// use borsh::{BorshSerialize, BorshDeserialize}; /// use solana_instruction::Instruction; /// use solana_keypair::Keypair; - /// use solana_program::message::Message; + /// use solana_message::Message; /// use solana_pubkey::Pubkey; /// use solana_rpc_client::rpc_client::RpcClient; /// use solana_signer::Signer; @@ -485,7 +488,7 @@ impl Transaction { /// use borsh::{BorshSerialize, BorshDeserialize}; /// use solana_instruction::Instruction; /// use solana_keypair::Keypair; - /// use solana_program::message::Message; + /// use solana_message::Message; /// use solana_pubkey::Pubkey; /// use solana_rpc_client::rpc_client::RpcClient; /// use solana_signer::Signer; @@ -534,6 +537,7 @@ impl Transaction { /// # /// # Ok::<(), anyhow::Error>(()) /// ``` + #[cfg(feature = "bincode")] pub fn new_signed_with_payer( instructions: &[Instruction], payer: Option<&Pubkey>, @@ -559,6 +563,7 @@ impl Transaction { /// /// Panics when signing fails. See [`Transaction::try_sign`] and for a full /// description of failure conditions. + #[cfg(feature = "bincode")] pub fn new_with_compiled_instructions( from_keypairs: &T, keys: &[Pubkey], @@ -656,6 +661,7 @@ impl Transaction { &self.message } + #[cfg(feature = "bincode")] /// Return the serialized message data to sign. pub fn message_data(&self) -> Vec { self.message().serialize() @@ -692,7 +698,7 @@ impl Transaction { /// use borsh::{BorshSerialize, BorshDeserialize}; /// use solana_instruction::Instruction; /// use solana_keypair::Keypair; - /// use solana_program::message::Message; + /// use solana_message::Message; /// use solana_pubkey::Pubkey; /// use solana_rpc_client::rpc_client::RpcClient; /// use solana_signer::Signer; @@ -737,6 +743,7 @@ impl Transaction { /// # /// # Ok::<(), anyhow::Error>(()) /// ``` + #[cfg(feature = "bincode")] pub fn sign(&mut self, keypairs: &T, recent_blockhash: Hash) { if let Err(e) = self.try_sign(keypairs, recent_blockhash) { panic!("Transaction::sign failed with error {e:?}"); @@ -763,6 +770,7 @@ impl Transaction { /// handle the error. See the documentation for /// [`Transaction::try_partial_sign`] for a full description of failure /// conditions. + #[cfg(feature = "bincode")] pub fn partial_sign(&mut self, keypairs: &T, recent_blockhash: Hash) { if let Err(e) = self.try_partial_sign(keypairs, recent_blockhash) { panic!("Transaction::partial_sign failed with error {e:?}"); @@ -782,6 +790,7 @@ impl Transaction { /// /// Panics if signing fails. Use [`Transaction::try_partial_sign_unchecked`] /// to handle the error. + #[cfg(feature = "bincode")] pub fn partial_sign_unchecked( &mut self, keypairs: &T, @@ -829,7 +838,7 @@ impl Transaction { /// use borsh::{BorshSerialize, BorshDeserialize}; /// use solana_instruction::Instruction; /// use solana_keypair::Keypair; - /// use solana_program::message::Message; + /// use solana_message::Message; /// use solana_pubkey::Pubkey; /// use solana_rpc_client::rpc_client::RpcClient; /// use solana_signer::Signer; @@ -874,6 +883,7 @@ impl Transaction { /// # /// # Ok::<(), anyhow::Error>(()) /// ``` + #[cfg(feature = "bincode")] pub fn try_sign( &mut self, keypairs: &T, @@ -937,6 +947,7 @@ impl Transaction { /// [`PresignerError::VerificationFailure`]: https://docs.rs/solana-signer/latest/solana_signer/enum.PresignerError.html#variant.WrongSize /// [`solana-remote-wallet`]: https://docs.rs/solana-remote-wallet/latest/ /// [`RemoteKeypair`]: https://docs.rs/solana-remote-wallet/latest/solana_remote_wallet/remote_keypair/struct.RemoteKeypair.html + #[cfg(feature = "bincode")] pub fn try_partial_sign( &mut self, keypairs: &T, @@ -963,6 +974,7 @@ impl Transaction { /// # Errors /// /// Returns an error if signing fails. + #[cfg(feature = "bincode")] pub fn try_partial_sign_unchecked( &mut self, keypairs: &T, @@ -1150,9 +1162,9 @@ mod tests { solana_instruction::AccountMeta, solana_keypair::Keypair, solana_presigner::Presigner, - solana_program::system_instruction, solana_sha256_hasher::hash, solana_signer::Signer, + solana_system_interface::instruction as system_instruction, std::mem::size_of, }; diff --git a/sdk/transaction/src/sanitized.rs b/sdk/transaction/src/sanitized.rs index d60c3e4659524c..2d0f3639c2c222 100644 --- a/sdk/transaction/src/sanitized.rs +++ b/sdk/transaction/src/sanitized.rs @@ -1,23 +1,22 @@ use { - crate::{ - simple_vote_transaction_checker::is_simple_vote_transaction, - versioned::{sanitized::SanitizedVersionedTransaction, VersionedTransaction}, - Transaction, - }, + crate::versioned::{sanitized::SanitizedVersionedTransaction, VersionedTransaction}, solana_hash::Hash, - solana_program::message::{ + solana_message::{ legacy, v0::{self, LoadedAddresses}, AddressLoader, LegacyMessage, SanitizedMessage, SanitizedVersionedMessage, VersionedMessage, }, solana_pubkey::Pubkey, - solana_reserved_account_keys::ReservedAccountKeys, - solana_sanitize::Sanitize, solana_signature::Signature, solana_transaction_error::{TransactionError, TransactionResult as Result}, std::collections::HashSet, }; +#[cfg(feature = "blake3")] +use { + crate::Transaction, solana_reserved_account_keys::ReservedAccountKeys, + solana_sanitize::Sanitize, +}; /// Maximum number of accounts that a transaction may lock. /// 128 was chosen because it is the minimum number of accounts @@ -91,6 +90,7 @@ impl SanitizedTransaction { }) } + #[cfg(feature = "blake3")] /// Create a sanitized transaction from an un-sanitized versioned /// transaction. If the input transaction uses address tables, attempt to /// lookup the address for each table index. @@ -102,8 +102,11 @@ impl SanitizedTransaction { reserved_account_keys: &HashSet, ) -> Result { let sanitized_versioned_tx = SanitizedVersionedTransaction::try_from(tx)?; - let is_simple_vote_tx = is_simple_vote_tx - .unwrap_or_else(|| is_simple_vote_transaction(&sanitized_versioned_tx)); + let is_simple_vote_tx = is_simple_vote_tx.unwrap_or_else(|| { + crate::simple_vote_transaction_checker::is_simple_vote_transaction( + &sanitized_versioned_tx, + ) + }); let message_hash = match message_hash.into() { MessageHash::Compute => sanitized_versioned_tx.message.message.hash(), MessageHash::Precomputed(hash) => hash, @@ -118,6 +121,7 @@ impl SanitizedTransaction { } /// Create a sanitized transaction from a legacy transaction + #[cfg(feature = "blake3")] pub fn try_from_legacy_transaction( tx: Transaction, reserved_account_keys: &HashSet, @@ -136,6 +140,7 @@ impl SanitizedTransaction { } /// Create a sanitized transaction from a legacy transaction. Used for tests only. + #[cfg(feature = "blake3")] pub fn from_transaction_for_tests(tx: Transaction) -> Self { Self::try_from_legacy_transaction(tx, &ReservedAccountKeys::empty_key_set()).unwrap() } @@ -250,6 +255,7 @@ impl SanitizedTransaction { } /// If the transaction uses a durable nonce, return the pubkey of the nonce account + #[cfg(feature = "bincode")] pub fn get_durable_nonce(&self) -> Option<&Pubkey> { self.message.get_durable_nonce() } @@ -337,10 +343,8 @@ mod tests { use { super::*, solana_keypair::Keypair, - solana_program::{ - message::{MessageHeader, SimpleAddressLoader}, - vote::{self, state::Vote}, - }, + solana_message::{MessageHeader, SimpleAddressLoader}, + solana_program::vote::{self, state::Vote}, solana_reserved_account_keys::ReservedAccountKeys, solana_signer::Signer, }; diff --git a/sdk/transaction/src/simple_vote_transaction_checker.rs b/sdk/transaction/src/simple_vote_transaction_checker.rs index 7029911552f9ce..bece183670d274 100644 --- a/sdk/transaction/src/simple_vote_transaction_checker.rs +++ b/sdk/transaction/src/simple_vote_transaction_checker.rs @@ -1,6 +1,6 @@ use { - crate::versioned::sanitized::SanitizedVersionedTransaction, - solana_program::message::VersionedMessage, solana_pubkey::Pubkey, solana_signature::Signature, + crate::versioned::sanitized::SanitizedVersionedTransaction, solana_message::VersionedMessage, + solana_pubkey::Pubkey, solana_signature::Signature, }; /// Simple vote transaction meets these conditions: diff --git a/sdk/transaction/src/versioned/mod.rs b/sdk/transaction/src/versioned/mod.rs index ce19d45ec36ce1..21f8be087b3608 100644 --- a/sdk/transaction/src/versioned/mod.rs +++ b/sdk/transaction/src/versioned/mod.rs @@ -1,12 +1,8 @@ //! Defines a transaction which supports multiple versions of messages. use { - crate::Transaction, - solana_program::message::VersionedMessage, - solana_sanitize::SanitizeError, - solana_signature::Signature, - solana_signer::{signers::Signers, SignerError}, - std::cmp::Ordering, + crate::Transaction, solana_message::VersionedMessage, solana_sanitize::SanitizeError, + solana_signature::Signature, std::cmp::Ordering, }; #[cfg(feature = "serde")] use { @@ -16,7 +12,9 @@ use { #[cfg(feature = "bincode")] use { solana_bincode::limited_deserialize, - solana_program::{system_instruction::SystemInstruction, system_program}, + solana_sdk_ids::system_program, + solana_signer::{signers::Signers, SignerError}, + solana_system_interface::instruction::SystemInstruction, }; pub mod sanitized; @@ -72,6 +70,7 @@ impl From for VersionedTransaction { impl VersionedTransaction { /// Signs a versioned message and if successful, returns a signed /// transaction. + #[cfg(feature = "bincode")] pub fn try_new( message: VersionedMessage, keypairs: &T, @@ -233,14 +232,12 @@ mod tests { use { super::*, solana_hash::Hash, + solana_instruction::{AccountMeta, Instruction}, solana_keypair::Keypair, - solana_program::{ - instruction::{AccountMeta, Instruction}, - message::Message as LegacyMessage, - pubkey::Pubkey, - system_instruction, - }, + solana_message::Message as LegacyMessage, + solana_pubkey::Pubkey, solana_signer::Signer, + solana_system_interface::instruction as system_instruction, }; #[test] diff --git a/sdk/transaction/src/versioned/sanitized.rs b/sdk/transaction/src/versioned/sanitized.rs index 880f93bdca7cb5..aec6033c377ffa 100644 --- a/sdk/transaction/src/versioned/sanitized.rs +++ b/sdk/transaction/src/versioned/sanitized.rs @@ -1,5 +1,5 @@ use { - crate::versioned::VersionedTransaction, solana_program::message::SanitizedVersionedMessage, + crate::versioned::VersionedTransaction, solana_message::SanitizedVersionedMessage, solana_sanitize::SanitizeError, solana_signature::Signature, }; @@ -42,11 +42,9 @@ impl SanitizedVersionedTransaction { mod tests { use { super::*, - solana_program::{ - hash::Hash, - message::{v0, VersionedMessage}, - pubkey::Pubkey, - }, + solana_hash::Hash, + solana_message::{v0, VersionedMessage}, + solana_pubkey::Pubkey, }; #[test] diff --git a/sdk/transaction/src/wasm.rs b/sdk/transaction/src/wasm.rs index c48723b1c7ded1..cdfc5792b3e569 100644 --- a/sdk/transaction/src/wasm.rs +++ b/sdk/transaction/src/wasm.rs @@ -2,11 +2,8 @@ #![cfg(target_arch = "wasm32")] #![allow(non_snake_case)] use { - crate::Transaction, - solana_hash::Hash, - solana_keypair::Keypair, - solana_program::{message::Message, wasm::instructions::Instructions}, - solana_pubkey::Pubkey, + crate::Transaction, solana_hash::Hash, solana_instruction::wasm::Instructions, + solana_keypair::Keypair, solana_message::Message, solana_pubkey::Pubkey, wasm_bindgen::prelude::*, }; diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index b1b426c735b1c0..b74749f96a7ea9 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -7127,8 +7127,8 @@ dependencies = [ "solana-hash", "solana-instruction", "solana-keypair", + "solana-message", "solana-precompiles", - "solana-program", "solana-pubkey", "solana-reserved-account-keys", "solana-sanitize", @@ -7136,6 +7136,7 @@ dependencies = [ "solana-short-vec", "solana-signature", "solana-signer", + "solana-system-interface", "solana-transaction-error", "wasm-bindgen", ]