From 89953cb8cf386b5065a878c4191d46eb9702f473 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Fri, 21 Jun 2024 03:21:00 +0400 Subject: [PATCH 1/4] extract decode-error crate --- Cargo.lock | 8 ++++++++ Cargo.toml | 2 ++ sdk/decode-error/Cargo.toml | 16 ++++++++++++++++ .../decode_error.rs => decode-error/src/lib.rs} | 0 4 files changed, 26 insertions(+) create mode 100644 sdk/decode-error/Cargo.toml rename sdk/{program/src/decode_error.rs => decode-error/src/lib.rs} (100%) diff --git a/Cargo.lock b/Cargo.lock index 3f63c40568dd26..97e65b0070ecb3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6161,6 +6161,14 @@ dependencies = [ "thiserror", ] +[[package]] +name = "solana-decode-error" +version = "2.1.0" +dependencies = [ + "num-derive", + "num-traits", +] + [[package]] name = "solana-define-syscall" version = "2.1.0" diff --git a/Cargo.toml b/Cargo.toml index 83b14d978974a0..eb09dd38416a76 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -100,6 +100,7 @@ members = [ "sdk/atomic-u64", "sdk/cargo-build-sbf", "sdk/cargo-test-sbf", + "sdk/decode-error", "sdk/gen-headers", "sdk/macro", "sdk/package-metadata-macro", @@ -350,6 +351,7 @@ solana-connection-cache = { path = "connection-cache", version = "=2.1.0", defau solana-core = { path = "core", version = "=2.1.0" } solana-cost-model = { path = "cost-model", version = "=2.1.0" } solana-curve25519 = { path = "curves/curve25519", version = "=2.1.0" } +solana-decode-error = { path = "sdk/decode-error", version = "=2.1.0" } solana-define-syscall = { path = "define-syscall", version = "=2.1.0" } solana-download-utils = { path = "download-utils", version = "=2.1.0" } solana-entry = { path = "entry", version = "=2.1.0" } diff --git a/sdk/decode-error/Cargo.toml b/sdk/decode-error/Cargo.toml new file mode 100644 index 00000000000000..13fb6370791604 --- /dev/null +++ b/sdk/decode-error/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "solana-decode-error" +description = "Solana DecodeError Trait" +documentation = "https://docs.rs/solana-decode-error" +version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[dependencies] +num-traits = { workspace = true } + +[dev-dependencies] +num-derive = { workspace = true } diff --git a/sdk/program/src/decode_error.rs b/sdk/decode-error/src/lib.rs similarity index 100% rename from sdk/program/src/decode_error.rs rename to sdk/decode-error/src/lib.rs From 68d9e3a71366e8d1eeb561cc4da773c68b43fc52 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Fri, 21 Jun 2024 04:12:15 +0400 Subject: [PATCH 2/4] update decode_error dependents and re-export in sdk and program --- Cargo.lock | 3 +++ cli/Cargo.toml | 1 + cli/src/cli.rs | 2 +- programs/sbf/Cargo.lock | 10 ++++++++++ programs/sbf/Cargo.toml | 1 + programs/sbf/rust/error_handling/Cargo.toml | 1 + programs/sbf/rust/error_handling/src/lib.rs | 2 +- sdk/Cargo.toml | 1 + sdk/program/Cargo.toml | 1 + sdk/program/src/lib.rs | 3 ++- sdk/program/src/program_error.rs | 3 ++- sdk/program/src/pubkey.rs | 3 ++- sdk/program/src/stake/instruction.rs | 2 +- sdk/program/src/system_instruction.rs | 2 +- sdk/program/src/vote/error.rs | 2 +- sdk/src/lib.rs | 4 +++- sdk/src/precompiles.rs | 6 ++---- 17 files changed, 34 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 97e65b0070ecb3..d7bf83a7f4d373 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5847,6 +5847,7 @@ dependencies = [ "solana-compute-budget", "solana-config-program", "solana-connection-cache", + "solana-decode-error", "solana-faucet", "solana-loader-v4-program", "solana-logger", @@ -6835,6 +6836,7 @@ dependencies = [ "sha2 0.10.8", "sha3 0.10.8", "solana-atomic-u64", + "solana-decode-error", "solana-define-syscall", "solana-frozen-abi", "solana-frozen-abi-macro", @@ -7305,6 +7307,7 @@ dependencies = [ "sha2 0.10.8", "sha3 0.10.8", "siphasher", + "solana-decode-error", "solana-frozen-abi", "solana-frozen-abi-macro", "solana-logger", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 1a0f24d2d04f62..6b9aa6792be253 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -37,6 +37,7 @@ solana-client = { workspace = true } solana-compute-budget = { workspace = true } solana-config-program = { workspace = true } solana-connection-cache = { workspace = true } +solana-decode-error = { workspace = true } solana-loader-v4-program = { workspace = true } solana-logger = { workspace = true } solana-program-runtime = { workspace = true } diff --git a/cli/src/cli.rs b/cli/src/cli.rs index af1b84493298fa..f051891fa29901 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -13,6 +13,7 @@ use { display::println_name_value, CliSignature, CliValidatorsSortOrder, OutputFormat, }, solana_client::connection_cache::ConnectionCache, + solana_decode_error::DecodeError, solana_remote_wallet::remote_wallet::RemoteWalletManager, solana_rpc_client::rpc_client::RpcClient, solana_rpc_client_api::{ @@ -23,7 +24,6 @@ use { solana_sdk::{ clock::{Epoch, Slot}, commitment_config::CommitmentConfig, - decode_error::DecodeError, hash::Hash, instruction::InstructionError, offchain_message::OffchainMessage, diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index bf3e18d7f34bc2..072aa00d028ad5 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -4917,6 +4917,13 @@ dependencies = [ "thiserror", ] +[[package]] +name = "solana-decode-error" +version = "2.1.0" +dependencies = [ + "num-traits", +] + [[package]] name = "solana-define-syscall" version = "2.1.0" @@ -5309,6 +5316,7 @@ dependencies = [ "sha2 0.10.8", "sha3 0.10.8", "solana-atomic-u64", + "solana-decode-error", "solana-define-syscall", "solana-sanitize", "solana-sdk-macro", @@ -5792,6 +5800,7 @@ version = "2.1.0" dependencies = [ "num-derive", "num-traits", + "solana-decode-error", "solana-program", "thiserror", ] @@ -6149,6 +6158,7 @@ dependencies = [ "sha2 0.10.8", "sha3 0.10.8", "siphasher", + "solana-decode-error", "solana-program", "solana-sanitize", "solana-sdk-macro", diff --git a/programs/sbf/Cargo.toml b/programs/sbf/Cargo.toml index 390b863872a2ef..111beed9b0ace2 100644 --- a/programs/sbf/Cargo.toml +++ b/programs/sbf/Cargo.toml @@ -31,6 +31,7 @@ solana-bpf-loader-program = { path = "../bpf_loader", version = "=2.1.0" } solana-cli-output = { path = "../../cli-output", version = "=2.1.0" } solana-compute-budget = { path = "../../compute-budget", version = "=2.1.0" } solana-curve25519 = { path = "../../curves/curve25519", version = "=2.1.0" } +solana-decode-error = { path = "../../sdk/decode-error", version = "=2.1.0" } solana-ledger = { path = "../../ledger", version = "=2.1.0" } solana-log-collector = { path = "../../log-collector", version = "=2.1.0" } solana-logger = { path = "../../logger", version = "=2.1.0" } diff --git a/programs/sbf/rust/error_handling/Cargo.toml b/programs/sbf/rust/error_handling/Cargo.toml index d95e9d0eb925b0..a623d0163bc44a 100644 --- a/programs/sbf/rust/error_handling/Cargo.toml +++ b/programs/sbf/rust/error_handling/Cargo.toml @@ -11,6 +11,7 @@ edition = { workspace = true } [dependencies] num-derive = { workspace = true } num-traits = { workspace = true } +solana-decode-error = { workspace = true } solana-program = { workspace = true } thiserror = { workspace = true } diff --git a/programs/sbf/rust/error_handling/src/lib.rs b/programs/sbf/rust/error_handling/src/lib.rs index ffd045ef1b3962..75aa233d867d12 100644 --- a/programs/sbf/rust/error_handling/src/lib.rs +++ b/programs/sbf/rust/error_handling/src/lib.rs @@ -4,9 +4,9 @@ extern crate solana_program; use { num_derive::FromPrimitive, num_traits::FromPrimitive, + solana_decode_error::DecodeError, solana_program::{ account_info::AccountInfo, - decode_error::DecodeError, entrypoint::ProgramResult, msg, program_error::{PrintProgramError, ProgramError}, diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index f2e6cc6d7cc2d3..c8327e192a8a8c 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -79,6 +79,7 @@ serde_with = { workspace = true, features = ["macros"] } sha2 = { workspace = true } sha3 = { workspace = true, optional = true } siphasher = { workspace = true } +solana-decode-error = { workspace = true } solana-frozen-abi = { workspace = true, optional = true } solana-frozen-abi-macro = { workspace = true, optional = true } solana-program = { workspace = true } diff --git a/sdk/program/Cargo.toml b/sdk/program/Cargo.toml index 2d2625322f5667..fabb555d1a96a5 100644 --- a/sdk/program/Cargo.toml +++ b/sdk/program/Cargo.toml @@ -32,6 +32,7 @@ serde_derive = { workspace = true } sha2 = { workspace = true } sha3 = { workspace = true } solana-atomic-u64 = { workspace = true } +solana-decode-error = { workspace = true } solana-frozen-abi = { workspace = true, optional = true } solana-frozen-abi-macro = { workspace = true, optional = true } solana-sanitize = { workspace = true } diff --git a/sdk/program/src/lib.rs b/sdk/program/src/lib.rs index a23b9dcf3696c7..054f249e7f99fe 100644 --- a/sdk/program/src/lib.rs +++ b/sdk/program/src/lib.rs @@ -486,7 +486,6 @@ pub mod bpf_loader_upgradeable; pub mod clock; pub mod compute_units; pub mod debug_account_data; -pub mod decode_error; pub mod ed25519_program; pub mod entrypoint; pub mod entrypoint_deprecated; @@ -592,6 +591,8 @@ pub mod sdk_ids { } } +#[deprecated(since = "2.1.0", note = "Use `solana-decode-error` crate instead")] +pub use solana_decode_error as decode_error; /// Same as [`declare_id`] except that it reports that this ID has been deprecated. pub use solana_sdk_macro::program_declare_deprecated_id as declare_deprecated_id; /// Convenience macro to declare a static public key and functions to interact with it. diff --git a/sdk/program/src/program_error.rs b/sdk/program/src/program_error.rs index f80827ca6c953c..f225561a52d389 100644 --- a/sdk/program/src/program_error.rs +++ b/sdk/program/src/program_error.rs @@ -4,8 +4,9 @@ #[cfg(feature = "borsh")] use borsh::io::Error as BorshIoError; use { - crate::{decode_error::DecodeError, instruction::InstructionError, msg, pubkey::PubkeyError}, + crate::{instruction::InstructionError, msg, pubkey::PubkeyError}, num_traits::{FromPrimitive, ToPrimitive}, + solana_decode_error::DecodeError, std::convert::TryFrom, thiserror::Error, }; diff --git a/sdk/program/src/pubkey.rs b/sdk/program/src/pubkey.rs index e9cabcc48c141e..5d3433c1247f90 100644 --- a/sdk/program/src/pubkey.rs +++ b/sdk/program/src/pubkey.rs @@ -9,9 +9,10 @@ use arbitrary::Arbitrary; #[cfg(feature = "borsh")] use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; use { - crate::{decode_error::DecodeError, hash::hashv}, + crate::hash::hashv, bytemuck_derive::{Pod, Zeroable}, num_derive::{FromPrimitive, ToPrimitive}, + solana_decode_error::DecodeError, std::{ convert::{Infallible, TryFrom}, fmt, mem, diff --git a/sdk/program/src/stake/instruction.rs b/sdk/program/src/stake/instruction.rs index e2a5b056e70618..57559d817ba328 100644 --- a/sdk/program/src/stake/instruction.rs +++ b/sdk/program/src/stake/instruction.rs @@ -3,7 +3,6 @@ use crate::stake::config; use { crate::{ clock::{Epoch, UnixTimestamp}, - decode_error::DecodeError, instruction::{AccountMeta, Instruction}, program_error::ProgramError, pubkey::Pubkey, @@ -16,6 +15,7 @@ use { log::*, num_derive::{FromPrimitive, ToPrimitive}, serde_derive::{Deserialize, Serialize}, + solana_decode_error::DecodeError, thiserror::Error, }; diff --git a/sdk/program/src/system_instruction.rs b/sdk/program/src/system_instruction.rs index 47fc97fbe0f69b..a1c301b85cdab9 100644 --- a/sdk/program/src/system_instruction.rs +++ b/sdk/program/src/system_instruction.rs @@ -42,7 +42,6 @@ #[allow(deprecated)] use { crate::{ - decode_error::DecodeError, instruction::{AccountMeta, Instruction}, nonce, pubkey::Pubkey, @@ -50,6 +49,7 @@ use { sysvar::{recent_blockhashes, rent}, }, num_derive::{FromPrimitive, ToPrimitive}, + solana_decode_error::DecodeError, thiserror::Error, }; diff --git a/sdk/program/src/vote/error.rs b/sdk/program/src/vote/error.rs index a5ec60ce5232fa..1883186f6e2b65 100644 --- a/sdk/program/src/vote/error.rs +++ b/sdk/program/src/vote/error.rs @@ -1,8 +1,8 @@ //! Vote program errors use { - crate::decode_error::DecodeError, num_derive::{FromPrimitive, ToPrimitive}, + solana_decode_error::DecodeError, thiserror::Error, }; diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index c6fbd2e301e6fb..9cf11e89582d2b 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -58,7 +58,6 @@ pub use solana_program::{ }; #[cfg(feature = "borsh")] pub use solana_program::{borsh, borsh0_10, borsh1}; - pub mod account; pub mod account_utils; pub mod client; @@ -110,6 +109,9 @@ pub mod transaction_context; pub mod transport; pub mod wasm; +#[deprecated(since = "2.1.0", note = "Use `solana-decode-error` crate instead")] +pub use solana_decode_error as decode_error; + #[deprecated(since = "2.1.0", note = "Use `solana-sanitize` crate instead")] pub use solana_sanitize as sanitize; /// Same as `declare_id` except report that this id has been deprecated. diff --git a/sdk/src/precompiles.rs b/sdk/src/precompiles.rs index 34885b05e287a9..04e1e2ea2ec389 100644 --- a/sdk/src/precompiles.rs +++ b/sdk/src/precompiles.rs @@ -3,11 +3,9 @@ #![cfg(feature = "full")] use { - crate::{ - decode_error::DecodeError, feature_set::FeatureSet, instruction::CompiledInstruction, - pubkey::Pubkey, - }, + crate::{feature_set::FeatureSet, instruction::CompiledInstruction, pubkey::Pubkey}, lazy_static::lazy_static, + solana_decode_error::DecodeError, thiserror::Error, }; From de1c91a750039e053a70c6e5a54460b17ed5624f Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Sat, 29 Jun 2024 13:42:07 +0400 Subject: [PATCH 3/4] fmt --- sdk/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 9cf11e89582d2b..ec38d487df4cc5 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -111,7 +111,6 @@ pub mod wasm; #[deprecated(since = "2.1.0", note = "Use `solana-decode-error` crate instead")] pub use solana_decode_error as decode_error; - #[deprecated(since = "2.1.0", note = "Use `solana-sanitize` crate instead")] pub use solana_sanitize as sanitize; /// Same as `declare_id` except report that this id has been deprecated. From 9ce5578087c65aebe6a8893c991ab1ec58b29645 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Sat, 29 Jun 2024 13:47:11 +0400 Subject: [PATCH 4/4] fix bad import after rebase --- sdk/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index ec38d487df4cc5..c460c625cb27be 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -49,9 +49,9 @@ pub use solana_program::{ account_info, address_lookup_table, alt_bn128, big_mod_exp, blake3, bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, clock, config, custom_heap_default, custom_panic_default, debug_account_data, declare_deprecated_sysvar_id, declare_sysvar_id, - decode_error, ed25519_program, epoch_rewards, epoch_schedule, fee_calculator, impl_sysvar_get, - incinerator, instruction, keccak, lamports, loader_instruction, loader_upgradeable_instruction, - loader_v4, loader_v4_instruction, message, msg, native_token, nonce, program, program_error, + ed25519_program, epoch_rewards, epoch_schedule, fee_calculator, impl_sysvar_get, incinerator, + instruction, keccak, lamports, loader_instruction, loader_upgradeable_instruction, loader_v4, + loader_v4_instruction, message, msg, native_token, nonce, program, program_error, program_memory, program_option, program_pack, rent, secp256k1_program, serde_varint, serialize_utils, short_vec, slot_hashes, slot_history, stable_layout, stake, stake_history, syscalls, system_instruction, system_program, sysvar, unchecked_div_by_const, vote,