Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract cluster-type crate #3372

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ members = [
"sdk/cargo-build-sbf",
"sdk/cargo-test-sbf",
"sdk/clock",
"sdk/cluster-type",
"sdk/commitment-config",
"sdk/cpi",
"sdk/decode-error",
Expand Down Expand Up @@ -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" }
Expand Down
10 changes: 10 additions & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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 }
Expand Down
26 changes: 26 additions & 0 deletions sdk/cluster-type/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
53 changes: 53 additions & 0 deletions sdk/cluster-type/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#![cfg_attr(feature = "frozen-abi", feature(min_specialization))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#[cfg(feature = "frozen-abi")]
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))]
#[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<Hash> {
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<Self, Self::Err> {
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")),
}
}
}
52 changes: 6 additions & 46 deletions sdk/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -28,7 +33,6 @@ use {
fs::{File, OpenOptions},
io::Write,
path::{Path, PathBuf},
str::FromStr,
time::{SystemTime, UNIX_EPOCH},
},
};
Expand All @@ -40,54 +44,10 @@ 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<Hash> {
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<Self, Self::Err> {
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),
frozen_abi(digest = "41wPwgEZLhp9AS4tjTQebW7cvHnkbSSTN19vaKwVett6")
frozen_abi(digest = "iDVgqt11gc2Fnu2mrkMsfsjfonDQ5mGX26vQwLivo7M")
)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct GenesisConfig {
Expand Down
Loading