From 0255e5c3d403e617fff0d27973332825c782dc83 Mon Sep 17 00:00:00 2001 From: Joe Caulfield Date: Thu, 5 Dec 2024 12:31:22 +0900 Subject: [PATCH 01/12] sdk: evict genesis_config --- Cargo.lock | 32 +++++++++++++ Cargo.toml | 2 + programs/sbf/Cargo.lock | 30 ++++++++++++ sdk/Cargo.toml | 5 ++ sdk/genesis-config/Cargo.toml | 47 ++++++++++++++++++ .../src/lib.rs} | 48 ++++++++++--------- sdk/src/lib.rs | 6 ++- svm/examples/Cargo.lock | 30 ++++++++++++ 8 files changed, 175 insertions(+), 25 deletions(-) create mode 100644 sdk/genesis-config/Cargo.toml rename sdk/{src/genesis_config.rs => genesis-config/src/lib.rs} (91%) diff --git a/Cargo.lock b/Cargo.lock index f1b6412e1a021f..bd8b41000a82a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7386,6 +7386,37 @@ dependencies = [ "tempfile", ] +[[package]] +name = "solana-genesis-config" +version = "2.2.0" +dependencies = [ + "bincode", + "chrono", + "memmap2", + "serde", + "serde_derive", + "solana-account", + "solana-clock", + "solana-cluster-type", + "solana-epoch-schedule", + "solana-fee-calculator", + "solana-frozen-abi", + "solana-frozen-abi-macro", + "solana-hash", + "solana-inflation", + "solana-keypair", + "solana-logger", + "solana-native-token", + "solana-poh-config", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-sha256-hasher", + "solana-shred-version", + "solana-signer", + "solana-time-utils", +] + [[package]] name = "solana-genesis-utils" version = "2.2.0" @@ -8986,6 +9017,7 @@ dependencies = [ "solana-fee-structure", "solana-frozen-abi", "solana-frozen-abi-macro", + "solana-genesis-config", "solana-hard-forks", "solana-inflation", "solana-instruction", diff --git a/Cargo.toml b/Cargo.toml index 7e1fa38779f382..07ed6fd2195a5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -136,6 +136,7 @@ members = [ "sdk/frozen-abi", "sdk/frozen-abi/macro", "sdk/gen-headers", + "sdk/genesis-config", "sdk/hard-forks", "sdk/hash", "sdk/inflation", @@ -499,6 +500,7 @@ solana-frozen-abi-macro = { path = "sdk/frozen-abi/macro", version = "=2.2.0" } solana-tps-client = { path = "tps-client", version = "=2.2.0" } solana-file-download = { path = "sdk/file-download", version = "=2.2.0" } solana-genesis = { path = "genesis", version = "=2.2.0" } +solana-genesis-config = { path = "sdk/genesis-config", version = "=2.2.0" } solana-genesis-utils = { path = "genesis-utils", version = "=2.2.0" } agave-geyser-plugin-interface = { path = "geyser-plugin-interface", version = "=2.2.0" } solana-geyser-plugin-manager = { path = "geyser-plugin-manager", version = "=2.2.0" } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 316adbe52bce1c..f4e00d9f45e6f8 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5902,6 +5902,35 @@ dependencies = [ "reqwest", ] +[[package]] +name = "solana-genesis-config" +version = "2.2.0" +dependencies = [ + "bincode", + "chrono", + "memmap2", + "serde", + "serde_derive", + "solana-account", + "solana-clock", + "solana-cluster-type", + "solana-epoch-schedule", + "solana-fee-calculator", + "solana-hash", + "solana-inflation", + "solana-keypair", + "solana-logger", + "solana-native-token", + "solana-poh-config", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-sha256-hasher", + "solana-shred-version", + "solana-signer", + "solana-time-utils", +] + [[package]] name = "solana-genesis-utils" version = "2.2.0" @@ -7607,6 +7636,7 @@ dependencies = [ "solana-epoch-rewards-hasher", "solana-feature-set", "solana-fee-structure", + "solana-genesis-config", "solana-hard-forks", "solana-inflation", "solana-instruction", diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index b15f1b66ad93c2..eb6f2883284eae 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -39,6 +39,7 @@ full = [ "dep:solana-cluster-type", "dep:solana-ed25519-program", "dep:solana-compute-budget-interface", + "dep:solana-genesis-config", "dep:solana-hard-forks", "dep:solana-keypair", "dep:solana-offchain-message", @@ -76,6 +77,7 @@ frozen-abi = [ "solana-fee-structure/frozen-abi", "solana-account/frozen-abi", "solana-cluster-type/frozen-abi", + "solana-genesis-config/frozen-abi", "solana-hard-forks/frozen-abi", "solana-inflation/frozen-abi", "solana-poh-config/frozen-abi", @@ -143,6 +145,9 @@ solana-frozen-abi = { workspace = true, optional = true, features = [ solana-frozen-abi-macro = { workspace = true, optional = true, features = [ "frozen-abi", ] } +solana-genesis-config = { workspace = true, features = [ + "serde", +], optional = true } solana-hard-forks = { workspace = true, features = [ "serde", ], optional = true } diff --git a/sdk/genesis-config/Cargo.toml b/sdk/genesis-config/Cargo.toml new file mode 100644 index 00000000000000..dd3aef928cc7b7 --- /dev/null +++ b/sdk/genesis-config/Cargo.toml @@ -0,0 +1,47 @@ +[package] +name = "solana-genesis-config" +description = "The chain's genesis config." +documentation = "https://docs.rs/solana-genesis-config" +version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[dependencies] +bincode = { workspace = true } +chrono = { workspace = true } +memmap2 = { workspace = true } +serde = { workspace = true, optional = true } +serde_derive = { workspace = true, optional = true } +solana-account = { workspace = true } +solana-clock = { workspace = true } +solana-cluster-type = { workspace = true } +solana-epoch-schedule = { workspace = true } +solana-fee-calculator = { workspace = true } +solana-frozen-abi = { workspace = true, optional = true } +solana-frozen-abi-macro = { workspace = true, optional = true } +solana-hash = { workspace = true } +solana-inflation = { workspace = true } +solana-keypair = { workspace = true } +solana-logger = { workspace = true } +solana-native-token = { workspace = true } +solana-poh-config = { workspace = true } +solana-pubkey = { workspace = true } +solana-rent = { workspace = true } +solana-sdk-ids = { workspace = true } +solana-sha256-hasher = { workspace = true } +solana-shred-version = { workspace = true } +solana-signer = { workspace = true } +solana-time-utils = { 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/src/genesis_config.rs b/sdk/genesis-config/src/lib.rs similarity index 91% rename from sdk/src/genesis_config.rs rename to sdk/genesis-config/src/lib.rs index af86e8e3005659..ad87b154d96c1b 100644 --- a/sdk/src/genesis_config.rs +++ b/sdk/genesis-config/src/lib.rs @@ -1,32 +1,34 @@ //! The chain's genesis config. -#![cfg(feature = "full")] +#![cfg_attr(feature = "frozen-abi", feature(min_specialization))] #[deprecated( since = "2.2.0", note = "Use `solana_cluster_type::ClusterType` instead." )] pub use solana_cluster_type::ClusterType; +#[cfg(feature = "frozen-abi")] +use solana_frozen_abi_macro::{frozen_abi, AbiExample}; use { - crate::{ - clock::{UnixTimestamp, DEFAULT_TICKS_PER_SLOT}, - epoch_schedule::EpochSchedule, - fee_calculator::FeeRateGovernor, - hash::{hash, Hash}, - inflation::Inflation, - poh_config::PohConfig, - pubkey::Pubkey, - rent::Rent, - shred_version::compute_shred_version, - signature::{Keypair, Signer}, - system_program, - timing::years_as_slots, - }, bincode::{deserialize, serialize}, chrono::{TimeZone, Utc}, memmap2::Mmap, solana_account::{Account, AccountSharedData}, + solana_clock::{UnixTimestamp, DEFAULT_TICKS_PER_SLOT}, + solana_epoch_schedule::EpochSchedule, + solana_fee_calculator::FeeRateGovernor, + solana_hash::Hash, + solana_inflation::Inflation, + solana_keypair::Keypair, solana_native_token::lamports_to_sol, + solana_poh_config::PohConfig, + solana_pubkey::Pubkey, + solana_rent::Rent, + solana_sdk_ids::system_program, + solana_sha256_hasher::hash, + solana_shred_version::compute_shred_version, + solana_signer::Signer, + solana_time_utils::years_as_slots, std::{ collections::BTreeMap, fmt, @@ -49,7 +51,11 @@ pub const UNUSED_DEFAULT: u64 = 1024; derive(AbiExample), frozen_abi(digest = "D9VFRSj4fodCuKFC9omQY2zY2Uw8wo6SzJFLeMJaVigm") )] -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[cfg_attr( + feature = "serde", + derive(serde_derive::Deserialize, serde_derive::Serialize) +)] +#[derive(Clone, Debug, PartialEq)] pub struct GenesisConfig { /// when the network (bootstrap validator) was started relative to the UNIX Epoch pub creation_time: UnixTimestamp, @@ -275,11 +281,7 @@ impl fmt::Display for GenesisConfig { #[cfg(test)] mod tests { - use { - super::*, - crate::signature::{Keypair, Signer}, - std::path::PathBuf, - }; + use {super::*, solana_signer::Signer, std::path::PathBuf}; fn make_tmp_path(name: &str) -> PathBuf { let out_dir = std::env::var("FARF_DIR").unwrap_or_else(|_| "farf".to_string()); @@ -310,10 +312,10 @@ mod tests { AccountSharedData::new(10_000, 0, &Pubkey::default()), ); config.add_account( - solana_sdk::pubkey::new_rand(), + solana_pubkey::new_rand(), AccountSharedData::new(1, 0, &Pubkey::default()), ); - config.add_native_instruction_processor("hi".to_string(), solana_sdk::pubkey::new_rand()); + config.add_native_instruction_processor("hi".to_string(), solana_pubkey::new_rand()); assert_eq!(config.accounts.len(), 2); assert!(config diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 2f4c09d6460133..96aeeb91dd1fa2 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -66,9 +66,11 @@ pub mod entrypoint; pub mod entrypoint_deprecated; pub mod example_mocks; pub mod feature; -pub mod genesis_config; #[cfg(feature = "full")] -#[deprecated(since = "2.2.0", note = "Use `solana-hard-forks` crate instead")] +#[deprecated(since = "2.2.0", note = "Use `solana_genesis_config` crate instead")] +pub use solana_genesis_config as genesis_config; +#[cfg(feature = "full")] +#[deprecated(since = "2.2.0", note = "Use `solana_hard_forks` crate instead")] pub use solana_hard_forks as hard_forks; pub mod hash; pub mod log; diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index ec51f4a2312caa..c5f2f207c5fe16 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -5743,6 +5743,35 @@ dependencies = [ "solana-native-token", ] +[[package]] +name = "solana-genesis-config" +version = "2.2.0" +dependencies = [ + "bincode", + "chrono", + "memmap2", + "serde", + "serde_derive", + "solana-account", + "solana-clock", + "solana-cluster-type", + "solana-epoch-schedule", + "solana-fee-calculator", + "solana-hash", + "solana-inflation", + "solana-keypair", + "solana-logger", + "solana-native-token", + "solana-poh-config", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-sha256-hasher", + "solana-shred-version", + "solana-signer", + "solana-time-utils", +] + [[package]] name = "solana-geyser-plugin-manager" version = "2.2.0" @@ -6936,6 +6965,7 @@ dependencies = [ "solana-epoch-rewards-hasher", "solana-feature-set", "solana-fee-structure", + "solana-genesis-config", "solana-hard-forks", "solana-inflation", "solana-instruction", From 218bb59df0ef54bec16eb89cd3ce924544f2dacc Mon Sep 17 00:00:00 2001 From: Joe C Date: Tue, 7 Jan 2025 14:28:01 +0800 Subject: [PATCH 02/12] Update sdk/src/lib.rs Co-authored-by: Jon C --- sdk/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 96aeeb91dd1fa2..cd3b1cc5cad60f 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -67,7 +67,7 @@ pub mod entrypoint_deprecated; pub mod example_mocks; pub mod feature; #[cfg(feature = "full")] -#[deprecated(since = "2.2.0", note = "Use `solana_genesis_config` crate instead")] +#[deprecated(since = "2.2.0", note = "Use `solana-genesis-config` crate instead")] pub use solana_genesis_config as genesis_config; #[cfg(feature = "full")] #[deprecated(since = "2.2.0", note = "Use `solana_hard_forks` crate instead")] From 04cc62d52b6b4e24a20169529bd4e9898ff51175 Mon Sep 17 00:00:00 2001 From: Joe C Date: Tue, 7 Jan 2025 14:28:24 +0800 Subject: [PATCH 03/12] Update sdk/src/lib.rs Co-authored-by: Jon C --- sdk/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index cd3b1cc5cad60f..3510f81bacd477 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -70,7 +70,7 @@ pub mod feature; #[deprecated(since = "2.2.0", note = "Use `solana-genesis-config` crate instead")] pub use solana_genesis_config as genesis_config; #[cfg(feature = "full")] -#[deprecated(since = "2.2.0", note = "Use `solana_hard_forks` crate instead")] +#[deprecated(since = "2.2.0", note = "Use `solana-hard-forks` crate instead")] pub use solana_hard_forks as hard_forks; pub mod hash; pub mod log; From 92ebf0859e3f1d74867317d4600b742924011f9b Mon Sep 17 00:00:00 2001 From: Joe C Date: Tue, 7 Jan 2025 14:30:22 +0800 Subject: [PATCH 04/12] Update sdk/genesis-config/Cargo.toml Co-authored-by: Jon C --- sdk/genesis-config/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/genesis-config/Cargo.toml b/sdk/genesis-config/Cargo.toml index dd3aef928cc7b7..b678b1eede68f9 100644 --- a/sdk/genesis-config/Cargo.toml +++ b/sdk/genesis-config/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "solana-genesis-config" -description = "The chain's genesis config." +description = "A Solana network's genesis config." documentation = "https://docs.rs/solana-genesis-config" version = { workspace = true } authors = { workspace = true } From 1891bc4fe7b37809e7e7666dfbcfe0807b667421 Mon Sep 17 00:00:00 2001 From: Joe Caulfield Date: Tue, 7 Jan 2025 14:40:13 +0800 Subject: [PATCH 05/12] sdk: drop unused deps --- Cargo.lock | 2 -- programs/sbf/Cargo.lock | 2 -- sdk/Cargo.toml | 4 ---- sdk/genesis-config/Cargo.toml | 2 +- svm/examples/Cargo.lock | 2 -- 5 files changed, 1 insertion(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bd8b41000a82a5..eca7a5ac6bfff4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8977,7 +8977,6 @@ dependencies = [ "bytemuck", "bytemuck_derive", "byteorder", - "chrono", "curve25519-dalek 4.1.3", "digest 0.10.7", "ed25519-dalek", @@ -8988,7 +8987,6 @@ dependencies = [ "lazy_static", "libsecp256k1", "log", - "memmap2", "num-derive", "num-traits", "openssl", diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index f4e00d9f45e6f8..028683a1b3ef47 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -7601,7 +7601,6 @@ dependencies = [ "bytemuck", "bytemuck_derive", "byteorder 1.5.0", - "chrono", "digest 0.10.7", "ed25519-dalek", "getrandom 0.1.14", @@ -7610,7 +7609,6 @@ dependencies = [ "lazy_static", "libsecp256k1 0.6.0", "log", - "memmap2", "num-derive", "num-traits", "qualifier_attr", diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index eb6f2883284eae..9f31e3009de903 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -22,8 +22,6 @@ default = [ ] full = [ "byteorder", - "chrono", - "memmap2", "rand", "rand0-7", "serde_json", @@ -99,7 +97,6 @@ bs58 = { workspace = true } bytemuck = { workspace = true } bytemuck_derive = { workspace = true } byteorder = { workspace = true, optional = true } -chrono = { workspace = true, features = ["alloc"], optional = true } curve25519-dalek = { workspace = true, optional = true } digest = { workspace = true, optional = true } ed25519-dalek = { workspace = true, optional = true } @@ -107,7 +104,6 @@ itertools = { workspace = true } lazy_static = { workspace = true } libsecp256k1 = { workspace = true, optional = true, features = ["hmac"] } log = { workspace = true } -memmap2 = { workspace = true, optional = true } num-derive = { workspace = true } num-traits = { workspace = true } qualifier_attr = { workspace = true, optional = true } diff --git a/sdk/genesis-config/Cargo.toml b/sdk/genesis-config/Cargo.toml index b678b1eede68f9..dc86cb8a06da37 100644 --- a/sdk/genesis-config/Cargo.toml +++ b/sdk/genesis-config/Cargo.toml @@ -11,7 +11,7 @@ edition = { workspace = true } [dependencies] bincode = { workspace = true } -chrono = { workspace = true } +chrono = { workspace = true, features = ["alloc"] } memmap2 = { workspace = true } serde = { workspace = true, optional = true } serde_derive = { workspace = true, optional = true } diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index c5f2f207c5fe16..d51d77b3439db9 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -6931,7 +6931,6 @@ dependencies = [ "bytemuck", "bytemuck_derive", "byteorder", - "chrono", "digest 0.10.7", "ed25519-dalek", "getrandom 0.1.16", @@ -6940,7 +6939,6 @@ dependencies = [ "lazy_static", "libsecp256k1", "log", - "memmap2", "num-derive", "num-traits", "rand 0.7.3", From f104929a81bbec334740ac6019d33efbeace1961 Mon Sep 17 00:00:00 2001 From: Joe Caulfield Date: Wed, 8 Jan 2025 01:05:12 +0800 Subject: [PATCH 06/12] pubkey rand feature dev dep --- sdk/genesis-config/Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sdk/genesis-config/Cargo.toml b/sdk/genesis-config/Cargo.toml index dc86cb8a06da37..df7022774299a1 100644 --- a/sdk/genesis-config/Cargo.toml +++ b/sdk/genesis-config/Cargo.toml @@ -36,6 +36,9 @@ solana-shred-version = { workspace = true } solana-signer = { workspace = true } solana-time-utils = { workspace = true } +[dev-dependencies] +solana-pubkey = { workspace = true, features = ["rand"] } + [features] frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] serde = ["dep:serde", "dep:serde_derive"] From d53d761f16f8938ac428341f54637373605b3280 Mon Sep 17 00:00:00 2001 From: Joe Caulfield Date: Wed, 8 Jan 2025 12:51:44 +0800 Subject: [PATCH 07/12] remove serde feature --- sdk/Cargo.toml | 4 +--- sdk/genesis-config/Cargo.toml | 21 ++++++++++----------- sdk/genesis-config/src/lib.rs | 7 ++----- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 9f31e3009de903..e0e6c0c5b72957 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -141,9 +141,7 @@ solana-frozen-abi = { workspace = true, optional = true, features = [ solana-frozen-abi-macro = { workspace = true, optional = true, features = [ "frozen-abi", ] } -solana-genesis-config = { workspace = true, features = [ - "serde", -], optional = true } +solana-genesis-config = { workspace = true, optional = true } solana-hard-forks = { workspace = true, features = [ "serde", ], optional = true } diff --git a/sdk/genesis-config/Cargo.toml b/sdk/genesis-config/Cargo.toml index df7022774299a1..21b656eda7a275 100644 --- a/sdk/genesis-config/Cargo.toml +++ b/sdk/genesis-config/Cargo.toml @@ -13,23 +13,23 @@ edition = { workspace = true } bincode = { workspace = true } chrono = { workspace = true, features = ["alloc"] } memmap2 = { workspace = true } -serde = { workspace = true, optional = true } -serde_derive = { workspace = true, optional = true } -solana-account = { workspace = true } -solana-clock = { workspace = true } -solana-cluster-type = { workspace = true } -solana-epoch-schedule = { workspace = true } -solana-fee-calculator = { workspace = true } +serde = { workspace = true } +serde_derive = { workspace = true } +solana-account = { workspace = true, features = ["serde"] } +solana-clock = { workspace = true, features = ["serde"] } +solana-cluster-type = { workspace = true, features = ["serde"] } +solana-epoch-schedule = { workspace = true, features = ["serde"] } +solana-fee-calculator = { workspace = true, features = ["serde"] } solana-frozen-abi = { workspace = true, optional = true } solana-frozen-abi-macro = { workspace = true, optional = true } solana-hash = { workspace = true } -solana-inflation = { workspace = true } +solana-inflation = { workspace = true, features = ["serde"] } solana-keypair = { workspace = true } solana-logger = { workspace = true } solana-native-token = { workspace = true } -solana-poh-config = { workspace = true } +solana-poh-config = { workspace = true, features = ["serde"] } solana-pubkey = { workspace = true } -solana-rent = { workspace = true } +solana-rent = { workspace = true, features = ["serde"] } solana-sdk-ids = { workspace = true } solana-sha256-hasher = { workspace = true } solana-shred-version = { workspace = true } @@ -41,7 +41,6 @@ solana-pubkey = { workspace = true, features = ["rand"] } [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"] diff --git a/sdk/genesis-config/src/lib.rs b/sdk/genesis-config/src/lib.rs index ad87b154d96c1b..a407223ba95493 100644 --- a/sdk/genesis-config/src/lib.rs +++ b/sdk/genesis-config/src/lib.rs @@ -13,6 +13,7 @@ use { bincode::{deserialize, serialize}, chrono::{TimeZone, Utc}, memmap2::Mmap, + serde_derive::{Deserialize, Serialize}, solana_account::{Account, AccountSharedData}, solana_clock::{UnixTimestamp, DEFAULT_TICKS_PER_SLOT}, solana_epoch_schedule::EpochSchedule, @@ -51,11 +52,7 @@ pub const UNUSED_DEFAULT: u64 = 1024; derive(AbiExample), frozen_abi(digest = "D9VFRSj4fodCuKFC9omQY2zY2Uw8wo6SzJFLeMJaVigm") )] -#[cfg_attr( - feature = "serde", - derive(serde_derive::Deserialize, serde_derive::Serialize) -)] -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct GenesisConfig { /// when the network (bootstrap validator) was started relative to the UNIX Epoch pub creation_time: UnixTimestamp, From a0850010f25d94728cb6e5d371bba6f8dd3ddb33 Mon Sep 17 00:00:00 2001 From: Joe Caulfield Date: Thu, 9 Jan 2025 02:00:00 +0800 Subject: [PATCH 08/12] serde is back now --- sdk/Cargo.toml | 4 +++- sdk/genesis-config/Cargo.toml | 32 ++++++++++++++++++++++---------- sdk/genesis-config/src/lib.rs | 35 ++++++++++++++++++++++++----------- 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index e0e6c0c5b72957..f7132e403f1c1a 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -141,7 +141,9 @@ solana-frozen-abi = { workspace = true, optional = true, features = [ solana-frozen-abi-macro = { workspace = true, optional = true, features = [ "frozen-abi", ] } -solana-genesis-config = { workspace = true, optional = true } +solana-genesis-config = { workspace = true, features = [ + "serde" +], optional = true } solana-hard-forks = { workspace = true, features = [ "serde", ], optional = true } diff --git a/sdk/genesis-config/Cargo.toml b/sdk/genesis-config/Cargo.toml index 21b656eda7a275..16da57dd0bd209 100644 --- a/sdk/genesis-config/Cargo.toml +++ b/sdk/genesis-config/Cargo.toml @@ -13,23 +13,23 @@ edition = { workspace = true } bincode = { workspace = true } chrono = { workspace = true, features = ["alloc"] } memmap2 = { workspace = true } -serde = { workspace = true } -serde_derive = { workspace = true } -solana-account = { workspace = true, features = ["serde"] } -solana-clock = { workspace = true, features = ["serde"] } -solana-cluster-type = { workspace = true, features = ["serde"] } -solana-epoch-schedule = { workspace = true, features = ["serde"] } -solana-fee-calculator = { workspace = true, features = ["serde"] } +serde = { workspace = true, optional = true } +serde_derive = { workspace = true, optional = true } +solana-account = { workspace = true } +solana-clock = { workspace = true } +solana-cluster-type = { workspace = true } +solana-epoch-schedule = { workspace = true } +solana-fee-calculator = { workspace = true } solana-frozen-abi = { workspace = true, optional = true } solana-frozen-abi-macro = { workspace = true, optional = true } solana-hash = { workspace = true } -solana-inflation = { workspace = true, features = ["serde"] } +solana-inflation = { workspace = true } solana-keypair = { workspace = true } solana-logger = { workspace = true } solana-native-token = { workspace = true } -solana-poh-config = { workspace = true, features = ["serde"] } +solana-poh-config = { workspace = true } solana-pubkey = { workspace = true } -solana-rent = { workspace = true, features = ["serde"] } +solana-rent = { workspace = true } solana-sdk-ids = { workspace = true } solana-sha256-hasher = { workspace = true } solana-shred-version = { workspace = true } @@ -41,6 +41,18 @@ solana-pubkey = { workspace = true, features = ["rand"] } [features] frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] +serde = [ + "dep:serde", + "dep:serde_derive", + "solana-account/serde", + "solana-clock/serde", + "solana-cluster-type/serde", + "solana-epoch-schedule/serde", + "solana-fee-calculator/serde", + "solana-inflation/serde", + "solana-poh-config/serde", + "solana-rent/serde", +] [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/sdk/genesis-config/src/lib.rs b/sdk/genesis-config/src/lib.rs index a407223ba95493..6fd738a6c6d798 100644 --- a/sdk/genesis-config/src/lib.rs +++ b/sdk/genesis-config/src/lib.rs @@ -9,33 +9,37 @@ pub use solana_cluster_type::ClusterType; #[cfg(feature = "frozen-abi")] use solana_frozen_abi_macro::{frozen_abi, AbiExample}; +#[cfg(feature = "serde")] use { bincode::{deserialize, serialize}, chrono::{TimeZone, Utc}, memmap2::Mmap, - serde_derive::{Deserialize, Serialize}, + solana_hash::Hash, + solana_native_token::lamports_to_sol, + solana_sha256_hasher::hash, + solana_shred_version::compute_shred_version, + std::{ + fmt, + fs::{File, OpenOptions}, + io::Write, + path::{Path, PathBuf}, + }, +}; +use { solana_account::{Account, AccountSharedData}, solana_clock::{UnixTimestamp, DEFAULT_TICKS_PER_SLOT}, solana_epoch_schedule::EpochSchedule, solana_fee_calculator::FeeRateGovernor, - solana_hash::Hash, solana_inflation::Inflation, solana_keypair::Keypair, - solana_native_token::lamports_to_sol, solana_poh_config::PohConfig, solana_pubkey::Pubkey, solana_rent::Rent, solana_sdk_ids::system_program, - solana_sha256_hasher::hash, - solana_shred_version::compute_shred_version, solana_signer::Signer, solana_time_utils::years_as_slots, std::{ collections::BTreeMap, - fmt, - fs::{File, OpenOptions}, - io::Write, - path::{Path, PathBuf}, time::{SystemTime, UNIX_EPOCH}, }, }; @@ -52,7 +56,11 @@ pub const UNUSED_DEFAULT: u64 = 1024; derive(AbiExample), frozen_abi(digest = "D9VFRSj4fodCuKFC9omQY2zY2Uw8wo6SzJFLeMJaVigm") )] -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[cfg_attr( + feature = "serde", + derive(serde_derive::Deserialize, serde_derive::Serialize) +)] +#[derive(Clone, Debug, PartialEq)] pub struct GenesisConfig { /// when the network (bootstrap validator) was started relative to the UNIX Epoch pub creation_time: UnixTimestamp, @@ -135,15 +143,18 @@ impl GenesisConfig { } } + #[cfg(feature = "serde")] pub fn hash(&self) -> Hash { let serialized = serialize(&self).unwrap(); hash(&serialized) } + #[cfg(feature = "serde")] fn genesis_filename(ledger_path: &Path) -> PathBuf { Path::new(ledger_path).join(DEFAULT_GENESIS_FILE) } + #[cfg(feature = "serde")] pub fn load(ledger_path: &Path) -> Result { let filename = Self::genesis_filename(ledger_path); let file = OpenOptions::new() @@ -173,6 +184,7 @@ impl GenesisConfig { Ok(genesis_config) } + #[cfg(feature = "serde")] pub fn write(&self, ledger_path: &Path) -> Result<(), std::io::Error> { let serialized = serialize(&self).map_err(|err| { std::io::Error::new( @@ -219,6 +231,7 @@ impl GenesisConfig { } } +#[cfg(feature = "serde")] impl fmt::Display for GenesisConfig { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( @@ -276,7 +289,7 @@ impl fmt::Display for GenesisConfig { } } -#[cfg(test)] +#[cfg(all(feature = "serde", test))] mod tests { use {super::*, solana_signer::Signer, std::path::PathBuf}; From f5942acf62f1f0691a44928038b404d45ec41400 Mon Sep 17 00:00:00 2001 From: Joe C Date: Thu, 16 Jan 2025 10:58:44 +0800 Subject: [PATCH 09/12] Update sdk/genesis-config/Cargo.toml Co-authored-by: Jon C --- sdk/genesis-config/Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdk/genesis-config/Cargo.toml b/sdk/genesis-config/Cargo.toml index 16da57dd0bd209..120bde65cd1748 100644 --- a/sdk/genesis-config/Cargo.toml +++ b/sdk/genesis-config/Cargo.toml @@ -56,6 +56,8 @@ serde = [ [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] [lints] workspace = true From 88aa19b2de940ddfe2c01a60ecb8e10c999e1f54 Mon Sep 17 00:00:00 2001 From: Joe C Date: Thu, 16 Jan 2025 10:58:58 +0800 Subject: [PATCH 10/12] Update sdk/genesis-config/src/lib.rs Co-authored-by: Jon C --- sdk/genesis-config/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/genesis-config/src/lib.rs b/sdk/genesis-config/src/lib.rs index 6fd738a6c6d798..8bce8c3cf5bc42 100644 --- a/sdk/genesis-config/src/lib.rs +++ b/sdk/genesis-config/src/lib.rs @@ -1,7 +1,7 @@ //! The chain's genesis config. #![cfg_attr(feature = "frozen-abi", feature(min_specialization))] - +#![cfg_attr(docsrs, feature(doc_auto_cfg))] #[deprecated( since = "2.2.0", note = "Use `solana_cluster_type::ClusterType` instead." From de48055578e49f467dfb563eb3c18e040b44b566 Mon Sep 17 00:00:00 2001 From: Joe C Date: Thu, 16 Jan 2025 10:59:49 +0800 Subject: [PATCH 11/12] Update sdk/genesis-config/Cargo.toml Co-authored-by: Jon C --- sdk/genesis-config/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/genesis-config/Cargo.toml b/sdk/genesis-config/Cargo.toml index 120bde65cd1748..99b738ace6a7e2 100644 --- a/sdk/genesis-config/Cargo.toml +++ b/sdk/genesis-config/Cargo.toml @@ -37,6 +37,7 @@ solana-signer = { workspace = true } solana-time-utils = { workspace = true } [dev-dependencies] +solana-genesis-config = { path = ".", features = ["serde"] } solana-pubkey = { workspace = true, features = ["rand"] } [features] From 8c087ee9b385cbe9382ba320763b93dbbfc1b08f Mon Sep 17 00:00:00 2001 From: Joe Caulfield Date: Thu, 16 Jan 2025 19:42:38 +0800 Subject: [PATCH 12/12] update lockfile --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index eca7a5ac6bfff4..415230e797aaed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7402,6 +7402,7 @@ dependencies = [ "solana-fee-calculator", "solana-frozen-abi", "solana-frozen-abi-macro", + "solana-genesis-config", "solana-hash", "solana-inflation", "solana-keypair",