From 7a7959e1e371b4c49babe38ad976e89b37896b56 Mon Sep 17 00:00:00 2001 From: tyshkor Date: Mon, 22 Aug 2022 11:20:48 +0200 Subject: [PATCH 01/14] most changes --- forest/src/daemon.rs | 2 ++ types/networks/src/lib.rs | 52 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/forest/src/daemon.rs b/forest/src/daemon.rs index af670d8e012d..40ca68e2b2a0 100644 --- a/forest/src/daemon.rs +++ b/forest/src/daemon.rs @@ -50,6 +50,8 @@ pub(super) async fn start(config: Config) { FOREST_VERSION_STRING.as_str() ); + config.chain.validate().unwrap(); + let path: PathBuf = config.client.data_dir.join("libp2p"); let net_keypair = get_keypair(&path.join("keypair")).unwrap_or_else(|| { // Keypair not found, generate and save generated keypair diff --git a/types/networks/src/lib.rs b/types/networks/src/lib.rs index b5892a14e81a..4dab3c823975 100644 --- a/types/networks/src/lib.rs +++ b/types/networks/src/lib.rs @@ -1,5 +1,6 @@ // Copyright 2019-2022 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT +#![feature(variant_count)] #[macro_use] extern crate lazy_static; @@ -89,7 +90,7 @@ const UPGRADE_INFOS: [UpgradeInfo; 16] = [ ]; /// 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, @@ -111,6 +112,27 @@ pub enum Height { Skyr, } +static HEIGHT_VARIANTS: [Height; 18] = [ + Height::Breeze, + Height::Smoke, + Height::Ignition, + Height::ActorsV2, + Height::Tape, + Height::Liftoff, + Height::Kumquat, + Height::Calico, + Height::Persian, + Height::Orange, + Height::Claus, + Height::Trust, + Height::Norwegian, + Height::Turbo, + Height::Hyperdrive, + Height::Chocolate, + Height::OhSnap, + Height::Skyr, +]; + impl Default for Height { fn default() -> Height { Self::Breeze @@ -151,6 +173,34 @@ pub struct ChainConfig { pub policy: Policy, } +impl ChainConfig { + pub fn validate(&self) -> Result<(), String> { + let number_of_network_version_variants = std::mem::variant_count::(); + let number_of_height_variants = std::mem::variant_count::(); + if number_of_network_version_variants + 1 != number_of_height_variants { + return Err( + "number of fvm_shared::NetworkVersion variants does not match number of Height variants + 1" + .to_string(), + ); + } + if self.height_infos.len() == number_of_height_variants { + Err( + "length of height_infos vector was smaller than the number of HeightInfo variants" + .to_string(), + ) + } else { + let mut height_set: HashSet = HashSet::from(HEIGHT_VARIANTS); + for item in &self.height_infos { + height_set.remove(&item.height); + } + if !height_set.is_empty() { + return Err("not all variants of the enum Height have a corresponding entry in height_infos".to_string()); + } + Ok(()) + } + } +} + // FIXME: remove this trait once builtin-actors Policy have it // https://github.com/filecoin-project/builtin-actors/pull/497 impl PartialEq for ChainConfig { From 9e9360b44c930539af946f387b43d5cbe8398e14 Mon Sep 17 00:00:00 2001 From: tyshkor Date: Mon, 22 Aug 2022 17:17:29 +0200 Subject: [PATCH 02/14] requested change --- forest/src/daemon.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/forest/src/daemon.rs b/forest/src/daemon.rs index 40ca68e2b2a0..ae82ee26c8bb 100644 --- a/forest/src/daemon.rs +++ b/forest/src/daemon.rs @@ -50,7 +50,12 @@ pub(super) async fn start(config: Config) { FOREST_VERSION_STRING.as_str() ); - config.chain.validate().unwrap(); + config.chain.validate().unwrap_or_else(|err_string| { + cli_error_and_die( + err_string, + 1, + ) + }); let path: PathBuf = config.client.data_dir.join("libp2p"); let net_keypair = get_keypair(&path.join("keypair")).unwrap_or_else(|| { From bab321ea4cfaeb2faa1e5290c6c9d29eb16ddcc4 Mon Sep 17 00:00:00 2001 From: tyshkor Date: Tue, 23 Aug 2022 09:27:55 +0200 Subject: [PATCH 03/14] fix fmt --- forest/src/daemon.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/forest/src/daemon.rs b/forest/src/daemon.rs index ae82ee26c8bb..d47c6fe3929c 100644 --- a/forest/src/daemon.rs +++ b/forest/src/daemon.rs @@ -50,12 +50,10 @@ pub(super) async fn start(config: Config) { FOREST_VERSION_STRING.as_str() ); - config.chain.validate().unwrap_or_else(|err_string| { - cli_error_and_die( - err_string, - 1, - ) - }); + config + .chain + .validate() + .unwrap_or_else(|err_string| cli_error_and_die(err_string, 1)); let path: PathBuf = config.client.data_dir.join("libp2p"); let net_keypair = get_keypair(&path.join("keypair")).unwrap_or_else(|| { From 9cf2af06ddde3075ba43a0bc61a39b5400b1b839 Mon Sep 17 00:00:00 2001 From: tyshkor Date: Tue, 30 Aug 2022 16:25:25 +0200 Subject: [PATCH 04/14] new ways: delete claus, version_schedule, sort --- forest/src/daemon.rs | 5 --- types/networks/src/calibnet/mod.rs | 6 +-- types/networks/src/lib.rs | 63 +++++++++--------------------- types/networks/src/mainnet/mod.rs | 6 +-- vm/interpreter/src/vm.rs | 2 - 5 files changed, 21 insertions(+), 61 deletions(-) diff --git a/forest/src/daemon.rs b/forest/src/daemon.rs index d47c6fe3929c..af670d8e012d 100644 --- a/forest/src/daemon.rs +++ b/forest/src/daemon.rs @@ -50,11 +50,6 @@ pub(super) async fn start(config: Config) { FOREST_VERSION_STRING.as_str() ); - config - .chain - .validate() - .unwrap_or_else(|err_string| cli_error_and_die(err_string, 1)); - let path: PathBuf = config.client.data_dir.join("libp2p"); let net_keypair = get_keypair(&path.join("keypair")).unwrap_or_else(|| { // Keypair not found, generate and save generated keypair 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 4dab3c823975..bb6634a5543c 100644 --- a/types/networks/src/lib.rs +++ b/types/networks/src/lib.rs @@ -102,7 +102,6 @@ pub enum Height { Calico, Persian, Orange, - Claus, Trust, Norwegian, Turbo, @@ -112,7 +111,7 @@ pub enum Height { Skyr, } -static HEIGHT_VARIANTS: [Height; 18] = [ +static HEIGHT_VARIANTS: [Height; 17] = [ Height::Breeze, Height::Smoke, Height::Ignition, @@ -123,7 +122,6 @@ static HEIGHT_VARIANTS: [Height; 18] = [ Height::Calico, Height::Persian, Height::Orange, - Height::Claus, Height::Trust, Height::Norwegian, Height::Turbo, @@ -153,6 +151,10 @@ pub struct HeightInfo { pub epoch: ChainEpoch, } +pub fn normalize(height_info_vec: &mut Vec) { + height_info_vec.sort_by(|a, b| a.epoch.cmp(&b.epoch)) +} + #[derive(Clone)] struct DrandPoint<'a> { pub height: ChainEpoch, @@ -166,50 +168,24 @@ 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")] pub policy: Policy, } -impl ChainConfig { - pub fn validate(&self) -> Result<(), String> { - let number_of_network_version_variants = std::mem::variant_count::(); - let number_of_height_variants = std::mem::variant_count::(); - if number_of_network_version_variants + 1 != number_of_height_variants { - return Err( - "number of fvm_shared::NetworkVersion variants does not match number of Height variants + 1" - .to_string(), - ); - } - if self.height_infos.len() == number_of_height_variants { - Err( - "length of height_infos vector was smaller than the number of HeightInfo variants" - .to_string(), - ) - } else { - let mut height_set: HashSet = HashSet::from(HEIGHT_VARIANTS); - for item in &self.height_infos { - height_set.remove(&item.height); - } - if !height_set.is_empty() { - return Err("not all variants of the enum Height have a corresponding entry in height_infos".to_string()); - } - Ok(()) - } - } -} - // FIXME: remove this trait once builtin-actors Policy have it // https://github.com/filecoin-project/builtin-actors/pull/497 impl PartialEq for ChainConfig { fn eq(&self, other: &Self) -> bool { + let height_infos = &mut self.height_infos.clone(); + normalize(height_infos); + let other_height_infos = &mut other.height_infos.clone(); + normalize(other_height_infos); 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 + && height_infos == 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 @@ -274,7 +250,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([ @@ -292,19 +267,18 @@ impl ChainConfig { } pub fn network_version(&self, epoch: ChainEpoch) -> NetworkVersion { - let height = self - .height_infos + let height_infos = &mut self.height_infos.clone(); + normalize(height_infos); + let height = 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).") + // unfallible as it is guaranteed that number of heights + // is equal to the number of network versions + TryFrom::try_from(height as u32).unwrap() } pub async fn get_beacon_schedule( @@ -329,7 +303,9 @@ impl ChainConfig { } pub fn epoch(&self, height: Height) -> ChainEpoch { - self.height_infos + let height_infos = &mut self.height_infos.clone(); + normalize(height_infos); + height_infos .iter() .find(|info| height == info.height) .map(|info| info.epoch) @@ -358,7 +334,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), From ec53f9483517b6324f92cbc2eac8e5eaf2ff0baa Mon Sep 17 00:00:00 2001 From: tyshkor Date: Wed, 31 Aug 2022 09:07:48 +0200 Subject: [PATCH 05/14] fix lint --- types/networks/src/lib.rs | 89 +-------------------------------------- 1 file changed, 1 insertion(+), 88 deletions(-) diff --git a/types/networks/src/lib.rs b/types/networks/src/lib.rs index bb6634a5543c..2bfce97046d2 100644 --- a/types/networks/src/lib.rs +++ b/types/networks/src/lib.rs @@ -22,73 +22,6 @@ 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, Hash)] pub enum Height { @@ -111,26 +44,6 @@ pub enum Height { Skyr, } -static HEIGHT_VARIANTS: [Height; 17] = [ - Height::Breeze, - Height::Smoke, - Height::Ignition, - Height::ActorsV2, - Height::Tape, - Height::Liftoff, - Height::Kumquat, - Height::Calico, - Height::Persian, - Height::Orange, - Height::Trust, - Height::Norwegian, - Height::Turbo, - Height::Hyperdrive, - Height::Chocolate, - Height::OhSnap, - Height::Skyr, -]; - impl Default for Height { fn default() -> Height { Self::Breeze @@ -151,7 +64,7 @@ pub struct HeightInfo { pub epoch: ChainEpoch, } -pub fn normalize(height_info_vec: &mut Vec) { +pub fn normalize(height_info_vec: &mut [HeightInfo]) { height_info_vec.sort_by(|a, b| a.epoch.cmp(&b.epoch)) } From a9bcf0630b02fbe7ba651ac3e737f706b50819d2 Mon Sep 17 00:00:00 2001 From: tyshkor Date: Wed, 31 Aug 2022 14:45:47 +0200 Subject: [PATCH 06/14] requested changes --- types/networks/src/lib.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/types/networks/src/lib.rs b/types/networks/src/lib.rs index 2bfce97046d2..5863d4762bca 100644 --- a/types/networks/src/lib.rs +++ b/types/networks/src/lib.rs @@ -1,7 +1,5 @@ // Copyright 2019-2022 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -#![feature(variant_count)] - #[macro_use] extern crate lazy_static; @@ -64,8 +62,9 @@ pub struct HeightInfo { pub epoch: ChainEpoch, } -pub fn normalize(height_info_vec: &mut [HeightInfo]) { - height_info_vec.sort_by(|a, b| a.epoch.cmp(&b.epoch)) +pub fn sort_by_epoch(mut height_info_vec: Vec) -> Vec { + height_info_vec.sort_by(|a, b| a.epoch.cmp(&b.epoch)); + height_info_vec } #[derive(Clone)] @@ -91,10 +90,8 @@ pub struct ChainConfig { // https://github.com/filecoin-project/builtin-actors/pull/497 impl PartialEq for ChainConfig { fn eq(&self, other: &Self) -> bool { - let height_infos = &mut self.height_infos.clone(); - normalize(height_infos); - let other_height_infos = &mut other.height_infos.clone(); - normalize(other_height_infos); + let height_infos = sort_by_epoch(self.height_infos.clone()); + let other_height_infos = sort_by_epoch(other.height_infos.clone()); self.name == other.name && self.bootstrap_peers == other.bootstrap_peers && self.block_delay_secs == other.block_delay_secs @@ -180,8 +177,7 @@ impl ChainConfig { } pub fn network_version(&self, epoch: ChainEpoch) -> NetworkVersion { - let height_infos = &mut self.height_infos.clone(); - normalize(height_infos); + let height_infos = sort_by_epoch(self.height_infos.clone()); let height = height_infos .iter() .rev() @@ -216,8 +212,7 @@ impl ChainConfig { } pub fn epoch(&self, height: Height) -> ChainEpoch { - let height_infos = &mut self.height_infos.clone(); - normalize(height_infos); + let height_infos = sort_by_epoch(self.height_infos.clone()); height_infos .iter() .find(|info| height == info.height) From e40f1438939a8b64f3d5a8c6a98c856a6b9af485 Mon Sep 17 00:00:00 2001 From: tyshkor Date: Thu, 1 Sep 2022 12:04:35 +0200 Subject: [PATCH 07/14] compile time check --- Cargo.lock | 1 + types/networks/Cargo.toml | 1 + types/networks/src/lib.rs | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index a43c47382b60..b5b06cc35424 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3167,6 +3167,7 @@ dependencies = [ "lazy_static", "serde", "serde_json", + "static_assertions", "toml", ] diff --git a/types/networks/Cargo.toml b/types/networks/Cargo.toml index da4b593b12e1..e07d190b0fa5 100644 --- a/types/networks/Cargo.toml +++ b/types/networks/Cargo.toml @@ -14,6 +14,7 @@ fvm_shared = { version = "0.8.0", default-features = false } lazy_static = "1.4" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" +static_assertions = "1.1.0" [dev-dependencies] toml = "0.5" diff --git a/types/networks/src/lib.rs b/types/networks/src/lib.rs index 5863d4762bca..6d0be9b345c5 100644 --- a/types/networks/src/lib.rs +++ b/types/networks/src/lib.rs @@ -1,5 +1,7 @@ // Copyright 2019-2022 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT +#![feature(variant_count)] + #[macro_use] extern crate lazy_static; @@ -8,6 +10,7 @@ use forest_beacon::{BeaconPoint, BeaconSchedule, DrandBeacon, DrandConfig}; use fvm_shared::clock::{ChainEpoch, EPOCH_DURATION_SECONDS}; use fvm_shared::sector::{RegisteredPoStProof, RegisteredSealProof, StoragePower}; use fvm_shared::version::NetworkVersion; +use static_assertions::const_assert_eq; use serde::{Deserialize, Serialize}; use std::collections::HashSet; @@ -17,6 +20,11 @@ mod calibnet; mod drand; mod mainnet; +const_assert_eq!( + std::mem::variant_count::(), + std::mem::variant_count::() +); + /// Newest network version for all networks pub const NEWEST_NETWORK_VERSION: NetworkVersion = NetworkVersion::V16; From 45dd497c754c4313a07031d5de173f35d791a6de Mon Sep 17 00:00:00 2001 From: tyshkor Date: Thu, 1 Sep 2022 12:59:36 +0200 Subject: [PATCH 08/14] from implementation --- Cargo.lock | 1 - types/networks/Cargo.toml | 1 - types/networks/src/lib.rs | 32 ++++++++++++++++++++++++-------- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b5b06cc35424..a43c47382b60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3167,7 +3167,6 @@ dependencies = [ "lazy_static", "serde", "serde_json", - "static_assertions", "toml", ] diff --git a/types/networks/Cargo.toml b/types/networks/Cargo.toml index e07d190b0fa5..da4b593b12e1 100644 --- a/types/networks/Cargo.toml +++ b/types/networks/Cargo.toml @@ -14,7 +14,6 @@ fvm_shared = { version = "0.8.0", default-features = false } lazy_static = "1.4" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -static_assertions = "1.1.0" [dev-dependencies] toml = "0.5" diff --git a/types/networks/src/lib.rs b/types/networks/src/lib.rs index 6d0be9b345c5..31e3d2a00ff9 100644 --- a/types/networks/src/lib.rs +++ b/types/networks/src/lib.rs @@ -1,7 +1,5 @@ // Copyright 2019-2022 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -#![feature(variant_count)] - #[macro_use] extern crate lazy_static; @@ -10,7 +8,6 @@ use forest_beacon::{BeaconPoint, BeaconSchedule, DrandBeacon, DrandConfig}; use fvm_shared::clock::{ChainEpoch, EPOCH_DURATION_SECONDS}; use fvm_shared::sector::{RegisteredPoStProof, RegisteredSealProof, StoragePower}; use fvm_shared::version::NetworkVersion; -use static_assertions::const_assert_eq; use serde::{Deserialize, Serialize}; use std::collections::HashSet; @@ -20,11 +17,6 @@ mod calibnet; mod drand; mod mainnet; -const_assert_eq!( - std::mem::variant_count::(), - std::mem::variant_count::() -); - /// Newest network version for all networks pub const NEWEST_NETWORK_VERSION: NetworkVersion = NetworkVersion::V16; @@ -56,6 +48,30 @@ impl Default for Height { } } +impl From for NetworkVersion { + fn from(height: Height) -> NetworkVersion { + match height { + Height::Breeze => NetworkVersion::V0, + Height::Smoke => NetworkVersion::V1, + Height::Ignition => NetworkVersion::V2, + Height::ActorsV2 => NetworkVersion::V3, + Height::Tape => NetworkVersion::V4, + 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, From 00af883a23fb5b58f79bda4d2a42b1724f6b8ae9 Mon Sep 17 00:00:00 2001 From: tyshkor Date: Thu, 1 Sep 2022 13:56:53 +0200 Subject: [PATCH 09/14] requested changes --- types/networks/src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/types/networks/src/lib.rs b/types/networks/src/lib.rs index 31e3d2a00ff9..b53d6fc73373 100644 --- a/types/networks/src/lib.rs +++ b/types/networks/src/lib.rs @@ -209,9 +209,7 @@ impl ChainConfig { .map(|info| info.height) .unwrap_or(Height::Breeze); - // unfallible as it is guaranteed that number of heights - // is equal to the number of network versions - TryFrom::try_from(height as u32).unwrap() + From::from(height) } pub async fn get_beacon_schedule( From 70f458ebf10552a0dedd3e84c4a45d5471f80914 Mon Sep 17 00:00:00 2001 From: tyshkor Date: Thu, 1 Sep 2022 16:53:29 +0200 Subject: [PATCH 10/14] requested changes --- types/networks/src/lib.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/types/networks/src/lib.rs b/types/networks/src/lib.rs index b53d6fc73373..63b5f7a2b853 100644 --- a/types/networks/src/lib.rs +++ b/types/networks/src/lib.rs @@ -42,6 +42,26 @@ pub enum Height { Skyr, } +pub const HEIGHT_VEC: [Height; 17] = [ + Height::Breeze, + Height::Smoke, + Height::Ignition, + Height::ActorsV2, + Height::Tape, + Height::Liftoff, + Height::Kumquat, + Height::Calico, + Height::Persian, + Height::Orange, + Height::Trust, + Height::Norwegian, + Height::Turbo, + Height::Hyperdrive, + Height::Chocolate, + Height::OhSnap, + Height::Skyr, +]; + impl Default for Height { fn default() -> Height { Self::Breeze @@ -234,7 +254,12 @@ impl ChainConfig { } pub fn epoch(&self, height: Height) -> ChainEpoch { - let height_infos = sort_by_epoch(self.height_infos.clone()); + let height_vec: Vec = self.height_infos.iter().map(|value| value.height).collect(); + let height_set: HashSet = HashSet::from_iter(height_vec); + let mut height_infos = sort_by_epoch(self.height_infos.clone()); + for &height in HashSet::from_iter(HEIGHT_VEC).difference(&height_set) { + height_infos.push(HeightInfo { height, epoch: 0 }); + } height_infos .iter() .find(|info| height == info.height) From c2c0883b583311fabe0f234d864ef789c93e834b Mon Sep 17 00:00:00 2001 From: tyshkor Date: Thu, 1 Sep 2022 17:36:07 +0200 Subject: [PATCH 11/14] requested changes --- types/networks/src/lib.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/types/networks/src/lib.rs b/types/networks/src/lib.rs index 63b5f7a2b853..7e22a25dc37f 100644 --- a/types/networks/src/lib.rs +++ b/types/networks/src/lib.rs @@ -254,17 +254,12 @@ impl ChainConfig { } pub fn epoch(&self, height: Height) -> ChainEpoch { - let height_vec: Vec = self.height_infos.iter().map(|value| value.height).collect(); - let height_set: HashSet = HashSet::from_iter(height_vec); - let mut height_infos = sort_by_epoch(self.height_infos.clone()); - for &height in HashSet::from_iter(HEIGHT_VEC).difference(&height_set) { - height_infos.push(HeightInfo { height, epoch: 0 }); - } + let height_infos = sort_by_epoch(self.height_infos.clone()); 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]> { From fa26316729dc87e1bfabb251a051d6298863ed77 Mon Sep 17 00:00:00 2001 From: tyshkor Date: Fri, 2 Sep 2022 12:49:07 +0200 Subject: [PATCH 12/14] requested changes --- types/networks/src/lib.rs | 41 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/types/networks/src/lib.rs b/types/networks/src/lib.rs index 7e22a25dc37f..bce485dae93d 100644 --- a/types/networks/src/lib.rs +++ b/types/networks/src/lib.rs @@ -42,26 +42,6 @@ pub enum Height { Skyr, } -pub const HEIGHT_VEC: [Height; 17] = [ - Height::Breeze, - Height::Smoke, - Height::Ignition, - Height::ActorsV2, - Height::Tape, - Height::Liftoff, - Height::Kumquat, - Height::Calico, - Height::Persian, - Height::Orange, - Height::Trust, - Height::Norwegian, - Height::Turbo, - Height::Hyperdrive, - Height::Chocolate, - Height::OhSnap, - Height::Skyr, -]; - impl Default for Height { fn default() -> Height { Self::Breeze @@ -71,11 +51,11 @@ impl Default for Height { impl From for NetworkVersion { fn from(height: Height) -> NetworkVersion { match height { - Height::Breeze => NetworkVersion::V0, - Height::Smoke => NetworkVersion::V1, - Height::Ignition => NetworkVersion::V2, - Height::ActorsV2 => NetworkVersion::V3, - Height::Tape => NetworkVersion::V4, + 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, @@ -106,7 +86,8 @@ pub struct HeightInfo { pub epoch: ChainEpoch, } -pub fn sort_by_epoch(mut height_info_vec: Vec) -> Vec { +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 } @@ -134,8 +115,8 @@ pub struct ChainConfig { // https://github.com/filecoin-project/builtin-actors/pull/497 impl PartialEq for ChainConfig { fn eq(&self, other: &Self) -> bool { - let height_infos = sort_by_epoch(self.height_infos.clone()); - let other_height_infos = sort_by_epoch(other.height_infos.clone()); + let height_infos = sort_by_epoch(&self.height_infos); + let other_height_infos = sort_by_epoch(&other.height_infos); self.name == other.name && self.bootstrap_peers == other.bootstrap_peers && self.block_delay_secs == other.block_delay_secs @@ -221,7 +202,7 @@ impl ChainConfig { } pub fn network_version(&self, epoch: ChainEpoch) -> NetworkVersion { - let height_infos = sort_by_epoch(self.height_infos.clone()); + let height_infos = sort_by_epoch(&self.height_infos); let height = height_infos .iter() .rev() @@ -254,7 +235,7 @@ impl ChainConfig { } pub fn epoch(&self, height: Height) -> ChainEpoch { - let height_infos = sort_by_epoch(self.height_infos.clone()); + let height_infos = sort_by_epoch(&self.height_infos); height_infos .iter() .find(|info| height == info.height) From 5c259bb4029070b9ae3b11c8c442f69692a58a80 Mon Sep 17 00:00:00 2001 From: tyshkor Date: Fri, 2 Sep 2022 16:04:31 +0200 Subject: [PATCH 13/14] requested changes --- types/networks/src/lib.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/types/networks/src/lib.rs b/types/networks/src/lib.rs index bce485dae93d..5ac170557ba9 100644 --- a/types/networks/src/lib.rs +++ b/types/networks/src/lib.rs @@ -115,12 +115,10 @@ pub struct ChainConfig { // https://github.com/filecoin-project/builtin-actors/pull/497 impl PartialEq for ChainConfig { fn eq(&self, other: &Self) -> bool { - let height_infos = sort_by_epoch(&self.height_infos); - let other_height_infos = sort_by_epoch(&other.height_infos); self.name == other.name && self.bootstrap_peers == other.bootstrap_peers && self.block_delay_secs == other.block_delay_secs - && 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 @@ -202,8 +200,7 @@ impl ChainConfig { } pub fn network_version(&self, epoch: ChainEpoch) -> NetworkVersion { - let height_infos = sort_by_epoch(&self.height_infos); - let height = height_infos + let height = sort_by_epoch(&self.height_infos) .iter() .rev() .find(|info| epoch > info.epoch) @@ -235,8 +232,7 @@ impl ChainConfig { } pub fn epoch(&self, height: Height) -> ChainEpoch { - let height_infos = sort_by_epoch(&self.height_infos); - height_infos + sort_by_epoch(&self.height_infos) .iter() .find(|info| height == info.height) .map(|info| info.epoch) From 2de70b6a097845020697404435be5c043627f9e9 Mon Sep 17 00:00:00 2001 From: tyshkor Date: Fri, 2 Sep 2022 16:14:05 +0200 Subject: [PATCH 14/14] delete Claus from deleg cns config --- blockchain/consensus/deleg_cns/configs/delegator-config.toml | 1 - blockchain/consensus/deleg_cns/configs/proposer-config.toml | 1 - 2 files changed, 2 deletions(-) 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 },