From 8c5a483bf2291ed016943cc20c7a918afe33d629 Mon Sep 17 00:00:00 2001 From: David Himmelstrup Date: Fri, 21 Jan 2022 17:31:42 +0100 Subject: [PATCH 1/4] Conformance test driver: Use network version from test files. --- tests/conformance_tests/src/message.rs | 5 ++-- .../tests/conformance_runner.rs | 3 +++ types/src/version.rs | 27 +++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/tests/conformance_tests/src/message.rs b/tests/conformance_tests/src/message.rs index b141f216c6c1..c45e6bff0348 100644 --- a/tests/conformance_tests/src/message.rs +++ b/tests/conformance_tests/src/message.rs @@ -4,7 +4,6 @@ use super::*; use db::MemoryDB; use interpreter::{CircSupplyCalc, LookbackStateGetter}; -use networks::get_network_version_default; use state_tree::StateTree; use vm::TokenAmount; @@ -23,6 +22,7 @@ pub struct ExecuteMessageParams<'a> { pub circ_supply: TokenAmount, pub basefee: TokenAmount, pub randomness: ReplayingRand<'a>, + pub nv: fil_types::NetworkVersion, } struct MockCircSupply(TokenAmount); @@ -51,13 +51,14 @@ pub fn execute_message( let circ_supply = MockCircSupply(params.circ_supply); let lb = MockStateLB(bs); + let nv = params.nv; let mut vm = VM::<_, _, _, _, _>::new( params.pre_root, bs, params.epoch, ¶ms.randomness, params.basefee, - get_network_version_default, + |_| nv, &circ_supply, &lb, )?; diff --git a/tests/conformance_tests/tests/conformance_runner.rs b/tests/conformance_tests/tests/conformance_runner.rs index 7cdd412a100d..dcb518b88095 100644 --- a/tests/conformance_tests/tests/conformance_runner.rs +++ b/tests/conformance_tests/tests/conformance_runner.rs @@ -29,6 +29,8 @@ use std::pin::Pin; use std::sync::Arc; use std::task::{Context, Poll}; use walkdir::{DirEntry, WalkDir}; +use std::convert::TryInto; +use fil_types::NetworkVersion; lazy_static! { static ref DEFAULT_BASE_FEE: BigInt = BigInt::from(100); @@ -189,6 +191,7 @@ async fn execute_message_vector( .map(|i| i.to_bigint().unwrap()) .unwrap_or(DEFAULT_BASE_FEE.clone()), randomness: ReplayingRand::new(randomness), + nv: variant.nv.try_into().unwrap_or(NetworkVersion::V0), }, )?; root = post_root; diff --git a/types/src/version.rs b/types/src/version.rs index f0a7074f8e73..bf5825aa14cb 100644 --- a/types/src/version.rs +++ b/types/src/version.rs @@ -3,6 +3,7 @@ use encoding::repr::Serialize_repr; use std::fmt::{self, Display, Formatter}; +use std::convert::TryFrom; /// Specifies the network version #[derive(Debug, PartialEq, Clone, Copy, PartialOrd, Serialize_repr)] @@ -40,6 +41,32 @@ pub enum NetworkVersion { V14, } +impl TryFrom for NetworkVersion { + type Error = (); + + fn try_from(v: u32) -> Result { + match v { + x if x == NetworkVersion::V15 as u32 => Ok(NetworkVersion::V15), + x if x == NetworkVersion::V14 as u32 => Ok(NetworkVersion::V14), + x if x == NetworkVersion::V13 as u32 => Ok(NetworkVersion::V13), + x if x == NetworkVersion::V12 as u32 => Ok(NetworkVersion::V12), + x if x == NetworkVersion::V11 as u32 => Ok(NetworkVersion::V11), + x if x == NetworkVersion::V10 as u32 => Ok(NetworkVersion::V10), + x if x == NetworkVersion::V9 as u32 => Ok(NetworkVersion::V9), + x if x == NetworkVersion::V8 as u32 => Ok(NetworkVersion::V8), + x if x == NetworkVersion::V7 as u32 => Ok(NetworkVersion::V7), + x if x == NetworkVersion::V6 as u32 => Ok(NetworkVersion::V6), + x if x == NetworkVersion::V5 as u32 => Ok(NetworkVersion::V5), + x if x == NetworkVersion::V4 as u32 => Ok(NetworkVersion::V4), + x if x == NetworkVersion::V3 as u32 => Ok(NetworkVersion::V3), + x if x == NetworkVersion::V2 as u32 => Ok(NetworkVersion::V2), + x if x == NetworkVersion::V1 as u32 => Ok(NetworkVersion::V1), + x if x == NetworkVersion::V0 as u32 => Ok(NetworkVersion::V0), + _ => Err(()), + } + } +} + impl Display for NetworkVersion { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { From 85e15ae5631e3464373395eab43b0fe65e7c8120 Mon Sep 17 00:00:00 2001 From: David Himmelstrup Date: Fri, 21 Jan 2022 17:32:24 +0100 Subject: [PATCH 2/4] Apply formatting. --- tests/conformance_tests/tests/conformance_runner.rs | 4 ++-- types/src/version.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/conformance_tests/tests/conformance_runner.rs b/tests/conformance_tests/tests/conformance_runner.rs index dcb518b88095..df6de30c4d7a 100644 --- a/tests/conformance_tests/tests/conformance_runner.rs +++ b/tests/conformance_tests/tests/conformance_runner.rs @@ -11,6 +11,7 @@ use cid::Cid; use clock::ChainEpoch; use conformance_tests::*; use encoding::Cbor; +use fil_types::NetworkVersion; use fil_types::TOTAL_FILECOIN; use flate2::read::GzDecoder; use forest_message::{MessageReceipt, UnsignedMessage}; @@ -21,6 +22,7 @@ use paramfetch::{get_params_default, SectorSizeOpt}; use regex::Regex; use state_manager::StateManager; use statediff::print_state_diff; +use std::convert::TryInto; use std::error::Error as StdError; use std::fmt; use std::fs::File; @@ -29,8 +31,6 @@ use std::pin::Pin; use std::sync::Arc; use std::task::{Context, Poll}; use walkdir::{DirEntry, WalkDir}; -use std::convert::TryInto; -use fil_types::NetworkVersion; lazy_static! { static ref DEFAULT_BASE_FEE: BigInt = BigInt::from(100); diff --git a/types/src/version.rs b/types/src/version.rs index bf5825aa14cb..5e82493280d5 100644 --- a/types/src/version.rs +++ b/types/src/version.rs @@ -2,8 +2,8 @@ // SPDX-License-Identifier: Apache-2.0, MIT use encoding::repr::Serialize_repr; -use std::fmt::{self, Display, Formatter}; use std::convert::TryFrom; +use std::fmt::{self, Display, Formatter}; /// Specifies the network version #[derive(Debug, PartialEq, Clone, Copy, PartialOrd, Serialize_repr)] From 993803a46271f74bb70dfaffa2e3a37f3c7f0c7a Mon Sep 17 00:00:00 2001 From: David Himmelstrup Date: Fri, 28 Jan 2022 11:20:21 +0100 Subject: [PATCH 3/4] Update test-vectors branch. --- tests/conformance_tests/test-vectors | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conformance_tests/test-vectors b/tests/conformance_tests/test-vectors index 7aebc6f892fc..d96ce11315df 160000 --- a/tests/conformance_tests/test-vectors +++ b/tests/conformance_tests/test-vectors @@ -1 +1 @@ -Subproject commit 7aebc6f892fc03819dc3f980df184604c9e9bf63 +Subproject commit d96ce11315dfd219a7279dfa129214212e1b0510 From a70c69dd13b26011a9600d3682e6b31f8a9225b6 Mon Sep 17 00:00:00 2001 From: David Himmelstrup Date: Fri, 28 Jan 2022 11:39:16 +0100 Subject: [PATCH 4/4] Derive network version numbers. --- types/src/version.rs | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/types/src/version.rs b/types/src/version.rs index 5e82493280d5..8dcf13623a0f 100644 --- a/types/src/version.rs +++ b/types/src/version.rs @@ -4,9 +4,11 @@ use encoding::repr::Serialize_repr; use std::convert::TryFrom; use std::fmt::{self, Display, Formatter}; +use num_derive::FromPrimitive; +use num_traits::FromPrimitive; /// Specifies the network version -#[derive(Debug, PartialEq, Clone, Copy, PartialOrd, Serialize_repr)] +#[derive(Debug, PartialEq, Clone, Copy, PartialOrd, Serialize_repr, FromPrimitive)] #[repr(u32)] pub enum NetworkVersion { /// genesis (specs-actors v0.9.3) @@ -45,23 +47,8 @@ impl TryFrom for NetworkVersion { type Error = (); fn try_from(v: u32) -> Result { - match v { - x if x == NetworkVersion::V15 as u32 => Ok(NetworkVersion::V15), - x if x == NetworkVersion::V14 as u32 => Ok(NetworkVersion::V14), - x if x == NetworkVersion::V13 as u32 => Ok(NetworkVersion::V13), - x if x == NetworkVersion::V12 as u32 => Ok(NetworkVersion::V12), - x if x == NetworkVersion::V11 as u32 => Ok(NetworkVersion::V11), - x if x == NetworkVersion::V10 as u32 => Ok(NetworkVersion::V10), - x if x == NetworkVersion::V9 as u32 => Ok(NetworkVersion::V9), - x if x == NetworkVersion::V8 as u32 => Ok(NetworkVersion::V8), - x if x == NetworkVersion::V7 as u32 => Ok(NetworkVersion::V7), - x if x == NetworkVersion::V6 as u32 => Ok(NetworkVersion::V6), - x if x == NetworkVersion::V5 as u32 => Ok(NetworkVersion::V5), - x if x == NetworkVersion::V4 as u32 => Ok(NetworkVersion::V4), - x if x == NetworkVersion::V3 as u32 => Ok(NetworkVersion::V3), - x if x == NetworkVersion::V2 as u32 => Ok(NetworkVersion::V2), - x if x == NetworkVersion::V1 as u32 => Ok(NetworkVersion::V1), - x if x == NetworkVersion::V0 as u32 => Ok(NetworkVersion::V0), + match FromPrimitive::from_u32(v) { + Some(nv) => Ok(nv), _ => Err(()), } }