From 4879c304914f5d0590a4fd10d53e383b0fb6ede7 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Thu, 25 Jul 2024 21:24:09 +0400 Subject: [PATCH 01/16] extract account crate --- Cargo.lock | 12 +++++++++++ Cargo.toml | 2 ++ sdk/account/Cargo.toml | 24 ++++++++++++++++++++++ sdk/{src/account.rs => account/src/lib.rs} | 24 +++++++++++----------- 4 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 sdk/account/Cargo.toml rename sdk/{src/account.rs => account/src/lib.rs} (98%) diff --git a/Cargo.lock b/Cargo.lock index 40a271eb1a6c78..d6782372a8a0ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5625,6 +5625,18 @@ dependencies = [ "sha-1 0.9.8", ] +[[package]] +name = "solana-acccount" +version = "2.1.0" +dependencies = [ + "bincode", + "qualifier_attr", + "serde", + "serde_bytes", + "serde_derive", + "solana-program", +] + [[package]] name = "solana-account-decoder" version = "2.1.0" diff --git a/Cargo.toml b/Cargo.toml index a61b7aacad85fc..31ccbcc3186d59 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -101,6 +101,7 @@ members = [ "runtime-transaction", "sanitize", "sdk", + "sdk/account", "sdk/account-info", "sdk/atomic-u64", "sdk/cargo-build-sbf", @@ -364,6 +365,7 @@ smallvec = "1.13.2" smpl_jwt = "0.7.1" socket2 = "0.5.7" soketto = "0.7" +solana-account = { path = "sdk/account", version = "=2.1.0" } solana-account-decoder = { path = "account-decoder", version = "=2.1.0" } solana-account-info = { path = "sdk/account-info", version = "=2.1.0" } solana-accounts-db = { path = "accounts-db", version = "=2.1.0" } diff --git a/sdk/account/Cargo.toml b/sdk/account/Cargo.toml new file mode 100644 index 00000000000000..41a8bbb102e05e --- /dev/null +++ b/sdk/account/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "solana-acccount" +description = "Solana Account type" +documentation = "https://docs.rs/solana-account" +version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[dependencies] +bincode = { workspace = true } +qualifier_attr = { workspace = true, optional = true } +serde = { workspace = true } +serde_bytes = { workspace = true } +serde_derive = { workspace = true } +solana-program = { workspace = true } + +[features] +dev-context-only-utils = ["dep:qualifier_attr"] + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] diff --git a/sdk/src/account.rs b/sdk/account/src/lib.rs similarity index 98% rename from sdk/src/account.rs rename to sdk/account/src/lib.rs index cb7dfbc9638c3e..95508a1f8ac3d5 100644 --- a/sdk/src/account.rs +++ b/sdk/account/src/lib.rs @@ -3,18 +3,17 @@ #[cfg(feature = "dev-context-only-utils")] use qualifier_attr::qualifiers; use { - crate::{ + serde::ser::{Serialize, Serializer}, + solana_program::{ + account_info::AccountInfo, bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, clock::{Epoch, INITIAL_RENT_EPOCH}, + debug_account_data::*, lamports::LamportsError, loader_v4, pubkey::Pubkey, + sysvar::Sysvar, }, - serde::{ - ser::{Serialize, Serializer}, - Deserialize, - }, - solana_program::{account_info::AccountInfo, debug_account_data::*, sysvar::Sysvar}, std::{ cell::{Ref, RefCell}, fmt, @@ -32,7 +31,7 @@ use { derive(AbiExample), frozen_abi(digest = "2SUJNHbXMPWrsSXmDTFc4VHx2XQ85fT5Leabefh5Nwe7") )] -#[derive(Deserialize, PartialEq, Eq, Clone, Default)] +#[derive(serde_derive::Deserialize, PartialEq, Eq, Clone, Default)] #[serde(rename_all = "camelCase")] pub struct Account { /// lamports in the account @@ -51,7 +50,8 @@ pub struct Account { // mod because we need 'Account' below to have the name 'Account' to match expected serialization mod account_serialize { use { - crate::{account::ReadableAccount, clock::Epoch, pubkey::Pubkey}, + crate::ReadableAccount, + solana_program::{clock::Epoch, pubkey::Pubkey}, serde::{ser::Serializer, Serialize}, }; #[repr(C)] @@ -60,7 +60,7 @@ mod account_serialize { derive(AbiExample), frozen_abi(digest = "2SUJNHbXMPWrsSXmDTFc4VHx2XQ85fT5Leabefh5Nwe7") )] - #[derive(Serialize)] + #[derive(serde_derive::Serialize)] #[serde(rename_all = "camelCase")] struct Account<'a> { lamports: u64, @@ -96,7 +96,7 @@ impl Serialize for Account { where S: Serializer, { - crate::account::account_serialize::serialize_account(self, serializer) + crate::account_serialize::serialize_account(self, serializer) } } @@ -105,7 +105,7 @@ impl Serialize for AccountSharedData { where S: Serializer, { - crate::account::account_serialize::serialize_account(self, serializer) + crate::account_serialize::serialize_account(self, serializer) } } @@ -113,7 +113,7 @@ impl Serialize for AccountSharedData { /// This will be the in-memory representation of the 'Account' struct data. /// The existing 'Account' structure cannot easily change due to downstream projects. #[cfg_attr(feature = "frozen-abi", derive(AbiExample))] -#[derive(PartialEq, Eq, Clone, Default, Deserialize)] +#[derive(PartialEq, Eq, Clone, Default, serde_derive::Deserialize)] #[serde(from = "Account")] pub struct AccountSharedData { /// lamports in the account From 49fe2b02b739d265a12952ddd6e318df3c22a99d Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Thu, 25 Jul 2024 21:30:13 +0400 Subject: [PATCH 02/16] tpyo in crate name --- Cargo.lock | 2 +- sdk/account/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d6782372a8a0ea..bc6876bccb3b22 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5626,7 +5626,7 @@ dependencies = [ ] [[package]] -name = "solana-acccount" +name = "solana-account" version = "2.1.0" dependencies = [ "bincode", diff --git a/sdk/account/Cargo.toml b/sdk/account/Cargo.toml index 41a8bbb102e05e..77083c96b79d28 100644 --- a/sdk/account/Cargo.toml +++ b/sdk/account/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "solana-acccount" +name = "solana-account" description = "Solana Account type" documentation = "https://docs.rs/solana-account" version = { workspace = true } From b418b128f8e8555e0c71c0f8192f9f59765e1a92 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Thu, 25 Jul 2024 21:32:00 +0400 Subject: [PATCH 03/16] update account usage in sdk --- Cargo.lock | 1 + sdk/Cargo.toml | 3 ++- sdk/src/account_utils.rs | 9 ++++----- sdk/src/client.rs | 5 ++--- sdk/src/feature.rs | 2 +- sdk/src/genesis_config.rs | 2 +- sdk/src/lib.rs | 1 - sdk/src/native_loader.rs | 2 +- sdk/src/nonce_account.rs | 2 +- sdk/src/rent_collector.rs | 8 ++++---- sdk/src/transaction_context.rs | 4 ++-- 11 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc6876bccb3b22..7cd2ae5eb40478 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7826,6 +7826,7 @@ dependencies = [ "sha2 0.10.8", "sha3", "siphasher", + "solana-account", "solana-bn254", "solana-decode-error", "solana-derivation-path", diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 8793f1e58bd1ab..137677fba8c1ca 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -35,7 +35,7 @@ full = [ "digest", ] borsh = ["dep:borsh", "solana-program/borsh", "solana-secp256k1-recover/borsh"] -dev-context-only-utils = ["qualifier_attr"] +dev-context-only-utils = ["qualifier_attr", "solana-account/dev-context-only-utils"] frozen-abi = [ "dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", @@ -83,6 +83,7 @@ serde_with = { workspace = true, features = ["macros"] } sha2 = { workspace = true } sha3 = { workspace = true, optional = true } siphasher = { workspace = true } +solana-account = { workspace = true } solana-bn254 = { workspace = true } solana-decode-error = { workspace = true } solana-derivation-path = { workspace = true } diff --git a/sdk/src/account_utils.rs b/sdk/src/account_utils.rs index e6e6a7bccd1b2b..efe83ccc21f295 100644 --- a/sdk/src/account_utils.rs +++ b/sdk/src/account_utils.rs @@ -1,11 +1,9 @@ //! Useful extras for `Account` state. use { - crate::{ - account::{Account, AccountSharedData}, - instruction::InstructionError, - }, + crate::instruction::InstructionError, bincode::ErrorKind, + solana_account::{Account, AccountSharedData}, std::cell::Ref, }; @@ -68,7 +66,8 @@ where mod tests { use { super::*, - crate::{account::AccountSharedData, pubkey::Pubkey}, + crate::pubkey::Pubkey, + solana_account::AccountSharedData }; #[test] diff --git a/sdk/src/client.rs b/sdk/src/client.rs index 185b9aeeb0d40b..1136d8103579df 100644 --- a/sdk/src/client.rs +++ b/sdk/src/client.rs @@ -9,8 +9,7 @@ #![cfg(feature = "full")] -use crate::{ - account::Account, +use {crate::{ clock::Slot, commitment_config::CommitmentConfig, epoch_info::EpochInfo, @@ -24,7 +23,7 @@ use crate::{ system_instruction, transaction::{self, Transaction, VersionedTransaction}, transport::Result, -}; +}, solana_account::Account}; pub trait Client: SyncClient + AsyncClient { fn tpu_addr(&self) -> String; diff --git a/sdk/src/feature.rs b/sdk/src/feature.rs index bca42e7bb6d327..a59e38ff0d252f 100644 --- a/sdk/src/feature.rs +++ b/sdk/src/feature.rs @@ -1,6 +1,6 @@ //! Methods for working with `Feature` accounts. -use crate::account::{AccountSharedData, ReadableAccount, WritableAccount}; +use solana_account::{AccountSharedData, ReadableAccount, WritableAccount}; pub use solana_program::feature::*; pub fn from_account(account: &T) -> Option { diff --git a/sdk/src/genesis_config.rs b/sdk/src/genesis_config.rs index 8e3f89f254830e..1032e8b7ed8a5f 100644 --- a/sdk/src/genesis_config.rs +++ b/sdk/src/genesis_config.rs @@ -4,7 +4,6 @@ use { crate::{ - account::{Account, AccountSharedData}, clock::{UnixTimestamp, DEFAULT_TICKS_PER_SLOT}, epoch_schedule::EpochSchedule, fee_calculator::FeeRateGovernor, @@ -22,6 +21,7 @@ use { bincode::{deserialize, serialize}, chrono::{TimeZone, Utc}, memmap2::Mmap, + solana_account::{Account, AccountSharedData}, std::{ collections::BTreeMap, fmt, diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 07c92473cbb46a..d61e01f4768c94 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; pub mod commitment_config; diff --git a/sdk/src/native_loader.rs b/sdk/src/native_loader.rs index 53a7ded4b61f54..1f32d3988fcf58 100644 --- a/sdk/src/native_loader.rs +++ b/sdk/src/native_loader.rs @@ -1,6 +1,6 @@ //! The native loader native program. -use crate::account::{ +use solana_account::{ Account, AccountSharedData, InheritableAccountFields, DUMMY_INHERITABLE_ACCOUNT_FIELDS, }; diff --git a/sdk/src/nonce_account.rs b/sdk/src/nonce_account.rs index 255011a7bb6402..f2127790345b92 100644 --- a/sdk/src/nonce_account.rs +++ b/sdk/src/nonce_account.rs @@ -2,7 +2,6 @@ use { crate::{ - account::{AccountSharedData, ReadableAccount}, account_utils::StateMut, hash::Hash, nonce::{ @@ -10,6 +9,7 @@ use { State, }, }, + solana_account::{AccountSharedData, ReadableAccount}, std::cell::RefCell, }; diff --git a/sdk/src/rent_collector.rs b/sdk/src/rent_collector.rs index 96a7e479db76a6..dff3e7264ed7eb 100644 --- a/sdk/src/rent_collector.rs +++ b/sdk/src/rent_collector.rs @@ -1,15 +1,14 @@ #![cfg(feature = "full")] //! calculate and collect rent from Accounts -use solana_sdk::{ - account::{AccountSharedData, ReadableAccount, WritableAccount}, +use {solana_sdk::{ clock::Epoch, epoch_schedule::EpochSchedule, genesis_config::GenesisConfig, incinerator, pubkey::Pubkey, rent::{Rent, RentDue}, -}; +}, solana_account::{AccountSharedData, ReadableAccount, WritableAccount}}; #[cfg_attr(feature = "frozen-abi", derive(AbiExample))] #[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] @@ -216,7 +215,8 @@ mod tests { use { super::*, assert_matches::assert_matches, - solana_sdk::{account::Account, sysvar}, + solana_account::Account, + solana_sdk::sysvar, }; fn default_rent_collector_clone_with_epoch(epoch: Epoch) -> RentCollector { diff --git a/sdk/src/transaction_context.rs b/sdk/src/transaction_context.rs index 0bb2f0ec983659..013c9c17ad2d13 100644 --- a/sdk/src/transaction_context.rs +++ b/sdk/src/transaction_context.rs @@ -6,21 +6,21 @@ use crate::signature::Signature; #[cfg(not(target_os = "solana"))] use { crate::{ - account::WritableAccount, rent::Rent, system_instruction::{ MAX_PERMITTED_ACCOUNTS_DATA_ALLOCATIONS_PER_TRANSACTION, MAX_PERMITTED_DATA_LENGTH, }, }, + solana_account::WritableAccount, solana_program::entrypoint::MAX_PERMITTED_DATA_INCREASE, std::mem::MaybeUninit, }; use { crate::{ - account::{AccountSharedData, ReadableAccount}, instruction::InstructionError, pubkey::Pubkey, }, + solana_account::{AccountSharedData, ReadableAccount}, std::{ cell::{Ref, RefCell, RefMut}, collections::HashSet, From 741822f4a3b9b2df30f0cbcaa4f6710a1b139f72 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Thu, 25 Jul 2024 21:35:25 +0400 Subject: [PATCH 04/16] update solana-program examples --- sdk/program/src/message/versions/v0/mod.rs | 2 +- sdk/program/src/system_instruction.rs | 2 +- sdk/program/src/sysvar/clock.rs | 2 +- sdk/program/src/sysvar/epoch_rewards.rs | 2 +- sdk/program/src/sysvar/epoch_schedule.rs | 2 +- sdk/program/src/sysvar/rent.rs | 2 +- sdk/program/src/sysvar/slot_hashes.rs | 2 +- sdk/program/src/sysvar/slot_history.rs | 2 +- sdk/program/src/sysvar/stake_history.rs | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sdk/program/src/message/versions/v0/mod.rs b/sdk/program/src/message/versions/v0/mod.rs index 9eaad5a9b39944..dfe6cbd350cbdc 100644 --- a/sdk/program/src/message/versions/v0/mod.rs +++ b/sdk/program/src/message/versions/v0/mod.rs @@ -195,7 +195,7 @@ impl Message { /// # solana_sdk, /// # }; /// # use std::borrow::Cow; - /// # use solana_sdk::account::Account; + /// # use solana_account::Account; /// use anyhow::Result; /// use solana_rpc_client::rpc_client::RpcClient; /// use solana_program::address_lookup_table::{self, state::{AddressLookupTable, LookupTableMeta}}; diff --git a/sdk/program/src/system_instruction.rs b/sdk/program/src/system_instruction.rs index bd0fcb0b37e0a6..257bc6bcc8c87d 100644 --- a/sdk/program/src/system_instruction.rs +++ b/sdk/program/src/system_instruction.rs @@ -1503,7 +1503,7 @@ pub fn create_nonce_account( /// system_instruction, /// transaction::Transaction, /// }; -/// # use solana_sdk::account::Account; +/// # use solana_account::Account; /// use std::path::Path; /// use anyhow::Result; /// # use anyhow::anyhow; diff --git a/sdk/program/src/sysvar/clock.rs b/sdk/program/src/sysvar/clock.rs index db87594001d578..8bec98b8a6e545 100644 --- a/sdk/program/src/sysvar/clock.rs +++ b/sdk/program/src/sysvar/clock.rs @@ -100,7 +100,7 @@ //! ``` //! # use solana_program::example_mocks::solana_sdk; //! # use solana_program::example_mocks::solana_rpc_client; -//! # use solana_sdk::account::Account; +//! # use solana_account::Account; //! # use solana_rpc_client::rpc_client::RpcClient; //! # use solana_sdk::sysvar::clock::{self, Clock}; //! # use anyhow::Result; diff --git a/sdk/program/src/sysvar/epoch_rewards.rs b/sdk/program/src/sysvar/epoch_rewards.rs index c8aa7bfbbc88e3..2fb91c8805fc6a 100755 --- a/sdk/program/src/sysvar/epoch_rewards.rs +++ b/sdk/program/src/sysvar/epoch_rewards.rs @@ -125,7 +125,7 @@ //! ``` //! # use solana_program::example_mocks::solana_sdk; //! # use solana_program::example_mocks::solana_rpc_client; -//! # use solana_sdk::account::Account; +//! # use solana_account::Account; //! # use solana_rpc_client::rpc_client::RpcClient; //! # use solana_sdk::sysvar::epoch_rewards::{self, EpochRewards}; //! # use anyhow::Result; diff --git a/sdk/program/src/sysvar/epoch_schedule.rs b/sdk/program/src/sysvar/epoch_schedule.rs index 0f3a0aa68896f8..c03bfa9e20cbf6 100644 --- a/sdk/program/src/sysvar/epoch_schedule.rs +++ b/sdk/program/src/sysvar/epoch_schedule.rs @@ -100,7 +100,7 @@ //! ``` //! # use solana_program::example_mocks::solana_sdk; //! # use solana_program::example_mocks::solana_rpc_client; -//! # use solana_sdk::account::Account; +//! # use solana_account::Account; //! # use solana_rpc_client::rpc_client::RpcClient; //! # use solana_sdk::sysvar::epoch_schedule::{self, EpochSchedule}; //! # use anyhow::Result; diff --git a/sdk/program/src/sysvar/rent.rs b/sdk/program/src/sysvar/rent.rs index 4767838383b22f..fa1588317b5b9b 100644 --- a/sdk/program/src/sysvar/rent.rs +++ b/sdk/program/src/sysvar/rent.rs @@ -101,7 +101,7 @@ //! ``` //! # use solana_program::example_mocks::solana_sdk; //! # use solana_program::example_mocks::solana_rpc_client; -//! # use solana_sdk::account::Account; +//! # use solana_account::Account; //! # use solana_rpc_client::rpc_client::RpcClient; //! # use solana_sdk::sysvar::rent::{self, Rent}; //! # use anyhow::Result; diff --git a/sdk/program/src/sysvar/slot_hashes.rs b/sdk/program/src/sysvar/slot_hashes.rs index ab683c1802b441..2e19ba4346e677 100644 --- a/sdk/program/src/sysvar/slot_hashes.rs +++ b/sdk/program/src/sysvar/slot_hashes.rs @@ -19,7 +19,7 @@ //! ``` //! # use solana_program::example_mocks::solana_sdk; //! # use solana_program::example_mocks::solana_rpc_client; -//! # use solana_sdk::account::Account; +//! # use solana_account::Account; //! # use solana_rpc_client::rpc_client::RpcClient; //! # use solana_sdk::sysvar::slot_hashes::{self, SlotHashes}; //! # use anyhow::Result; diff --git a/sdk/program/src/sysvar/slot_history.rs b/sdk/program/src/sysvar/slot_history.rs index 668d4f194e2f8d..442ef58fa940ce 100644 --- a/sdk/program/src/sysvar/slot_history.rs +++ b/sdk/program/src/sysvar/slot_history.rs @@ -19,7 +19,7 @@ //! ``` //! # use solana_program::example_mocks::solana_sdk; //! # use solana_program::example_mocks::solana_rpc_client; -//! # use solana_sdk::account::Account; +//! # use solana_account::Account; //! # use solana_rpc_client::rpc_client::RpcClient; //! # use solana_sdk::sysvar::slot_history::{self, SlotHistory}; //! # use anyhow::Result; diff --git a/sdk/program/src/sysvar/stake_history.rs b/sdk/program/src/sysvar/stake_history.rs index 0c41689b102f71..e22842d692cb4a 100644 --- a/sdk/program/src/sysvar/stake_history.rs +++ b/sdk/program/src/sysvar/stake_history.rs @@ -19,7 +19,7 @@ //! ``` //! # use solana_program::example_mocks::solana_sdk; //! # use solana_program::example_mocks::solana_rpc_client; -//! # use solana_sdk::account::Account; +//! # use solana_account::Account; //! # use solana_rpc_client::rpc_client::RpcClient; //! # use solana_sdk::sysvar::stake_history::{self, StakeHistory}; //! # use anyhow::Result; From 05a787b9d6785322f5fccb084ddb854dc6934e78 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Thu, 25 Jul 2024 21:43:52 +0400 Subject: [PATCH 05/16] re-export solana_account with deprecation notice --- sdk/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index d61e01f4768c94..11f65d40eedaec 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -106,6 +106,8 @@ pub mod transaction_context; pub mod transport; pub mod wasm; +#[deprecated(since = "2.1.0", note = "Use `solana-account` crate instead")] +pub use solana_account as account; #[deprecated(since = "2.1.0", note = "Use `solana-bn254` crate instead")] pub use solana_bn254 as alt_bn128; #[deprecated(since = "2.1.0", note = "Use `solana-decode-error` crate instead")] From aec0ac16640c8c28ce9b697eb93188f0d1ee292e Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Thu, 25 Jul 2024 21:52:40 +0400 Subject: [PATCH 06/16] fix frozen-abi support --- Cargo.lock | 4 ++++ sdk/Cargo.toml | 1 + sdk/account/Cargo.toml | 12 ++++++++++++ sdk/account/build.rs | 22 ++++++++++++++++++++++ sdk/account/src/lib.rs | 5 +++++ 5 files changed, 44 insertions(+) create mode 100644 sdk/account/build.rs diff --git a/Cargo.lock b/Cargo.lock index 7cd2ae5eb40478..5a8e96af186a53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5631,9 +5631,13 @@ version = "2.1.0" dependencies = [ "bincode", "qualifier_attr", + "rustc_version 0.4.0", "serde", "serde_bytes", "serde_derive", + "solana-frozen-abi", + "solana-frozen-abi-macro", + "solana-logger", "solana-program", ] diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 137677fba8c1ca..de82f1352eed27 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -41,6 +41,7 @@ frozen-abi = [ "dep:solana-frozen-abi-macro", "solana-feature-set/frozen-abi", "solana-program/frozen-abi", + "solana-account/frozen-abi", "solana-short-vec/frozen-abi", "solana-signature/frozen-abi" ] diff --git a/sdk/account/Cargo.toml b/sdk/account/Cargo.toml index 77083c96b79d28..77dbf349dbd4e2 100644 --- a/sdk/account/Cargo.toml +++ b/sdk/account/Cargo.toml @@ -15,10 +15,22 @@ qualifier_attr = { workspace = true, optional = true } serde = { workspace = true } serde_bytes = { workspace = true } serde_derive = { workspace = true } +solana-frozen-abi = { workspace = true, optional = true } +solana-frozen-abi-macro = { workspace = true, optional = true } +solana-logger = { workspace = true, optional = true } solana-program = { workspace = true } +[build-dependencies] +rustc_version = { workspace = true } + [features] dev-context-only-utils = ["dep:qualifier_attr"] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "dep:solana-logger", + "solana-program/frozen-abi" +] [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/sdk/account/build.rs b/sdk/account/build.rs new file mode 100644 index 00000000000000..e17ca70cb4718b --- /dev/null +++ b/sdk/account/build.rs @@ -0,0 +1,22 @@ +extern crate rustc_version; +use rustc_version::{version_meta, Channel}; + +fn main() { + // Copied and adapted from + // https://github.com/Kimundi/rustc-version-rs/blob/1d692a965f4e48a8cb72e82cda953107c0d22f47/README.md#example + // Licensed under Apache-2.0 + MIT + match version_meta().unwrap().channel { + Channel::Stable => { + println!("cargo:rustc-cfg=RUSTC_WITHOUT_SPECIALIZATION"); + } + Channel::Beta => { + println!("cargo:rustc-cfg=RUSTC_WITHOUT_SPECIALIZATION"); + } + Channel::Nightly => { + println!("cargo:rustc-cfg=RUSTC_WITH_SPECIALIZATION"); + } + Channel::Dev => { + println!("cargo:rustc-cfg=RUSTC_WITH_SPECIALIZATION"); + } + } +} diff --git a/sdk/account/src/lib.rs b/sdk/account/src/lib.rs index 95508a1f8ac3d5..9466492e756daf 100644 --- a/sdk/account/src/lib.rs +++ b/sdk/account/src/lib.rs @@ -1,7 +1,10 @@ +#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(min_specialization))] //! The Solana [`Account`] type. #[cfg(feature = "dev-context-only-utils")] use qualifier_attr::qualifiers; +#[cfg(feature = "frozen-abi")] +use solana_frozen_abi_macro::{frozen_abi, AbiExample}; use { serde::ser::{Serialize, Serializer}, solana_program::{ @@ -54,6 +57,8 @@ mod account_serialize { solana_program::{clock::Epoch, pubkey::Pubkey}, serde::{ser::Serializer, Serialize}, }; + #[cfg(feature = "frozen-abi")] + use solana_frozen_abi_macro::{frozen_abi, AbiExample}; #[repr(C)] #[cfg_attr( feature = "frozen-abi", From ae2a63378105bc7bc0610ca23743aa1cfb7d5482 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Thu, 25 Jul 2024 21:53:17 +0400 Subject: [PATCH 07/16] fmt --- sdk/account/src/lib.rs | 6 +++--- sdk/src/account_utils.rs | 6 +----- sdk/src/client.rs | 33 ++++++++++++++++++--------------- sdk/src/rent_collector.rs | 26 ++++++++++++-------------- sdk/src/transaction_context.rs | 23 ++++++++++------------- 5 files changed, 44 insertions(+), 50 deletions(-) diff --git a/sdk/account/src/lib.rs b/sdk/account/src/lib.rs index 9466492e756daf..7522a8ee583773 100644 --- a/sdk/account/src/lib.rs +++ b/sdk/account/src/lib.rs @@ -52,13 +52,13 @@ pub struct Account { // mod because we need 'Account' below to have the name 'Account' to match expected serialization mod account_serialize { + #[cfg(feature = "frozen-abi")] + use solana_frozen_abi_macro::{frozen_abi, AbiExample}; use { crate::ReadableAccount, - solana_program::{clock::Epoch, pubkey::Pubkey}, serde::{ser::Serializer, Serialize}, + solana_program::{clock::Epoch, pubkey::Pubkey}, }; - #[cfg(feature = "frozen-abi")] - use solana_frozen_abi_macro::{frozen_abi, AbiExample}; #[repr(C)] #[cfg_attr( feature = "frozen-abi", diff --git a/sdk/src/account_utils.rs b/sdk/src/account_utils.rs index efe83ccc21f295..7338d64cc33498 100644 --- a/sdk/src/account_utils.rs +++ b/sdk/src/account_utils.rs @@ -64,11 +64,7 @@ where #[cfg(test)] mod tests { - use { - super::*, - crate::pubkey::Pubkey, - solana_account::AccountSharedData - }; + use {super::*, crate::pubkey::Pubkey, solana_account::AccountSharedData}; #[test] fn test_account_state() { diff --git a/sdk/src/client.rs b/sdk/src/client.rs index 1136d8103579df..f33f31d478f6af 100644 --- a/sdk/src/client.rs +++ b/sdk/src/client.rs @@ -9,21 +9,24 @@ #![cfg(feature = "full")] -use {crate::{ - clock::Slot, - commitment_config::CommitmentConfig, - epoch_info::EpochInfo, - hash::Hash, - instruction::Instruction, - message::Message, - pubkey::Pubkey, - signature::{Keypair, Signature}, - signer::Signer, - signers::Signers, - system_instruction, - transaction::{self, Transaction, VersionedTransaction}, - transport::Result, -}, solana_account::Account}; +use { + crate::{ + clock::Slot, + commitment_config::CommitmentConfig, + epoch_info::EpochInfo, + hash::Hash, + instruction::Instruction, + message::Message, + pubkey::Pubkey, + signature::{Keypair, Signature}, + signer::Signer, + signers::Signers, + system_instruction, + transaction::{self, Transaction, VersionedTransaction}, + transport::Result, + }, + solana_account::Account, +}; pub trait Client: SyncClient + AsyncClient { fn tpu_addr(&self) -> String; diff --git a/sdk/src/rent_collector.rs b/sdk/src/rent_collector.rs index dff3e7264ed7eb..4be46786a1de12 100644 --- a/sdk/src/rent_collector.rs +++ b/sdk/src/rent_collector.rs @@ -1,14 +1,17 @@ #![cfg(feature = "full")] //! calculate and collect rent from Accounts -use {solana_sdk::{ - clock::Epoch, - epoch_schedule::EpochSchedule, - genesis_config::GenesisConfig, - incinerator, - pubkey::Pubkey, - rent::{Rent, RentDue}, -}, solana_account::{AccountSharedData, ReadableAccount, WritableAccount}}; +use { + solana_account::{AccountSharedData, ReadableAccount, WritableAccount}, + solana_sdk::{ + clock::Epoch, + epoch_schedule::EpochSchedule, + genesis_config::GenesisConfig, + incinerator, + pubkey::Pubkey, + rent::{Rent, RentDue}, + }, +}; #[cfg_attr(feature = "frozen-abi", derive(AbiExample))] #[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] @@ -212,12 +215,7 @@ impl std::ops::AddAssign for CollectedInfo { #[cfg(test)] mod tests { - use { - super::*, - assert_matches::assert_matches, - solana_account::Account, - solana_sdk::sysvar, - }; + use {super::*, assert_matches::assert_matches, solana_account::Account, solana_sdk::sysvar}; fn default_rent_collector_clone_with_epoch(epoch: Epoch) -> RentCollector { RentCollector::default().clone_with_epoch(epoch) diff --git a/sdk/src/transaction_context.rs b/sdk/src/transaction_context.rs index 013c9c17ad2d13..95f65c3af55fe0 100644 --- a/sdk/src/transaction_context.rs +++ b/sdk/src/transaction_context.rs @@ -3,6 +3,16 @@ #[cfg(all(not(target_os = "solana"), feature = "full", debug_assertions))] use crate::signature::Signature; +use { + crate::{instruction::InstructionError, pubkey::Pubkey}, + solana_account::{AccountSharedData, ReadableAccount}, + std::{ + cell::{Ref, RefCell, RefMut}, + collections::HashSet, + pin::Pin, + rc::Rc, + }, +}; #[cfg(not(target_os = "solana"))] use { crate::{ @@ -15,19 +25,6 @@ use { solana_program::entrypoint::MAX_PERMITTED_DATA_INCREASE, std::mem::MaybeUninit, }; -use { - crate::{ - instruction::InstructionError, - pubkey::Pubkey, - }, - solana_account::{AccountSharedData, ReadableAccount}, - std::{ - cell::{Ref, RefCell, RefMut}, - collections::HashSet, - pin::Pin, - rc::Rc, - }, -}; /// Index of an account inside of the TransactionContext or an InstructionContext. pub type IndexOfAccount = u16; From 72a24f1fec42d700ce6a2205cdd6f29af96db6c7 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Thu, 25 Jul 2024 22:12:01 +0400 Subject: [PATCH 08/16] update digest --- sdk/src/genesis_config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/genesis_config.rs b/sdk/src/genesis_config.rs index 1032e8b7ed8a5f..73550a034df299 100644 --- a/sdk/src/genesis_config.rs +++ b/sdk/src/genesis_config.rs @@ -87,7 +87,7 @@ impl FromStr for ClusterType { #[cfg_attr( feature = "frozen-abi", derive(AbiExample), - frozen_abi(digest = "GDkrvVXezJYuGHcKSK19wvPBUMfKsifKQtoBxH1RpriL") + frozen_abi(digest = "7ZsjoPQ4zyASKfitx2QxRHib2ZUpqHhAiWyBoZ82eY4J") )] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] pub struct GenesisConfig { From 010017fc57248a2b34d9661607a57d1b6061ee5b Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Fri, 26 Jul 2024 03:47:39 +0400 Subject: [PATCH 09/16] update lock file --- programs/sbf/Cargo.lock | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index bb2021ea6c2477..7ecabb1c1b0097 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -4688,6 +4688,19 @@ dependencies = [ "sha-1", ] +[[package]] +name = "solana-account" +version = "2.1.0" +dependencies = [ + "bincode", + "qualifier_attr", + "rustc_version", + "serde", + "serde_bytes", + "serde_derive", + "solana-program", +] + [[package]] name = "solana-account-decoder" version = "2.1.0" @@ -6596,6 +6609,7 @@ dependencies = [ "sha2 0.10.8", "sha3", "siphasher", + "solana-account", "solana-bn254", "solana-decode-error", "solana-derivation-path", From ba2c75690b645309428d5e5120283e1e1db6f6ff Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Fri, 26 Jul 2024 12:12:10 +0400 Subject: [PATCH 10/16] fix doctests --- sdk/program/src/message/versions/v0/mod.rs | 2 +- sdk/program/src/system_instruction.rs | 2 +- sdk/program/src/sysvar/clock.rs | 2 +- sdk/program/src/sysvar/epoch_rewards.rs | 2 +- sdk/program/src/sysvar/epoch_schedule.rs | 2 +- sdk/program/src/sysvar/rent.rs | 2 +- sdk/program/src/sysvar/slot_hashes.rs | 2 +- sdk/program/src/sysvar/slot_history.rs | 2 +- sdk/program/src/sysvar/stake_history.rs | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sdk/program/src/message/versions/v0/mod.rs b/sdk/program/src/message/versions/v0/mod.rs index dfe6cbd350cbdc..9eaad5a9b39944 100644 --- a/sdk/program/src/message/versions/v0/mod.rs +++ b/sdk/program/src/message/versions/v0/mod.rs @@ -195,7 +195,7 @@ impl Message { /// # solana_sdk, /// # }; /// # use std::borrow::Cow; - /// # use solana_account::Account; + /// # use solana_sdk::account::Account; /// use anyhow::Result; /// use solana_rpc_client::rpc_client::RpcClient; /// use solana_program::address_lookup_table::{self, state::{AddressLookupTable, LookupTableMeta}}; diff --git a/sdk/program/src/system_instruction.rs b/sdk/program/src/system_instruction.rs index 257bc6bcc8c87d..bd0fcb0b37e0a6 100644 --- a/sdk/program/src/system_instruction.rs +++ b/sdk/program/src/system_instruction.rs @@ -1503,7 +1503,7 @@ pub fn create_nonce_account( /// system_instruction, /// transaction::Transaction, /// }; -/// # use solana_account::Account; +/// # use solana_sdk::account::Account; /// use std::path::Path; /// use anyhow::Result; /// # use anyhow::anyhow; diff --git a/sdk/program/src/sysvar/clock.rs b/sdk/program/src/sysvar/clock.rs index 8bec98b8a6e545..db87594001d578 100644 --- a/sdk/program/src/sysvar/clock.rs +++ b/sdk/program/src/sysvar/clock.rs @@ -100,7 +100,7 @@ //! ``` //! # use solana_program::example_mocks::solana_sdk; //! # use solana_program::example_mocks::solana_rpc_client; -//! # use solana_account::Account; +//! # use solana_sdk::account::Account; //! # use solana_rpc_client::rpc_client::RpcClient; //! # use solana_sdk::sysvar::clock::{self, Clock}; //! # use anyhow::Result; diff --git a/sdk/program/src/sysvar/epoch_rewards.rs b/sdk/program/src/sysvar/epoch_rewards.rs index 2fb91c8805fc6a..c8aa7bfbbc88e3 100755 --- a/sdk/program/src/sysvar/epoch_rewards.rs +++ b/sdk/program/src/sysvar/epoch_rewards.rs @@ -125,7 +125,7 @@ //! ``` //! # use solana_program::example_mocks::solana_sdk; //! # use solana_program::example_mocks::solana_rpc_client; -//! # use solana_account::Account; +//! # use solana_sdk::account::Account; //! # use solana_rpc_client::rpc_client::RpcClient; //! # use solana_sdk::sysvar::epoch_rewards::{self, EpochRewards}; //! # use anyhow::Result; diff --git a/sdk/program/src/sysvar/epoch_schedule.rs b/sdk/program/src/sysvar/epoch_schedule.rs index c03bfa9e20cbf6..0f3a0aa68896f8 100644 --- a/sdk/program/src/sysvar/epoch_schedule.rs +++ b/sdk/program/src/sysvar/epoch_schedule.rs @@ -100,7 +100,7 @@ //! ``` //! # use solana_program::example_mocks::solana_sdk; //! # use solana_program::example_mocks::solana_rpc_client; -//! # use solana_account::Account; +//! # use solana_sdk::account::Account; //! # use solana_rpc_client::rpc_client::RpcClient; //! # use solana_sdk::sysvar::epoch_schedule::{self, EpochSchedule}; //! # use anyhow::Result; diff --git a/sdk/program/src/sysvar/rent.rs b/sdk/program/src/sysvar/rent.rs index fa1588317b5b9b..4767838383b22f 100644 --- a/sdk/program/src/sysvar/rent.rs +++ b/sdk/program/src/sysvar/rent.rs @@ -101,7 +101,7 @@ //! ``` //! # use solana_program::example_mocks::solana_sdk; //! # use solana_program::example_mocks::solana_rpc_client; -//! # use solana_account::Account; +//! # use solana_sdk::account::Account; //! # use solana_rpc_client::rpc_client::RpcClient; //! # use solana_sdk::sysvar::rent::{self, Rent}; //! # use anyhow::Result; diff --git a/sdk/program/src/sysvar/slot_hashes.rs b/sdk/program/src/sysvar/slot_hashes.rs index 2e19ba4346e677..ab683c1802b441 100644 --- a/sdk/program/src/sysvar/slot_hashes.rs +++ b/sdk/program/src/sysvar/slot_hashes.rs @@ -19,7 +19,7 @@ //! ``` //! # use solana_program::example_mocks::solana_sdk; //! # use solana_program::example_mocks::solana_rpc_client; -//! # use solana_account::Account; +//! # use solana_sdk::account::Account; //! # use solana_rpc_client::rpc_client::RpcClient; //! # use solana_sdk::sysvar::slot_hashes::{self, SlotHashes}; //! # use anyhow::Result; diff --git a/sdk/program/src/sysvar/slot_history.rs b/sdk/program/src/sysvar/slot_history.rs index 442ef58fa940ce..668d4f194e2f8d 100644 --- a/sdk/program/src/sysvar/slot_history.rs +++ b/sdk/program/src/sysvar/slot_history.rs @@ -19,7 +19,7 @@ //! ``` //! # use solana_program::example_mocks::solana_sdk; //! # use solana_program::example_mocks::solana_rpc_client; -//! # use solana_account::Account; +//! # use solana_sdk::account::Account; //! # use solana_rpc_client::rpc_client::RpcClient; //! # use solana_sdk::sysvar::slot_history::{self, SlotHistory}; //! # use anyhow::Result; diff --git a/sdk/program/src/sysvar/stake_history.rs b/sdk/program/src/sysvar/stake_history.rs index e22842d692cb4a..0c41689b102f71 100644 --- a/sdk/program/src/sysvar/stake_history.rs +++ b/sdk/program/src/sysvar/stake_history.rs @@ -19,7 +19,7 @@ //! ``` //! # use solana_program::example_mocks::solana_sdk; //! # use solana_program::example_mocks::solana_rpc_client; -//! # use solana_account::Account; +//! # use solana_sdk::account::Account; //! # use solana_rpc_client::rpc_client::RpcClient; //! # use solana_sdk::sysvar::stake_history::{self, StakeHistory}; //! # use anyhow::Result; From cc17cb5c90742bcab280929463dd13a4ef1a0e8c Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Sat, 14 Sep 2024 14:55:46 +0400 Subject: [PATCH 11/16] update lock file --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 5a8e96af186a53..e7d8679bb4bc2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5631,7 +5631,7 @@ version = "2.1.0" dependencies = [ "bincode", "qualifier_attr", - "rustc_version 0.4.0", + "rustc_version 0.4.1", "serde", "serde_bytes", "serde_derive", From 48387da5d5abcf840fdabf7c083845172dc7a8c9 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Sat, 14 Sep 2024 15:41:07 +0400 Subject: [PATCH 12/16] remove unnecessary build script --- sdk/account/Cargo.toml | 3 --- sdk/account/build.rs | 22 ---------------------- sdk/account/src/lib.rs | 2 +- 3 files changed, 1 insertion(+), 26 deletions(-) delete mode 100644 sdk/account/build.rs diff --git a/sdk/account/Cargo.toml b/sdk/account/Cargo.toml index 77dbf349dbd4e2..e2c5c1d17cf29d 100644 --- a/sdk/account/Cargo.toml +++ b/sdk/account/Cargo.toml @@ -20,9 +20,6 @@ solana-frozen-abi-macro = { workspace = true, optional = true } solana-logger = { workspace = true, optional = true } solana-program = { workspace = true } -[build-dependencies] -rustc_version = { workspace = true } - [features] dev-context-only-utils = ["dep:qualifier_attr"] frozen-abi = [ diff --git a/sdk/account/build.rs b/sdk/account/build.rs deleted file mode 100644 index e17ca70cb4718b..00000000000000 --- a/sdk/account/build.rs +++ /dev/null @@ -1,22 +0,0 @@ -extern crate rustc_version; -use rustc_version::{version_meta, Channel}; - -fn main() { - // Copied and adapted from - // https://github.com/Kimundi/rustc-version-rs/blob/1d692a965f4e48a8cb72e82cda953107c0d22f47/README.md#example - // Licensed under Apache-2.0 + MIT - match version_meta().unwrap().channel { - Channel::Stable => { - println!("cargo:rustc-cfg=RUSTC_WITHOUT_SPECIALIZATION"); - } - Channel::Beta => { - println!("cargo:rustc-cfg=RUSTC_WITHOUT_SPECIALIZATION"); - } - Channel::Nightly => { - println!("cargo:rustc-cfg=RUSTC_WITH_SPECIALIZATION"); - } - Channel::Dev => { - println!("cargo:rustc-cfg=RUSTC_WITH_SPECIALIZATION"); - } - } -} diff --git a/sdk/account/src/lib.rs b/sdk/account/src/lib.rs index 7522a8ee583773..42adbe08767fb7 100644 --- a/sdk/account/src/lib.rs +++ b/sdk/account/src/lib.rs @@ -1,4 +1,4 @@ -#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(min_specialization))] +#![cfg_attr(feature = "frozen-abi", feature(min_specialization))] //! The Solana [`Account`] type. #[cfg(feature = "dev-context-only-utils")] From 0f1caf1f446ac2a048b71de286769ee5903b002a Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Tue, 24 Sep 2024 20:25:19 +0400 Subject: [PATCH 13/16] update lock files --- Cargo.lock | 1 - programs/sbf/Cargo.lock | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e7d8679bb4bc2a..8fb8c59968266e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5631,7 +5631,6 @@ version = "2.1.0" dependencies = [ "bincode", "qualifier_attr", - "rustc_version 0.4.1", "serde", "serde_bytes", "serde_derive", diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 7ecabb1c1b0097..e88e06245b7c41 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -4694,7 +4694,6 @@ version = "2.1.0" dependencies = [ "bincode", "qualifier_attr", - "rustc_version", "serde", "serde_bytes", "serde_derive", From de2e65cac3512afce8f9512321c93d6a4c9d3bff Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Sun, 29 Sep 2024 00:06:34 +0400 Subject: [PATCH 14/16] sort table --- sdk/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index de82f1352eed27..85ae6b890707e1 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -40,8 +40,8 @@ frozen-abi = [ "dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "solana-feature-set/frozen-abi", - "solana-program/frozen-abi", "solana-account/frozen-abi", + "solana-program/frozen-abi", "solana-short-vec/frozen-abi", "solana-signature/frozen-abi" ] From cb19413290c42f4023623d1fe9fb257b14a08d68 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Thu, 3 Oct 2024 17:11:07 +0400 Subject: [PATCH 15/16] make serde and bincode optional in the new crate --- Cargo.lock | 1 + sdk/Cargo.toml | 2 +- sdk/account/Cargo.toml | 17 +++++++++----- sdk/account/src/lib.rs | 53 ++++++++++++++++++++++++++++++++++++------ 4 files changed, 59 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8fb8c59968266e..cb555b8e6a64ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5634,6 +5634,7 @@ dependencies = [ "serde", "serde_bytes", "serde_derive", + "solana-account", "solana-frozen-abi", "solana-frozen-abi-macro", "solana-logger", diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 85ae6b890707e1..e0e7f132ffec20 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -84,7 +84,7 @@ serde_with = { workspace = true, features = ["macros"] } sha2 = { workspace = true } sha3 = { workspace = true, optional = true } siphasher = { workspace = true } -solana-account = { workspace = true } +solana-account = { workspace = true, features = ["bincode"] } solana-bn254 = { workspace = true } solana-decode-error = { workspace = true } solana-derivation-path = { workspace = true } diff --git a/sdk/account/Cargo.toml b/sdk/account/Cargo.toml index e2c5c1d17cf29d..33d210778f08e5 100644 --- a/sdk/account/Cargo.toml +++ b/sdk/account/Cargo.toml @@ -10,24 +10,29 @@ license = { workspace = true } edition = { workspace = true } [dependencies] -bincode = { workspace = true } +bincode = { workspace = true, optional = true } qualifier_attr = { workspace = true, optional = true } -serde = { workspace = true } -serde_bytes = { workspace = true } -serde_derive = { workspace = true } +serde = { workspace = true, optional = true } +serde_bytes = { workspace = true, optional = true } +serde_derive = { workspace = true, optional = true } solana-frozen-abi = { workspace = true, optional = true } solana-frozen-abi-macro = { workspace = true, optional = true } solana-logger = { workspace = true, optional = true } solana-program = { workspace = true } +[dev-dependencies] +solana-account = { path = ".", features = ["dev-context-only-utils"] } + [features] -dev-context-only-utils = ["dep:qualifier_attr"] +bincode = ["dep:bincode", "serde"] +dev-context-only-utils = ["bincode", "dep:qualifier_attr"] frozen-abi = [ "dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "dep:solana-logger", - "solana-program/frozen-abi" + "solana-program/frozen-abi", ] +serde = ["dep:serde", "dep:serde_bytes", "dep:serde_derive"] [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/sdk/account/src/lib.rs b/sdk/account/src/lib.rs index 42adbe08767fb7..c2bcbbfd02c916 100644 --- a/sdk/account/src/lib.rs +++ b/sdk/account/src/lib.rs @@ -3,10 +3,13 @@ #[cfg(feature = "dev-context-only-utils")] use qualifier_attr::qualifiers; +#[cfg(feature = "serde")] +use serde::ser::{Serialize, Serializer}; #[cfg(feature = "frozen-abi")] use solana_frozen_abi_macro::{frozen_abi, AbiExample}; +#[cfg(feature = "bincode")] +use solana_program::sysvar::Sysvar; use { - serde::ser::{Serialize, Serializer}, solana_program::{ account_info::AccountInfo, bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, @@ -15,7 +18,6 @@ use { lamports::LamportsError, loader_v4, pubkey::Pubkey, - sysvar::Sysvar, }, std::{ cell::{Ref, RefCell}, @@ -34,13 +36,17 @@ use { derive(AbiExample), frozen_abi(digest = "2SUJNHbXMPWrsSXmDTFc4VHx2XQ85fT5Leabefh5Nwe7") )] -#[derive(serde_derive::Deserialize, PartialEq, Eq, Clone, Default)] -#[serde(rename_all = "camelCase")] +#[cfg_attr( + feature = "serde", + derive(serde_derive::Deserialize), + serde(rename_all = "camelCase") +)] +#[derive(PartialEq, Eq, Clone, Default)] pub struct Account { /// lamports in the account pub lamports: u64, /// data held in this account - #[serde(with = "serde_bytes")] + #[cfg_attr(feature = "serde", serde(with = "serde_bytes"))] pub data: Vec, /// the program that owns this account. If executable, the program that loads this account. pub owner: Pubkey, @@ -51,6 +57,7 @@ pub struct Account { } // mod because we need 'Account' below to have the name 'Account' to match expected serialization +#[cfg(feature = "serde")] mod account_serialize { #[cfg(feature = "frozen-abi")] use solana_frozen_abi_macro::{frozen_abi, AbiExample}; @@ -96,6 +103,7 @@ mod account_serialize { } } +#[cfg(feature = "serde")] impl Serialize for Account { fn serialize(&self, serializer: S) -> Result where @@ -105,6 +113,7 @@ impl Serialize for Account { } } +#[cfg(feature = "serde")] impl Serialize for AccountSharedData { fn serialize(&self, serializer: S) -> Result where @@ -118,8 +127,12 @@ impl Serialize for AccountSharedData { /// This will be the in-memory representation of the 'Account' struct data. /// The existing 'Account' structure cannot easily change due to downstream projects. #[cfg_attr(feature = "frozen-abi", derive(AbiExample))] -#[derive(PartialEq, Eq, Clone, Default, serde_derive::Deserialize)] -#[serde(from = "Account")] +#[cfg_attr( + feature = "serde", + derive(serde_derive::Deserialize), + serde(from = "Account") +)] +#[derive(PartialEq, Eq, Clone, Default)] pub struct AccountSharedData { /// lamports in the account lamports: u64, @@ -440,6 +453,7 @@ fn shared_new_ref( Rc::new(RefCell::new(shared_new::(lamports, space, owner))) } +#[cfg(feature = "bincode")] fn shared_new_data( lamports: u64, state: &T, @@ -454,6 +468,8 @@ fn shared_new_data( Epoch::default(), )) } + +#[cfg(feature = "bincode")] fn shared_new_ref_data( lamports: u64, state: &T, @@ -464,6 +480,7 @@ fn shared_new_ref_data( )?)) } +#[cfg(feature = "bincode")] fn shared_new_data_with_space( lamports: u64, state: &T, @@ -476,6 +493,8 @@ fn shared_new_data_with_space( Ok(account) } + +#[cfg(feature = "bincode")] fn shared_new_ref_data_with_space( lamports: u64, state: &T, @@ -487,12 +506,14 @@ fn shared_new_ref_data_with_space( )?)) } +#[cfg(feature = "bincode")] fn shared_deserialize_data( account: &U, ) -> Result { bincode::deserialize(account.data()) } +#[cfg(feature = "bincode")] fn shared_serialize_data( account: &mut U, state: &T, @@ -510,6 +531,7 @@ impl Account { pub fn new_ref(lamports: u64, space: usize, owner: &Pubkey) -> Rc> { shared_new_ref(lamports, space, owner) } + #[cfg(feature = "bincode")] pub fn new_data( lamports: u64, state: &T, @@ -517,6 +539,7 @@ impl Account { ) -> Result { shared_new_data(lamports, state, owner) } + #[cfg(feature = "bincode")] pub fn new_ref_data( lamports: u64, state: &T, @@ -524,6 +547,7 @@ impl Account { ) -> Result, bincode::Error> { shared_new_ref_data(lamports, state, owner) } + #[cfg(feature = "bincode")] pub fn new_data_with_space( lamports: u64, state: &T, @@ -532,6 +556,7 @@ impl Account { ) -> Result { shared_new_data_with_space(lamports, state, space, owner) } + #[cfg(feature = "bincode")] pub fn new_ref_data_with_space( lamports: u64, state: &T, @@ -543,9 +568,11 @@ impl Account { pub fn new_rent_epoch(lamports: u64, space: usize, owner: &Pubkey, rent_epoch: Epoch) -> Self { shared_new_rent_epoch(lamports, space, owner, rent_epoch) } + #[cfg(feature = "bincode")] pub fn deserialize_data(&self) -> Result { shared_deserialize_data(self) } + #[cfg(feature = "bincode")] pub fn serialize_data(&mut self, state: &T) -> Result<(), bincode::Error> { shared_serialize_data(self, state) } @@ -636,6 +663,7 @@ impl AccountSharedData { pub fn new_ref(lamports: u64, space: usize, owner: &Pubkey) -> Rc> { shared_new_ref(lamports, space, owner) } + #[cfg(feature = "bincode")] pub fn new_data( lamports: u64, state: &T, @@ -643,6 +671,7 @@ impl AccountSharedData { ) -> Result { shared_new_data(lamports, state, owner) } + #[cfg(feature = "bincode")] pub fn new_ref_data( lamports: u64, state: &T, @@ -650,6 +679,7 @@ impl AccountSharedData { ) -> Result, bincode::Error> { shared_new_ref_data(lamports, state, owner) } + #[cfg(feature = "bincode")] pub fn new_data_with_space( lamports: u64, state: &T, @@ -658,6 +688,7 @@ impl AccountSharedData { ) -> Result { shared_new_data_with_space(lamports, state, space, owner) } + #[cfg(feature = "bincode")] pub fn new_ref_data_with_space( lamports: u64, state: &T, @@ -669,9 +700,11 @@ impl AccountSharedData { pub fn new_rent_epoch(lamports: u64, space: usize, owner: &Pubkey, rent_epoch: Epoch) -> Self { shared_new_rent_epoch(lamports, space, owner, rent_epoch) } + #[cfg(feature = "bincode")] pub fn deserialize_data(&self) -> Result { shared_deserialize_data(self) } + #[cfg(feature = "bincode")] pub fn serialize_data(&mut self, state: &T) -> Result<(), bincode::Error> { shared_serialize_data(self, state) } @@ -680,6 +713,7 @@ impl AccountSharedData { pub type InheritableAccountFields = (u64, Epoch); pub const DUMMY_INHERITABLE_ACCOUNT_FIELDS: InheritableAccountFields = (1, INITIAL_RENT_EPOCH); +#[cfg(feature = "bincode")] pub fn create_account_with_fields( sysvar: &S, (lamports, rent_epoch): InheritableAccountFields, @@ -691,10 +725,12 @@ pub fn create_account_with_fields( account } +#[cfg(feature = "bincode")] pub fn create_account_for_test(sysvar: &S) -> Account { create_account_with_fields(sysvar, DUMMY_INHERITABLE_ACCOUNT_FIELDS) } +#[cfg(feature = "bincode")] /// Create an `Account` from a `Sysvar`. pub fn create_account_shared_data_with_fields( sysvar: &S, @@ -703,6 +739,7 @@ pub fn create_account_shared_data_with_fields( AccountSharedData::from(create_account_with_fields(sysvar, fields)) } +#[cfg(feature = "bincode")] pub fn create_account_shared_data_for_test(sysvar: &S) -> AccountSharedData { AccountSharedData::from(create_account_with_fields( sysvar, @@ -710,11 +747,13 @@ pub fn create_account_shared_data_for_test(sysvar: &S) -> AccountShar )) } +#[cfg(feature = "bincode")] /// Create a `Sysvar` from an `Account`'s data. pub fn from_account(account: &T) -> Option { bincode::deserialize(account.data()).ok() } +#[cfg(feature = "bincode")] /// Serialize a `Sysvar` into an `Account`'s data. pub fn to_account(sysvar: &S, account: &mut T) -> Option<()> { bincode::serialize_into(account.data_as_mut_slice(), sysvar).ok() From 7880055d05d8aac89754c686e6680f45786a2b24 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Mon, 7 Oct 2024 11:59:00 +0400 Subject: [PATCH 16/16] update digest --- sdk/src/genesis_config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/genesis_config.rs b/sdk/src/genesis_config.rs index 73550a034df299..24208a76363dbf 100644 --- a/sdk/src/genesis_config.rs +++ b/sdk/src/genesis_config.rs @@ -87,7 +87,7 @@ impl FromStr for ClusterType { #[cfg_attr( feature = "frozen-abi", derive(AbiExample), - frozen_abi(digest = "7ZsjoPQ4zyASKfitx2QxRHib2ZUpqHhAiWyBoZ82eY4J") + frozen_abi(digest = "2eGYc5mpKqDsS8sZfNS4mVq4qPptXYa9hSid2Hpv4DkQ") )] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] pub struct GenesisConfig {