Skip to content

Commit

Permalink
extract transaction-error crate (#2295)
Browse files Browse the repository at this point in the history
* extract transaction-error crate

* update TransactionError usage in sdk

* fix frozen-abi support

* make serde optional in solana-transaction-error

* update lock file

* fmt

* add #[cfg(not(target_os = "solana"))] where applicable

* fmt

* put solana-transaction-error behind feature "full"

* use workspace lints

* update digest

* make rustc_version optional

* avoid frozen-abi build script

* add back workspace lints

* remove thiserror

* remove unused build deps

* use solana-instruction directly

* move AddressLoaderError and SanitizeMessageError to transaction-error, and fix its solana-instruction dep features

* lint

* move TransportError to transaction-error crate

* use doc_auto_cfg like in #3121

* missing comma

* add deprecations to re-exports
  • Loading branch information
kevinheavey authored Oct 22, 2024
1 parent 3cc0ebf commit 31bcb94
Show file tree
Hide file tree
Showing 16 changed files with 502 additions and 292 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 @@ -137,6 +137,7 @@ members = [
"sdk/signature",
"sdk/slot-hashes",
"sdk/stable-layout",
"sdk/transaction-error",
"send-transaction-service",
"short-vec",
"stake-accounts",
Expand Down Expand Up @@ -497,6 +498,7 @@ solana-svm-transaction = { path = "svm-transaction", version = "=2.1.0" }
solana-system-program = { path = "programs/system", version = "=2.1.0" }
solana-test-validator = { path = "test-validator", version = "=2.1.0" }
solana-thin-client = { path = "thin-client", version = "=2.1.0" }
solana-transaction-error = { path = "sdk/transaction-error", version = "=2.1.0" }
solana-tpu-client = { path = "tpu-client", version = "=2.1.0", default-features = false }
solana-transaction-status = { path = "transaction-status", version = "=2.1.0" }
solana-transaction-status-client-types = { path = "transaction-status-client-types", version = "=2.1.0" }
Expand Down
12 changes: 12 additions & 0 deletions 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 runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ struct RentMetrics {
pub type BankStatusCache = StatusCache<Result<()>>;
#[cfg_attr(
feature = "frozen-abi",
frozen_abi(digest = "BswQL6n7kKwgHFKcwMCQcrWjt8h59Vh6KkNb75iaqG2B")
frozen_abi(digest = "BHg4qpwegtaJypLUqAdjQYzYeLfEGf6tA4U5cREbHMHi")
)]
pub type BankSlotDelta = SlotDelta<Result<()>>;

Expand Down
7 changes: 5 additions & 2 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ full = [
"sha3",
"digest",
"solana-pubkey/rand",
"dep:solana-precompile-error"
"dep:solana-precompile-error",
"dep:solana-transaction-error"
]
borsh = ["dep:borsh", "solana-program/borsh", "solana-secp256k1-recover/borsh"]
dev-context-only-utils = ["qualifier_attr", "solana-account/dev-context-only-utils"]
Expand All @@ -45,7 +46,8 @@ frozen-abi = [
"solana-account/frozen-abi",
"solana-program/frozen-abi",
"solana-short-vec/frozen-abi",
"solana-signature/frozen-abi"
"solana-signature/frozen-abi",
"solana-transaction-error/frozen-abi"
]

[dependencies]
Expand Down Expand Up @@ -114,6 +116,7 @@ solana-signature = { workspace = true, features = [
"std",
"verify",
], optional = true }
solana-transaction-error = { workspace = true, features = ["serde"], optional = true }
thiserror = { workspace = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
1 change: 1 addition & 0 deletions sdk/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ bitflags = { workspace = true }
curve25519-dalek = { workspace = true }
num-bigint = { workspace = true }
rand = { workspace = true }
solana-transaction-error = { workspace = true }

[target.'cfg(not(target_os = "solana"))'.dev-dependencies]
arbitrary = { workspace = true, features = ["derive"] }
Expand Down
37 changes: 6 additions & 31 deletions sdk/program/src/message/address_loader.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,9 @@
use {
super::v0::{LoadedAddresses, MessageAddressTableLookup},
thiserror::Error,
};

#[derive(Debug, Error, PartialEq, Eq, Clone)]
pub enum AddressLoaderError {
/// Address loading from lookup tables is disabled
#[error("Address loading from lookup tables is disabled")]
Disabled,

/// Failed to load slot hashes sysvar
#[error("Failed to load slot hashes sysvar")]
SlotHashesSysvarNotFound,

/// Attempted to lookup addresses from a table that does not exist
#[error("Attempted to lookup addresses from a table that does not exist")]
LookupTableAccountNotFound,

/// Attempted to lookup addresses from an account owned by the wrong program
#[error("Attempted to lookup addresses from an account owned by the wrong program")]
InvalidAccountOwner,

/// Attempted to lookup addresses from an invalid account
#[error("Attempted to lookup addresses from an invalid account")]
InvalidAccountData,

/// Address lookup contains an invalid index
#[error("Address lookup contains an invalid index")]
InvalidLookupIndex,
}
use super::v0::{LoadedAddresses, MessageAddressTableLookup};
#[deprecated(
since = "2.1.0",
note = "Use solana_transaction_error::AddressLoaderError instead"
)]
pub use solana_transaction_error::AddressLoaderError;

