From 0f38e039724e6376d702d42930db2cb5cf12b692 Mon Sep 17 00:00:00 2001 From: Kevin Heavey Date: Mon, 7 Oct 2024 10:03:18 +0400 Subject: [PATCH] Extract solana-rent crate (#3022) * extract rent crate * add #![no_std] to rent crate * missing dev deps * update digest * update digest --- Cargo.lock | 14 +++++++++ Cargo.toml | 2 ++ programs/sbf/Cargo.lock | 10 +++++++ runtime/src/bank/serde_snapshot.rs | 2 +- sdk/program/Cargo.toml | 2 ++ sdk/program/src/lib.rs | 3 +- sdk/rent/Cargo.toml | 31 ++++++++++++++++++++ sdk/{program/src/rent.rs => rent/src/lib.rs} | 22 ++++++++++++-- sdk/src/genesis_config.rs | 2 +- 9 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 sdk/rent/Cargo.toml rename sdk/{program/src/rent.rs => rent/src/lib.rs} (92%) diff --git a/Cargo.lock b/Cargo.lock index 982eb8dff236b4..40a271eb1a6c78 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7250,6 +7250,7 @@ dependencies = [ "solana-program-option", "solana-program-pack", "solana-pubkey", + "solana-rent", "solana-sanitize", "solana-sdk-macro", "solana-secp256k1-recover", @@ -7476,6 +7477,19 @@ dependencies = [ "uriparse", ] +[[package]] +name = "solana-rent" +version = "2.1.0" +dependencies = [ + "serde", + "serde_derive", + "solana-clock", + "solana-frozen-abi", + "solana-frozen-abi-macro", + "solana-sdk-macro", + "static_assertions", +] + [[package]] name = "solana-rpc" version = "2.1.0" diff --git a/Cargo.toml b/Cargo.toml index c1cfbfc2f8af82..a61b7aacad85fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -121,6 +121,7 @@ members = [ "sdk/program-option", "sdk/program-pack", "sdk/pubkey", + "sdk/rent", "sdk/serde-varint", "sdk/serialize-utils", "sdk/sha256-hasher", @@ -440,6 +441,7 @@ solana-pubsub-client = { path = "pubsub-client", version = "=2.1.0" } solana-quic-client = { path = "quic-client", version = "=2.1.0" } solana-rayon-threadlimit = { path = "rayon-threadlimit", version = "=2.1.0" } solana-remote-wallet = { path = "remote-wallet", version = "=2.1.0", default-features = false } +solana-rent = { path = "sdk/rent", version = "=2.1.0", default-features = false } solana-sanitize = { path = "sanitize", version = "=2.1.0" } solana-serde-varint = { path = "sdk/serde-varint", version = "=2.1.0" } solana-serialize-utils = { path = "sdk/serialize-utils", version = "=2.1.0" } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 69c5ae6de9e2f0..bb2021ea6c2477 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5652,6 +5652,7 @@ dependencies = [ "solana-program-option", "solana-program-pack", "solana-pubkey", + "solana-rent", "solana-sanitize", "solana-sdk-macro", "solana-secp256k1-recover", @@ -5854,6 +5855,15 @@ dependencies = [ "uriparse", ] +[[package]] +name = "solana-rent" +version = "2.1.0" +dependencies = [ + "serde", + "serde_derive", + "solana-sdk-macro", +] + [[package]] name = "solana-rpc" version = "2.1.0" diff --git a/runtime/src/bank/serde_snapshot.rs b/runtime/src/bank/serde_snapshot.rs index d0a422e1ad95d0..1235afd319062b 100644 --- a/runtime/src/bank/serde_snapshot.rs +++ b/runtime/src/bank/serde_snapshot.rs @@ -535,7 +535,7 @@ mod tests { #[cfg_attr( feature = "frozen-abi", derive(AbiExample), - frozen_abi(digest = "6d4H7gw1hSrspdTew8dAXZ5dZT1mwFc6VZdXnkuggJ8E") + frozen_abi(digest = "8hwm4YsQXJWGZdp762SkJnDok29LXKwFtmW9oQ2KSzrN") )] #[derive(Serialize)] pub struct BankAbiTestWrapper { diff --git a/sdk/program/Cargo.toml b/sdk/program/Cargo.toml index 2919a7bb5689ad..f7bc8ba8aeaa96 100644 --- a/sdk/program/Cargo.toml +++ b/sdk/program/Cargo.toml @@ -53,6 +53,7 @@ solana-program-memory = { workspace = true } solana-program-option = { workspace = true } solana-program-pack = { workspace = true } solana-pubkey = { workspace = true, features = ["bytemuck", "curve25519", "serde", "std"] } +solana-rent = { workspace = true, features = ["serde"] } solana-sanitize = { workspace = true } solana-sdk-macro = { workspace = true } solana-secp256k1-recover = { workspace = true } @@ -128,6 +129,7 @@ frozen-abi = [ "solana-hash/frozen-abi", "solana-instruction/frozen-abi", "solana-pubkey/frozen-abi", + "solana-rent/frozen-abi", "solana-short-vec/frozen-abi" ] diff --git a/sdk/program/src/lib.rs b/sdk/program/src/lib.rs index b853cd07d93be3..de02676c1f7c28 100644 --- a/sdk/program/src/lib.rs +++ b/sdk/program/src/lib.rs @@ -508,7 +508,6 @@ pub mod program; pub mod program_error; pub mod program_stubs; pub mod program_utils; -pub mod rent; pub mod secp256k1_program; pub mod slot_hashes; pub mod slot_history; @@ -542,7 +541,7 @@ pub use { solana_account_info::{self as account_info, debug_account_data}, solana_clock as clock, solana_msg::msg, - solana_program_option as program_option, solana_pubkey as pubkey, + solana_program_option as program_option, solana_pubkey as pubkey, solana_rent as rent, }; /// The [config native program][np]. diff --git a/sdk/rent/Cargo.toml b/sdk/rent/Cargo.toml new file mode 100644 index 00000000000000..d3e978bdcdc084 --- /dev/null +++ b/sdk/rent/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "solana-rent" +description = "Configuration for Solana network rent." +documentation = "https://docs.rs/solana-rent" +version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[dependencies] +serde = { 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-sdk-macro = { workspace = true } + +[dev-dependencies] +solana-clock = { workspace = true } +static_assertions = { workspace = true } + +[features] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] +serde = ["dep:serde", "dep:serde_derive"] + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[lints] +workspace = true diff --git a/sdk/program/src/rent.rs b/sdk/rent/src/lib.rs similarity index 92% rename from sdk/program/src/rent.rs rename to sdk/rent/src/lib.rs index 47308066d927cc..7b50e8953b288f 100644 --- a/sdk/program/src/rent.rs +++ b/sdk/rent/src/lib.rs @@ -3,13 +3,29 @@ //! [rent]: https://docs.solanalabs.com/implemented-proposals/rent #![allow(clippy::arithmetic_side_effects)] +#![no_std] +#![cfg_attr(feature = "frozen-abi", feature(min_specialization))] +#[cfg(feature = "frozen-abi")] +extern crate std; -use {solana_clock::DEFAULT_SLOTS_PER_EPOCH, solana_sdk_macro::CloneZeroed}; +use solana_sdk_macro::CloneZeroed; + +// inlined to avoid solana_clock dep +const DEFAULT_SLOTS_PER_EPOCH: u64 = 432_000; +#[cfg(test)] +static_assertions::const_assert_eq!( + DEFAULT_SLOTS_PER_EPOCH, + solana_clock::DEFAULT_SLOTS_PER_EPOCH +); /// Configuration of network rent. #[repr(C)] -#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] -#[derive(Serialize, Deserialize, PartialEq, CloneZeroed, Debug)] +#[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))] +#[cfg_attr( + feature = "serde", + derive(serde_derive::Deserialize, serde_derive::Serialize) +)] +#[derive(PartialEq, CloneZeroed, Debug)] pub struct Rent { /// Rental rate in lamports/byte-year. pub lamports_per_byte_year: u64, diff --git a/sdk/src/genesis_config.rs b/sdk/src/genesis_config.rs index ba58d5bd8811f8..8e3f89f254830e 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 = "z6vuQfrTaknTiRs1giPFzG1Jcw8eReidFTNDTmaX6GN") + frozen_abi(digest = "GDkrvVXezJYuGHcKSK19wvPBUMfKsifKQtoBxH1RpriL") )] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] pub struct GenesisConfig {