From 389640031b6ae3295a720772b8e94d213815b7ac Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Wed, 30 Oct 2024 02:43:35 +0400 Subject: [PATCH 1/5] extract cluster-type crate --- Cargo.lock | 12 +++++++++ Cargo.toml | 2 ++ programs/sbf/Cargo.lock | 10 ++++++++ sdk/Cargo.toml | 5 ++++ sdk/cluster-type/Cargo.toml | 26 +++++++++++++++++++ sdk/cluster-type/src/lib.rs | 51 +++++++++++++++++++++++++++++++++++++ sdk/src/genesis_config.rs | 50 ++++-------------------------------- 7 files changed, 111 insertions(+), 45 deletions(-) create mode 100644 sdk/cluster-type/Cargo.toml create mode 100644 sdk/cluster-type/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index a25b30e0102318..458837f93823a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6521,6 +6521,17 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "solana-cluster-type" +version = "2.2.0" +dependencies = [ + "serde", + "serde_derive", + "solana-frozen-abi", + "solana-frozen-abi-macro", + "solana-hash", +] + [[package]] name = "solana-commitment-config" version = "2.2.0" @@ -8307,6 +8318,7 @@ dependencies = [ "siphasher", "solana-account", "solana-bn254", + "solana-cluster-type", "solana-commitment-config", "solana-decode-error", "solana-derivation-path", diff --git a/Cargo.toml b/Cargo.toml index 8778a641a570dd..846c8f0e5dbb6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -107,6 +107,7 @@ members = [ "sdk/clock", "sdk/commitment-config", "sdk/cpi", + "sdk/cluster-type", "sdk/decode-error", "sdk/define-syscall", "sdk/derivation-path", @@ -422,6 +423,7 @@ solana-cli-config = { path = "cli-config", version = "=2.2.0" } solana-cli-output = { path = "cli-output", version = "=2.2.0" } solana-client = { path = "client", version = "=2.2.0" } solana-clock = { path = "sdk/clock", version = "=2.2.0" } +solana-cluster-type = { path = "sdk/cluster-type", version = "=2.2.0" } solana-commitment-config = { path = "sdk/commitment-config", version = "=2.2.0" } solana-compute-budget = { path = "compute-budget", version = "=2.2.0" } solana-compute-budget-program = { path = "programs/compute-budget", version = "=2.2.0" } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index f6b09c5bceb8b4..c4d88b299b2a04 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5238,6 +5238,15 @@ dependencies = [ "solana-sysvar-id", ] +[[package]] +name = "solana-cluster-type" +version = "2.2.0" +dependencies = [ + "serde", + "serde_derive", + "solana-hash", +] + [[package]] name = "solana-commitment-config" version = "2.2.0" @@ -7043,6 +7052,7 @@ dependencies = [ "siphasher", "solana-account", "solana-bn254", + "solana-cluster-type", "solana-commitment-config", "solana-decode-error", "solana-derivation-path", diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index cfef796073044f..eab6ad0fb991ed 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -34,6 +34,7 @@ full = [ "solana-commitment-config", "digest", "solana-pubkey/rand", + "dep:solana-cluster-type", "dep:solana-keypair", "dep:solana-precompile-error", "dep:solana-presigner", @@ -50,6 +51,7 @@ frozen-abi = [ "solana-feature-set/frozen-abi", "solana-fee-structure/frozen-abi", "solana-account/frozen-abi", + "solana-cluster-type/frozen-abi", "solana-inflation/frozen-abi", "solana-program/frozen-abi", "solana-reward-info/frozen-abi", @@ -95,6 +97,9 @@ sha3 = { workspace = true, optional = true } siphasher = { workspace = true } solana-account = { workspace = true, features = ["bincode"] } solana-bn254 = { workspace = true } +solana-cluster-type = { workspace = true, features = [ + "serde", +], optional = true } solana-commitment-config = { workspace = true, optional = true, features = ["serde"] } solana-decode-error = { workspace = true } solana-derivation-path = { workspace = true } diff --git a/sdk/cluster-type/Cargo.toml b/sdk/cluster-type/Cargo.toml new file mode 100644 index 00000000000000..1890bab1034791 --- /dev/null +++ b/sdk/cluster-type/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "solana-cluster-type" +description = "Solana ClusterType enum" +documentation = "https://docs.rs/solana-cluster-type" +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-hash = { workspace = true, default-features = false } + +[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"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] diff --git a/sdk/cluster-type/src/lib.rs b/sdk/cluster-type/src/lib.rs new file mode 100644 index 00000000000000..56336ebcca45b0 --- /dev/null +++ b/sdk/cluster-type/src/lib.rs @@ -0,0 +1,51 @@ +#![cfg_attr(feature = "frozen-abi", feature(min_specialization))] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] +use {solana_hash::Hash, std::str::FromStr}; + +// The order can't align with release lifecycle only to remain ABI-compatible... +#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] +#[cfg_attr( + feature = "serde", + derive(serde_derive::Deserialize, serde_derive::Serialize) +)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum ClusterType { + Testnet, + MainnetBeta, + Devnet, + Development, +} + +impl ClusterType { + pub const STRINGS: [&'static str; 4] = ["development", "devnet", "testnet", "mainnet-beta"]; + + /// Get the known genesis hash for this ClusterType + pub fn get_genesis_hash(&self) -> Option { + match self { + Self::MainnetBeta => { + Some(Hash::from_str("5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d").unwrap()) + } + Self::Testnet => { + Some(Hash::from_str("4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY").unwrap()) + } + Self::Devnet => { + Some(Hash::from_str("EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG").unwrap()) + } + Self::Development => None, + } + } +} + +impl FromStr for ClusterType { + type Err = String; + + fn from_str(s: &str) -> Result { + match s { + "development" => Ok(ClusterType::Development), + "devnet" => Ok(ClusterType::Devnet), + "testnet" => Ok(ClusterType::Testnet), + "mainnet-beta" => Ok(ClusterType::MainnetBeta), + _ => Err(format!("{s} is unrecognized for cluster type")), + } + } +} diff --git a/sdk/src/genesis_config.rs b/sdk/src/genesis_config.rs index 3a14dac108cba4..a663dd2daafded 100644 --- a/sdk/src/genesis_config.rs +++ b/sdk/src/genesis_config.rs @@ -2,6 +2,11 @@ #![cfg(feature = "full")] +#[deprecated( + since = "2.2.0", + note = "Use `solana_cluster_type::ClusterType` instead." +)] +pub use solana_cluster_type::ClusterType; use { crate::{ clock::{UnixTimestamp, DEFAULT_TICKS_PER_SLOT}, @@ -28,7 +33,6 @@ use { fs::{File, OpenOptions}, io::Write, path::{Path, PathBuf}, - str::FromStr, time::{SystemTime, UNIX_EPOCH}, }, }; @@ -40,50 +44,6 @@ pub const DEFAULT_GENESIS_DOWNLOAD_PATH: &str = "/genesis.tar.bz2"; // deprecated default that is no longer used pub const UNUSED_DEFAULT: u64 = 1024; -// The order can't align with release lifecycle only to remain ABI-compatible... -#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] -#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] -pub enum ClusterType { - Testnet, - MainnetBeta, - Devnet, - Development, -} - -impl ClusterType { - pub const STRINGS: [&'static str; 4] = ["development", "devnet", "testnet", "mainnet-beta"]; - - /// Get the known genesis hash for this ClusterType - pub fn get_genesis_hash(&self) -> Option { - match self { - Self::MainnetBeta => { - Some(Hash::from_str("5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d").unwrap()) - } - Self::Testnet => { - Some(Hash::from_str("4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY").unwrap()) - } - Self::Devnet => { - Some(Hash::from_str("EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG").unwrap()) - } - Self::Development => None, - } - } -} - -impl FromStr for ClusterType { - type Err = String; - - fn from_str(s: &str) -> Result { - match s { - "development" => Ok(ClusterType::Development), - "devnet" => Ok(ClusterType::Devnet), - "testnet" => Ok(ClusterType::Testnet), - "mainnet-beta" => Ok(ClusterType::MainnetBeta), - _ => Err(format!("{s} is unrecognized for cluster type")), - } - } -} - #[cfg_attr( feature = "frozen-abi", derive(AbiExample), From 8ddf6b2a621ae9bc5890d02e3f8e4ad30c5213f0 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Wed, 30 Oct 2024 03:05:30 +0400 Subject: [PATCH 2/5] fix frozen-abi support --- sdk/cluster-type/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdk/cluster-type/src/lib.rs b/sdk/cluster-type/src/lib.rs index 56336ebcca45b0..4a3ec218e67838 100644 --- a/sdk/cluster-type/src/lib.rs +++ b/sdk/cluster-type/src/lib.rs @@ -1,6 +1,8 @@ #![cfg_attr(feature = "frozen-abi", feature(min_specialization))] #![cfg_attr(docsrs, feature(doc_auto_cfg))] use {solana_hash::Hash, std::str::FromStr}; +#[cfg(feature = "frozen-abi")] +use solana_frozen_abi_macro::{AbiExample, AbiEnumVisitor}; // The order can't align with release lifecycle only to remain ABI-compatible... #[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] From 4b2ea71fb954b9adc31f2f43f4988d05fa7c3627 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Wed, 30 Oct 2024 03:26:03 +0400 Subject: [PATCH 3/5] sort deps --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 846c8f0e5dbb6f..e1ffc9626bac9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -105,9 +105,9 @@ members = [ "sdk/cargo-build-sbf", "sdk/cargo-test-sbf", "sdk/clock", + "sdk/cluster-type", "sdk/commitment-config", "sdk/cpi", - "sdk/cluster-type", "sdk/decode-error", "sdk/define-syscall", "sdk/derivation-path", From 8b94491bede1e47d68aa9c5387a26abe46f6a801 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Wed, 30 Oct 2024 03:27:41 +0400 Subject: [PATCH 4/5] udpate 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 a663dd2daafded..bd71cb09a6b47b 100644 --- a/sdk/src/genesis_config.rs +++ b/sdk/src/genesis_config.rs @@ -47,7 +47,7 @@ pub const UNUSED_DEFAULT: u64 = 1024; #[cfg_attr( feature = "frozen-abi", derive(AbiExample), - frozen_abi(digest = "41wPwgEZLhp9AS4tjTQebW7cvHnkbSSTN19vaKwVett6") + frozen_abi(digest = "iDVgqt11gc2Fnu2mrkMsfsjfonDQ5mGX26vQwLivo7M") )] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] pub struct GenesisConfig { From 994973318de46a9140e140febf7b9e2076675717 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Wed, 30 Oct 2024 03:49:36 +0400 Subject: [PATCH 5/5] fmt --- sdk/cluster-type/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/cluster-type/src/lib.rs b/sdk/cluster-type/src/lib.rs index 4a3ec218e67838..fee10110f730c9 100644 --- a/sdk/cluster-type/src/lib.rs +++ b/sdk/cluster-type/src/lib.rs @@ -1,8 +1,8 @@ #![cfg_attr(feature = "frozen-abi", feature(min_specialization))] #![cfg_attr(docsrs, feature(doc_auto_cfg))] -use {solana_hash::Hash, std::str::FromStr}; #[cfg(feature = "frozen-abi")] -use solana_frozen_abi_macro::{AbiExample, AbiEnumVisitor}; +use solana_frozen_abi_macro::{AbiEnumVisitor, AbiExample}; +use {solana_hash::Hash, std::str::FromStr}; // The order can't align with release lifecycle only to remain ABI-compatible... #[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))]