pub trait AddressLoader: Clone {
fn load_addresses(
Expand Down
33 changes: 7 additions & 26 deletions sdk/program/src/message/sanitized.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#[deprecated(
since = "2.1.0",
note = "Use solana_transaction_error::SanitizeMessageError instead"
)]
pub use solana_transaction_error::SanitizeMessageError;
use {
crate::{
ed25519_program,
Expand All @@ -6,8 +11,7 @@ use {
message::{
legacy,
v0::{self, LoadedAddresses},
AccountKeys, AddressLoader, AddressLoaderError, MessageHeader,
SanitizedVersionedMessage, VersionedMessage,
AccountKeys, AddressLoader, MessageHeader, SanitizedVersionedMessage, VersionedMessage,
},
nonce::NONCED_TX_MARKER_IX_INDEX,
program_utils::limited_deserialize,
Expand All @@ -16,9 +20,8 @@ use {
solana_program::{system_instruction::SystemInstruction, system_program},
sysvar::instructions::{BorrowedAccountMeta, BorrowedInstruction},
},
solana_sanitize::{Sanitize, SanitizeError},
solana_sanitize::Sanitize,
std::{borrow::Cow, collections::HashSet, convert::TryFrom},
thiserror::Error,
};

#[derive(Debug, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -80,28 +83,6 @@ pub enum SanitizedMessage {
V0(v0::LoadedMessage<'static>),
}

#[derive(PartialEq, Debug, Error, Eq, Clone)]
pub enum SanitizeMessageError {
#[error("index out of bounds")]
IndexOutOfBounds,
#[error("value out of bounds")]
ValueOutOfBounds,
#[error("invalid value")]
InvalidValue,
#[error("{0}")]
AddressLoaderError(#[from] AddressLoaderError),
}

impl From<SanitizeError> for SanitizeMessageError {
fn from(err: SanitizeError) -> Self {
match err {
SanitizeError::IndexOutOfBounds => Self::IndexOutOfBounds,
SanitizeError::ValueOutOfBounds => Self::ValueOutOfBounds,
SanitizeError::InvalidValue => Self::InvalidValue,
}
}
}

impl SanitizedMessage {
/// Create a sanitized message from a sanitized versioned message.
/// If the input message uses address tables, attempt to look up the
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use {
crate::{
pubkey::Pubkey,
signature::{PresignerError, Signature},
transaction::TransactionError,
},
itertools::Itertools,
solana_derivation_path::DerivationPath,
solana_transaction_error::TransactionError,
std::{
error,
fs::{self, File, OpenOptions},
Expand Down
Loading

0 comments on commit 31bcb94

Please sign in to comment.