diff --git a/blockchain/consensus/deleg_cns/configs/delegator-config.toml b/blockchain/consensus/deleg_cns/configs/delegator-config.toml index 6dd05dfdec37..1bab698802bb 100644 --- a/blockchain/consensus/deleg_cns/configs/delegator-config.toml +++ b/blockchain/consensus/deleg_cns/configs/delegator-config.toml @@ -16,7 +16,6 @@ height_infos = [ { height = "Calico", epoch = -1 }, { height = "Persian", epoch = -1 }, { height = "Orange", epoch = -1 }, - { height = "Claus", epoch = -1 }, { height = "Trust", epoch = -1 }, { height = "Norwegian", epoch = -1 }, { height = "Turbo", epoch = -1 }, diff --git a/blockchain/consensus/deleg_cns/configs/proposer-config.toml b/blockchain/consensus/deleg_cns/configs/proposer-config.toml index 26bf3d6e3095..a5451b0f4fc0 100644 --- a/blockchain/consensus/deleg_cns/configs/proposer-config.toml +++ b/blockchain/consensus/deleg_cns/configs/proposer-config.toml @@ -16,7 +16,6 @@ height_infos = [ { height = "Calico", epoch = -1 }, { height = "Persian", epoch = -1 }, { height = "Orange", epoch = -1 }, - { height = "Claus", epoch = -1 }, { height = "Trust", epoch = -1 }, { height = "Norwegian", epoch = -1 }, { height = "Turbo", epoch = -1 }, diff --git a/types/networks/src/calibnet/mod.rs b/types/networks/src/calibnet/mod.rs index 4ec65f69914e..ac305eb81c5f 100644 --- a/types/networks/src/calibnet/mod.rs +++ b/types/networks/src/calibnet/mod.rs @@ -17,7 +17,7 @@ pub const DEFAULT_BOOTSTRAP: &[&str] = &[ ]; /// Height epochs. -pub const HEIGHT_INFOS: [HeightInfo; 18] = [ +pub const HEIGHT_INFOS: [HeightInfo; 17] = [ HeightInfo { height: Height::Breeze, epoch: -1, @@ -58,10 +58,6 @@ pub const HEIGHT_INFOS: [HeightInfo; 18] = [ height: Height::Orange, epoch: 300, }, - HeightInfo { - height: Height::Claus, - epoch: 270, - }, HeightInfo { height: Height::Trust, epoch: 330, diff --git a/types/networks/src/lib.rs b/types/networks/src/lib.rs index b5892a14e81a..5ac170557ba9 100644 --- a/types/networks/src/lib.rs +++ b/types/networks/src/lib.rs @@ -1,6 +1,5 @@ // Copyright 2019-2022 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT - #[macro_use] extern crate lazy_static; @@ -21,75 +20,8 @@ mod mainnet; /// Newest network version for all networks pub const NEWEST_NETWORK_VERSION: NetworkVersion = NetworkVersion::V16; -const UPGRADE_INFOS: [UpgradeInfo; 16] = [ - UpgradeInfo { - height: Height::Breeze, - version: NetworkVersion::V1, - }, - UpgradeInfo { - height: Height::Smoke, - version: NetworkVersion::V2, - }, - UpgradeInfo { - height: Height::Ignition, - version: NetworkVersion::V3, - }, - UpgradeInfo { - height: Height::ActorsV2, - version: NetworkVersion::V4, - }, - UpgradeInfo { - height: Height::Tape, - version: NetworkVersion::V5, - }, - UpgradeInfo { - height: Height::Kumquat, - version: NetworkVersion::V6, - }, - UpgradeInfo { - height: Height::Calico, - version: NetworkVersion::V7, - }, - UpgradeInfo { - height: Height::Persian, - version: NetworkVersion::V8, - }, - UpgradeInfo { - height: Height::Orange, - version: NetworkVersion::V9, - }, - UpgradeInfo { - height: Height::Trust, - version: NetworkVersion::V10, - }, - UpgradeInfo { - height: Height::Norwegian, - version: NetworkVersion::V11, - }, - UpgradeInfo { - height: Height::Turbo, - version: NetworkVersion::V12, - }, - UpgradeInfo { - height: Height::Hyperdrive, - version: NetworkVersion::V13, - }, - UpgradeInfo { - height: Height::Chocolate, - version: NetworkVersion::V14, - }, - UpgradeInfo { - height: Height::OhSnap, - version: NetworkVersion::V15, - }, - UpgradeInfo { - height: Height::Skyr, - version: NetworkVersion::V16, - }, -]; - /// Defines the meaningful heights of the protocol. -#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)] pub enum Height { Breeze, Smoke, @@ -101,7 +33,6 @@ pub enum Height { Calico, Persian, Orange, - Claus, Trust, Norwegian, Turbo, @@ -117,6 +48,30 @@ impl Default for Height { } } +impl From for NetworkVersion { + fn from(height: Height) -> NetworkVersion { + match height { + Height::Breeze => NetworkVersion::V1, + Height::Smoke => NetworkVersion::V2, + Height::Ignition => NetworkVersion::V3, + Height::ActorsV2 => NetworkVersion::V4, + Height::Tape => NetworkVersion::V5, + Height::Liftoff => NetworkVersion::V5, + Height::Kumquat => NetworkVersion::V6, + Height::Calico => NetworkVersion::V7, + Height::Persian => NetworkVersion::V8, + Height::Orange => NetworkVersion::V9, + Height::Trust => NetworkVersion::V10, + Height::Norwegian => NetworkVersion::V11, + Height::Turbo => NetworkVersion::V12, + Height::Hyperdrive => NetworkVersion::V13, + Height::Chocolate => NetworkVersion::V14, + Height::OhSnap => NetworkVersion::V15, + Height::Skyr => NetworkVersion::V16, + } + } +} + #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] pub struct UpgradeInfo { pub height: Height, @@ -131,6 +86,12 @@ pub struct HeightInfo { pub epoch: ChainEpoch, } +pub fn sort_by_epoch(height_info_slice: &[HeightInfo]) -> Vec { + let mut height_info_vec = height_info_slice.to_vec(); + height_info_vec.sort_by(|a, b| a.epoch.cmp(&b.epoch)); + height_info_vec +} + #[derive(Clone)] struct DrandPoint<'a> { pub height: ChainEpoch, @@ -144,7 +105,6 @@ pub struct ChainConfig { pub name: String, pub bootstrap_peers: Vec, pub block_delay_secs: u64, - pub version_schedule: Vec, pub height_infos: Vec, #[serde(default = "default_policy")] #[serde(with = "serde_policy")] @@ -158,8 +118,7 @@ impl PartialEq for ChainConfig { self.name == other.name && self.bootstrap_peers == other.bootstrap_peers && self.block_delay_secs == other.block_delay_secs - && self.version_schedule == other.version_schedule - && self.height_infos == other.height_infos + && sort_by_epoch(&self.height_infos) == sort_by_epoch(&other.height_infos) && (self.policy.max_aggregated_sectors == other.policy.max_aggregated_sectors && self.policy.min_aggregated_sectors == other.policy.min_aggregated_sectors && self.policy.max_aggregated_proof_size == other.policy.max_aggregated_proof_size @@ -224,7 +183,6 @@ impl ChainConfig { name: "calibnet".to_string(), bootstrap_peers: DEFAULT_BOOTSTRAP.iter().map(|x| x.to_string()).collect(), block_delay_secs: EPOCH_DURATION_SECONDS as u64, - version_schedule: UPGRADE_INFOS.to_vec(), height_infos: HEIGHT_INFOS.to_vec(), policy: Policy { valid_post_proof_type: HashSet::::from([ @@ -242,19 +200,14 @@ impl ChainConfig { } pub fn network_version(&self, epoch: ChainEpoch) -> NetworkVersion { - let height = self - .height_infos + let height = sort_by_epoch(&self.height_infos) .iter() .rev() .find(|info| epoch > info.epoch) .map(|info| info.height) .unwrap_or(Height::Breeze); - self.version_schedule - .iter() - .find(|info| height == info.height) - .map(|info| info.version) - .expect("A network version should exist even if not specified in the config (a default exists).") + From::from(height) } pub async fn get_beacon_schedule( @@ -279,11 +232,11 @@ impl ChainConfig { } pub fn epoch(&self, height: Height) -> ChainEpoch { - self.height_infos + sort_by_epoch(&self.height_infos) .iter() .find(|info| height == info.height) .map(|info| info.epoch) - .expect("Internal error: Protocol height not found in map. Please report to https://github.com/ChainSafe/forest/issues") + .unwrap_or(0) } pub fn genesis_bytes(&self) -> Option<&[u8]> { @@ -308,7 +261,6 @@ impl Default for ChainConfig { name: "mainnet".to_string(), bootstrap_peers: DEFAULT_BOOTSTRAP.iter().map(|x| x.to_string()).collect(), block_delay_secs: EPOCH_DURATION_SECONDS as u64, - version_schedule: UPGRADE_INFOS.to_vec(), height_infos: HEIGHT_INFOS.to_vec(), policy: Policy { valid_post_proof_type: HashSet::::from([ diff --git a/types/networks/src/mainnet/mod.rs b/types/networks/src/mainnet/mod.rs index a09dadb7a357..dcb40b4dbaf5 100644 --- a/types/networks/src/mainnet/mod.rs +++ b/types/networks/src/mainnet/mod.rs @@ -32,7 +32,7 @@ pub const DEFAULT_BOOTSTRAP: &[&str] = &[ ]; /// Height epochs. -pub const HEIGHT_INFOS: [HeightInfo; 18] = [ +pub const HEIGHT_INFOS: [HeightInfo; 17] = [ HeightInfo { height: Height::Breeze, epoch: 41_280, @@ -73,10 +73,6 @@ pub const HEIGHT_INFOS: [HeightInfo; 18] = [ height: Height::Orange, epoch: 336_458, }, - HeightInfo { - height: Height::Claus, - epoch: 343_200, - }, HeightInfo { height: Height::Trust, epoch: 550_321, diff --git a/vm/interpreter/src/vm.rs b/vm/interpreter/src/vm.rs index b066839a2845..a2f3cfae6ecb 100644 --- a/vm/interpreter/src/vm.rs +++ b/vm/interpreter/src/vm.rs @@ -70,7 +70,6 @@ pub trait LookbackStateGetter { #[derive(Clone, Copy)] pub struct Heights { pub calico: ChainEpoch, - pub claus: ChainEpoch, pub turbo: ChainEpoch, pub hyperdrive: ChainEpoch, pub chocolate: ChainEpoch, @@ -80,7 +79,6 @@ impl Heights { pub fn new(chain_config: &ChainConfig) -> Self { Heights { calico: chain_config.epoch(Height::Calico), - claus: chain_config.epoch(Height::Claus), turbo: chain_config.epoch(Height::Turbo), hyperdrive: chain_config.epoch(Height::Hyperdrive), chocolate: chain_config.epoch(Height::Chocolate),