Skip to content

Commit

Permalink
remove solana-program (except for dev deps)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinheavey committed Dec 3, 2024
1 parent e22445e commit 8b0db58
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 60 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion programs/sbf/Cargo.lock

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

2 changes: 1 addition & 1 deletion sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 13 additions & 4 deletions sdk/transaction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ 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 }
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]
Expand All @@ -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",
Expand All @@ -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"]
Expand Down
38 changes: 25 additions & 13 deletions sdk/transaction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -381,6 +383,7 @@ impl Transaction {
/// #
/// # Ok::<(), anyhow::Error>(())
/// ```
#[cfg(feature = "bincode")]
pub fn new<T: Signers + ?Sized>(
from_keypairs: &T,
message: Message,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -534,6 +537,7 @@ impl Transaction {
/// #
/// # Ok::<(), anyhow::Error>(())
/// ```
#[cfg(feature = "bincode")]
pub fn new_signed_with_payer<T: Signers + ?Sized>(
instructions: &[Instruction],
payer: Option<&Pubkey>,
Expand All @@ -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<T: Signers + ?Sized>(
from_keypairs: &T,
keys: &[Pubkey],
Expand Down Expand Up @@ -656,6 +661,7 @@ impl Transaction {
&self.message
}

#[cfg(feature = "bincode")]
/// Return the serialized message data to sign.
pub fn message_data(&self) -> Vec<u8> {
self.message().serialize()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -737,6 +743,7 @@ impl Transaction {
/// #
/// # Ok::<(), anyhow::Error>(())
/// ```
#[cfg(feature = "bincode")]
pub fn sign<T: Signers + ?Sized>(&mut self, keypairs: &T, recent_blockhash: Hash) {
if let Err(e) = self.try_sign(keypairs, recent_blockhash) {
panic!("Transaction::sign failed with error {e:?}");
Expand All @@ -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<T: Signers + ?Sized>(&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:?}");
Expand All @@ -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<T: Signers + ?Sized>(
&mut self,
keypairs: &T,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -874,6 +883,7 @@ impl Transaction {
/// #
/// # Ok::<(), anyhow::Error>(())
/// ```
#[cfg(feature = "bincode")]
pub fn try_sign<T: Signers + ?Sized>(
&mut self,
keypairs: &T,
Expand Down Expand Up @@ -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<T: Signers + ?Sized>(
&mut self,
keypairs: &T,
Expand All @@ -963,6 +974,7 @@ impl Transaction {
/// # Errors
///
/// Returns an error if signing fails.
#[cfg(feature = "bincode")]
pub fn try_partial_sign_unchecked<T: Signers + ?Sized>(
&mut self,
keypairs: &T,
Expand Down Expand Up @@ -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,
};

Expand Down
32 changes: 18 additions & 14 deletions sdk/transaction/src/sanitized.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -102,8 +102,11 @@ impl SanitizedTransaction {
reserved_account_keys: &HashSet<Pubkey>,
) -> Result<Self> {
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,
Expand All @@ -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<Pubkey>,
Expand All @@ -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()
}
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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,
};
Expand Down
4 changes: 2 additions & 2 deletions sdk/transaction/src/simple_vote_transaction_checker.rs
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Loading

0 comments on commit 8b0db58

Please sign in to comment.