Rename to ClusterType and restore devnet compat. (#12068)

* Rename to ClusterType and restore devnet compat.

* De-duplicate parse code and add comments

* Adjust default Devnet genesis & reduce it in tests
This commit is contained in:
Ryo Onodera
2020-09-08 23:55:09 +09:00
committed by GitHub
parent c67f8bd821
commit 53b8ea4464
25 changed files with 376 additions and 319 deletions

View File

@ -25,20 +25,41 @@ use std::{
fs::{File, OpenOptions},
io::Write,
path::{Path, PathBuf},
str::FromStr,
time::{SystemTime, UNIX_EPOCH},
};
// 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...
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, AbiEnumVisitor, AbiExample)]
pub enum OperatingMode {
Preview, // Next set of cluster features to be promoted to Stable
Stable, // Stable cluster features
Development, // All features (including experimental features)
pub enum ClusterType {
Testnet,
MainnetBeta,
Devnet,
Development,
}
#[frozen_abi(digest = "2KQs7m2DbLxkEx6pY9Z6qwYJAhN2Q4AdoNgUcULmscgB")]
impl ClusterType {
pub const STRINGS: [&'static str; 4] = ["development", "devnet", "testnet", "mainnet-beta"];
}
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!("{} is unrecognized for cluster type", s)),
}
}
}
#[frozen_abi(digest = "AM75NxYJj5s45rtkFV5S1RCHg2kNMgACjTu5HPfEt4Fp")]
#[derive(Serialize, Deserialize, Debug, Clone, AbiExample)]
pub struct GenesisConfig {
/// when the network (bootstrap validator) was started relative to the UNIX Epoch
@ -65,7 +86,7 @@ pub struct GenesisConfig {
/// how slots map to epochs
pub epoch_schedule: EpochSchedule,
/// network runlevel
pub operating_mode: OperatingMode,
pub cluster_type: ClusterType,
}
// useful for basic tests
@ -101,7 +122,7 @@ impl Default for GenesisConfig {
fee_rate_governor: FeeRateGovernor::default(),
rent: Rent::default(),
epoch_schedule: EpochSchedule::default(),
operating_mode: OperatingMode::Development,
cluster_type: ClusterType::Development,
}
}
}
@ -212,7 +233,7 @@ impl fmt::Display for GenesisConfig {
f,
"\
Creation time: {}\n\
Operating mode: {:?}\n\
Cluster type: {:?}\n\
Genesis hash: {}\n\
Shred version: {}\n\
Ticks per slot: {:?}\n\
@ -225,7 +246,7 @@ impl fmt::Display for GenesisConfig {
Capitalization: {} SOL in {} accounts\n\
",
Utc.timestamp(self.creation_time, 0).to_rfc3339(),
self.operating_mode,
self.cluster_type,
self.hash(),
compute_shred_version(&self.hash(), None),
self.ticks_per_slot,