From a5b896882629f3c327825a8f0ea58324bf1ac2e2 Mon Sep 17 00:00:00 2001 From: John Tromp Date: Tue, 24 Nov 2020 17:13:28 +0100 Subject: [PATCH] HardFork4 (#3478) * HardFork4 initial commit * HF4 obsoletes secondary_scale, which becomes an nonce extension 8->12 bytes * fix TESTNET_FOURTH_HARD_FORK height * improve predicted height for testnet fork on dec 8 * move local variable as suggested by antiochp --- chain/src/pipe.rs | 8 +- core/src/consensus.rs | 37 ++---- core/src/global.rs | 55 +++----- core/src/pow.rs | 2 +- core/src/pow/cuckaroo.rs | 5 + core/src/pow/types.rs | 2 + core/tests/block.rs | 19 ++- core/tests/consensus_mainnet.rs | 81 +++--------- core/tests/consensus_testnet.rs | 155 ++++++++--------------- pool/tests/nrd_kernel_relative_height.rs | 2 +- pool/tests/nrd_kernels_disabled.rs | 2 +- pool/tests/nrd_kernels_enabled.rs | 2 +- 12 files changed, 127 insertions(+), 243 deletions(-) diff --git a/chain/src/pipe.rs b/chain/src/pipe.rs index 39f64bd4b..f1884d695 100644 --- a/chain/src/pipe.rs +++ b/chain/src/pipe.rs @@ -18,7 +18,9 @@ use crate::core::consensus; use crate::core::core::hash::Hashed; use crate::core::core::verifier_cache::VerifierCache; use crate::core::core::Committed; -use crate::core::core::{block, Block, BlockHeader, BlockSums, OutputIdentifier, TransactionBody}; +use crate::core::core::{ + block, Block, BlockHeader, BlockSums, HeaderVersion, OutputIdentifier, TransactionBody, +}; use crate::core::global; use crate::core::pow; use crate::error::{Error, ErrorKind}; @@ -394,7 +396,9 @@ fn validate_header(header: &BlockHeader, ctx: &mut BlockContext<'_>) -> Result<( return Err(ErrorKind::WrongTotalDifficulty.into()); } // check the secondary PoW scaling factor if applicable - if header.pow.secondary_scaling != next_header_info.secondary_scaling { + if header.version < HeaderVersion(5) + && header.pow.secondary_scaling != next_header_info.secondary_scaling + { info!( "validate_header: header secondary scaling {} != {}", header.pow.secondary_scaling, next_header_info.secondary_scaling diff --git a/core/src/consensus.rs b/core/src/consensus.rs index bea63da94..6b8f4e0a1 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -136,22 +136,22 @@ pub const TESTNET_SECOND_HARD_FORK: u64 = 298_080; /// Testnet second hard fork height, set to happen around 2020-06-20 pub const TESTNET_THIRD_HARD_FORK: u64 = 552_960; -/// AutomatedTesting and UserTesting HF1 height. -pub const TESTING_FIRST_HARD_FORK: u64 = 3; +/// Testnet second hard fork height, set to happen around 2020-12-8 +pub const TESTNET_FOURTH_HARD_FORK: u64 = 642_240; -/// AutomatedTesting and UserTesting HF2 height. -pub const TESTING_SECOND_HARD_FORK: u64 = 6; - -/// AutomatedTesting and UserTesting HF3 height. -pub const TESTING_THIRD_HARD_FORK: u64 = 9; +/// Fork every 3 blocks +pub const TESTING_HARD_FORK_INTERVAL: u64 = 3; /// Compute possible block version at a given height, implements /// 6 months interval scheduled hard forks for the first 2 years. pub fn header_version(height: u64) -> HeaderVersion { - let chain_type = global::get_chain_type(); let hf_interval = (1 + height / HARD_FORK_INTERVAL) as u16; - match chain_type { - global::ChainTypes::Mainnet => HeaderVersion(hf_interval), + match global::get_chain_type() { + global::ChainTypes::Mainnet => HeaderVersion(min(5, hf_interval)), + global::ChainTypes::AutomatedTesting | global::ChainTypes::UserTesting => { + let testing_hf_interval = (1 + height / TESTING_HARD_FORK_INTERVAL) as u16; + HeaderVersion(min(5, testing_hf_interval)) + } global::ChainTypes::Testnet => { if height < TESTNET_FIRST_HARD_FORK { HeaderVersion(1) @@ -159,20 +159,7 @@ pub fn header_version(height: u64) -> HeaderVersion { HeaderVersion(2) } else if height < TESTNET_THIRD_HARD_FORK { HeaderVersion(3) - } else if height < 4 * HARD_FORK_INTERVAL { - HeaderVersion(4) - } else { - HeaderVersion(hf_interval) - } - } - global::ChainTypes::AutomatedTesting | global::ChainTypes::UserTesting => { - if height < TESTING_FIRST_HARD_FORK { - HeaderVersion(1) - } else if height < TESTING_SECOND_HARD_FORK { - HeaderVersion(2) - } else if height < TESTING_THIRD_HARD_FORK { - HeaderVersion(3) - } else if height < 4 * HARD_FORK_INTERVAL { + } else if height < TESTNET_FOURTH_HARD_FORK { HeaderVersion(4) } else { HeaderVersion(5) @@ -184,7 +171,7 @@ pub fn header_version(height: u64) -> HeaderVersion { /// Check whether the block version is valid at a given height, implements /// 6 months interval scheduled hard forks for the first 2 years. pub fn valid_header_version(height: u64, version: HeaderVersion) -> bool { - height < 4 * HARD_FORK_INTERVAL && version == header_version(height) + version == header_version(height) } /// Number of blocks used to calculate difficulty adjustments diff --git a/core/src/global.rs b/core/src/global.rs index 196e0b525..3740ebf05 100644 --- a/core/src/global.rs +++ b/core/src/global.rs @@ -17,19 +17,17 @@ //! should be used sparingly. use crate::consensus::{ - graph_weight, valid_header_version, HeaderInfo, BASE_EDGE_BITS, BLOCK_KERNEL_WEIGHT, + graph_weight, header_version, HeaderInfo, BASE_EDGE_BITS, BLOCK_KERNEL_WEIGHT, BLOCK_OUTPUT_WEIGHT, BLOCK_TIME_SEC, COINBASE_MATURITY, CUT_THROUGH_HORIZON, DAY_HEIGHT, DEFAULT_MIN_EDGE_BITS, DIFFICULTY_ADJUST_WINDOW, INITIAL_DIFFICULTY, MAX_BLOCK_WEIGHT, PROOFSIZE, SECOND_POW_EDGE_BITS, STATE_SYNC_THRESHOLD, }; use crate::core::block::HeaderVersion; -use crate::{ - pow::{ - self, new_cuckaroo_ctx, new_cuckarood_ctx, new_cuckaroom_ctx, new_cuckarooz_ctx, - new_cuckatoo_ctx, BitVec, PoWContext, - }, - ser::ProtocolVersion, +use crate::pow::{ + self, new_cuckaroo_ctx, new_cuckarood_ctx, new_cuckaroom_ctx, new_cuckarooz_ctx, + new_cuckatoo_ctx, no_cuckaroo_ctx, BitVec, PoWContext, }; +use crate::ser::ProtocolVersion; use std::cell::Cell; use util::OneTime; @@ -215,7 +213,7 @@ pub fn is_nrd_enabled() -> bool { }) } -/// Return either a cuckoo context or a cuckatoo context +/// Return either a cuckaroo* context or a cuckatoo context /// Single change point pub fn create_pow_context( height: u64, @@ -224,35 +222,22 @@ pub fn create_pow_context( max_sols: u32, ) -> Result, pow::Error> { let chain_type = get_chain_type(); - match chain_type { - // Mainnet has Cuckaroo{,d,m,z}29 for AR and Cuckatoo31+ for AF - ChainTypes::Mainnet if edge_bits > 29 => new_cuckatoo_ctx(edge_bits, proof_size, max_sols), - ChainTypes::Mainnet if valid_header_version(height, HeaderVersion(4)) => { - new_cuckarooz_ctx(edge_bits, proof_size) + if chain_type == ChainTypes::Mainnet || chain_type == ChainTypes::Testnet { + // Mainnet and Testnet have Cuckatoo31+ for AF and Cuckaroo{,d,m,z}29 for AR + if edge_bits > 29 { + new_cuckatoo_ctx(edge_bits, proof_size, max_sols) + } else { + match header_version(height) { + HeaderVersion(1) => new_cuckaroo_ctx(edge_bits, proof_size), + HeaderVersion(2) => new_cuckarood_ctx(edge_bits, proof_size), + HeaderVersion(3) => new_cuckaroom_ctx(edge_bits, proof_size), + HeaderVersion(4) => new_cuckarooz_ctx(edge_bits, proof_size), + _ => no_cuckaroo_ctx(), + } } - ChainTypes::Mainnet if valid_header_version(height, HeaderVersion(3)) => { - new_cuckaroom_ctx(edge_bits, proof_size) - } - ChainTypes::Mainnet if valid_header_version(height, HeaderVersion(2)) => { - new_cuckarood_ctx(edge_bits, proof_size) - } - ChainTypes::Mainnet => new_cuckaroo_ctx(edge_bits, proof_size), - - // Same for Testnet - ChainTypes::Testnet if edge_bits > 29 => new_cuckatoo_ctx(edge_bits, proof_size, max_sols), - ChainTypes::Testnet if valid_header_version(height, HeaderVersion(4)) => { - new_cuckarooz_ctx(edge_bits, proof_size) - } - ChainTypes::Testnet if valid_header_version(height, HeaderVersion(3)) => { - new_cuckaroom_ctx(edge_bits, proof_size) - } - ChainTypes::Testnet if valid_header_version(height, HeaderVersion(2)) => { - new_cuckarood_ctx(edge_bits, proof_size) - } - ChainTypes::Testnet => new_cuckaroo_ctx(edge_bits, proof_size), - + } else { // Everything else is Cuckatoo only - _ => new_cuckatoo_ctx(edge_bits, proof_size, max_sols), + new_cuckatoo_ctx(edge_bits, proof_size, max_sols) } } diff --git a/core/src/pow.rs b/core/src/pow.rs index b9eb2eb28..93d0382b7 100644 --- a/core/src/pow.rs +++ b/core/src/pow.rs @@ -49,7 +49,7 @@ pub mod lean; mod siphash; mod types; -pub use crate::pow::cuckaroo::{new_cuckaroo_ctx, CuckarooContext}; +pub use crate::pow::cuckaroo::{new_cuckaroo_ctx, no_cuckaroo_ctx, CuckarooContext}; pub use crate::pow::cuckarood::{new_cuckarood_ctx, CuckaroodContext}; pub use crate::pow::cuckaroom::{new_cuckaroom_ctx, CuckaroomContext}; pub use crate::pow::cuckarooz::{new_cuckarooz_ctx, CuckaroozContext}; diff --git a/core/src/pow/cuckaroo.rs b/core/src/pow/cuckaroo.rs index 61447f861..ab43423bf 100644 --- a/core/src/pow/cuckaroo.rs +++ b/core/src/pow/cuckaroo.rs @@ -37,6 +37,11 @@ pub fn new_cuckaroo_ctx(edge_bits: u8, proof_size: usize) -> Result Result, Error> { + Err(ErrorKind::Verification("no cuckaroo past HardFork4".to_owned()).into()) +} + /// Cuckaroo cycle context. Only includes the verifier for now. pub struct CuckarooContext { params: CuckooParams, diff --git a/core/src/pow/types.rs b/core/src/pow/types.rs index 07824359e..89783a101 100644 --- a/core/src/pow/types.rs +++ b/core/src/pow/types.rs @@ -214,6 +214,8 @@ pub struct ProofOfWork { /// Total accumulated difficulty since genesis block pub total_difficulty: Difficulty, /// Variable difficulty scaling factor fo secondary proof of work + /// After HardFork4, which obsoletes secondary PoW, this effectively + /// becomes 4 more bytes of nonce. might be repurposed in future. pub secondary_scaling: u32, /// Nonce increment used to mine this block. pub nonce: u64, diff --git a/core/tests/block.rs b/core/tests/block.rs index 8212461c0..309a0d94d 100644 --- a/core/tests/block.rs +++ b/core/tests/block.rs @@ -14,7 +14,7 @@ mod common; use crate::common::{new_block, tx1i2o, tx2i1o, txspend1i1o}; -use crate::core::consensus::{self, BLOCK_OUTPUT_WEIGHT, TESTING_THIRD_HARD_FORK}; +use crate::core::consensus::{self, BLOCK_OUTPUT_WEIGHT, TESTING_HARD_FORK_INTERVAL}; use crate::core::core::block::{Block, BlockHeader, Error, HeaderVersion, UntrustedBlockHeader}; use crate::core::core::hash::Hashed; use crate::core::core::id::ShortIdentifiable; @@ -95,7 +95,6 @@ fn block_with_nrd_kernel_pre_post_hf3() { // Enable the global NRD feature flag. NRD kernels valid at HF3 at height 9. global::set_local_chain_type(global::ChainTypes::AutomatedTesting); global::set_local_nrd_enabled(true); - let keychain = ExtKeychain::from_random_seed(false).unwrap(); let builder = ProofBuilder::new(&keychain); let key_id1 = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); @@ -113,7 +112,7 @@ fn block_with_nrd_kernel_pre_post_hf3() { .unwrap(); let txs = &[tx]; - let prev_height = TESTING_THIRD_HARD_FORK - 2; + let prev_height = 3 * TESTING_HARD_FORK_INTERVAL - 2; let prev = BlockHeader { height: prev_height, version: consensus::header_version(prev_height), @@ -134,7 +133,7 @@ fn block_with_nrd_kernel_pre_post_hf3() { Err(Error::NRDKernelPreHF3) ); - let prev_height = TESTING_THIRD_HARD_FORK - 1; + let prev_height = 3 * TESTING_HARD_FORK_INTERVAL - 1; let prev = BlockHeader { height: prev_height, version: consensus::header_version(prev_height), @@ -149,13 +148,13 @@ fn block_with_nrd_kernel_pre_post_hf3() { ); // Block is valid at header version 4 (at HF height) if it contains an NRD kernel. - assert_eq!(b.header.height, TESTING_THIRD_HARD_FORK); + assert_eq!(b.header.height, 3 * TESTING_HARD_FORK_INTERVAL); assert_eq!(b.header.version, HeaderVersion(4)); assert!(b .validate(&BlindingFactor::zero(), verifier_cache()) .is_ok()); - let prev_height = TESTING_THIRD_HARD_FORK; + let prev_height = 3 * TESTING_HARD_FORK_INTERVAL; let prev = BlockHeader { height: prev_height, version: consensus::header_version(prev_height), @@ -199,7 +198,7 @@ fn block_with_nrd_kernel_nrd_not_enabled() { let txs = &[tx]; - let prev_height = TESTING_THIRD_HARD_FORK - 2; + let prev_height = 3 * TESTING_HARD_FORK_INTERVAL - 2; let prev = BlockHeader { height: prev_height, version: consensus::header_version(prev_height), @@ -220,7 +219,7 @@ fn block_with_nrd_kernel_nrd_not_enabled() { Err(Error::NRDKernelNotEnabled) ); - let prev_height = TESTING_THIRD_HARD_FORK - 1; + let prev_height = 3 * TESTING_HARD_FORK_INTERVAL - 1; let prev = BlockHeader { height: prev_height, version: consensus::header_version(prev_height), @@ -235,14 +234,14 @@ fn block_with_nrd_kernel_nrd_not_enabled() { ); // Block is invalid as NRD not enabled. - assert_eq!(b.header.height, TESTING_THIRD_HARD_FORK); + assert_eq!(b.header.height, 3 * TESTING_HARD_FORK_INTERVAL); assert_eq!(b.header.version, HeaderVersion(4)); assert_eq!( b.validate(&BlindingFactor::zero(), verifier_cache()), Err(Error::NRDKernelNotEnabled) ); - let prev_height = TESTING_THIRD_HARD_FORK; + let prev_height = 3 * TESTING_HARD_FORK_INTERVAL; let prev = BlockHeader { height: prev_height, version: consensus::header_version(prev_height), diff --git a/core/tests/consensus_mainnet.rs b/core/tests/consensus_mainnet.rs index 85721d7f7..a2bbfc5aa 100644 --- a/core/tests/consensus_mainnet.rs +++ b/core/tests/consensus_mainnet.rs @@ -435,73 +435,22 @@ fn test_secondary_pow_scale() { fn hard_forks() { global::set_local_chain_type(global::ChainTypes::Mainnet); - assert!(valid_header_version(0, HeaderVersion(1))); - assert!(valid_header_version(10, HeaderVersion(1))); - assert!(!valid_header_version(10, HeaderVersion(2))); - assert!(valid_header_version( - HARD_FORK_INTERVAL - 1, - HeaderVersion(1) - )); - assert!(!valid_header_version(HARD_FORK_INTERVAL, HeaderVersion(1))); - assert!(valid_header_version(HARD_FORK_INTERVAL, HeaderVersion(2))); - assert!(valid_header_version( - HARD_FORK_INTERVAL + 1, - HeaderVersion(2) - )); + assert_eq!(header_version(0), HeaderVersion(1)); + assert_eq!(header_version(10), HeaderVersion(1)); - assert!(valid_header_version( - HARD_FORK_INTERVAL * 2 - 1, - HeaderVersion(2) - )); - assert!(!valid_header_version( - HARD_FORK_INTERVAL * 2, - HeaderVersion(2) - )); - assert!(valid_header_version( - HARD_FORK_INTERVAL * 2, - HeaderVersion(3) - )); - assert!(valid_header_version( - HARD_FORK_INTERVAL * 2 + 1, - HeaderVersion(3) - )); + assert_eq!(header_version(HARD_FORK_INTERVAL - 1), HeaderVersion(1)); + assert_eq!(header_version(HARD_FORK_INTERVAL), HeaderVersion(2)); + assert_eq!(header_version(HARD_FORK_INTERVAL + 1), HeaderVersion(2)); - assert!(valid_header_version( - HARD_FORK_INTERVAL * 3 - 1, - HeaderVersion(3) - )); - assert!(!valid_header_version( - HARD_FORK_INTERVAL * 3, - HeaderVersion(3) - )); - assert!(valid_header_version( - HARD_FORK_INTERVAL * 3, - HeaderVersion(4) - )); - assert!(valid_header_version( - HARD_FORK_INTERVAL * 3 + 1, - HeaderVersion(4) - )); + assert_eq!(header_version(HARD_FORK_INTERVAL * 2 - 1), HeaderVersion(2)); + assert_eq!(header_version(HARD_FORK_INTERVAL * 2), HeaderVersion(3)); + assert_eq!(header_version(HARD_FORK_INTERVAL * 2 + 1), HeaderVersion(3)); - // v5 not active yet - assert!(!valid_header_version( - HARD_FORK_INTERVAL * 4, - HeaderVersion(5) - )); - assert!(!valid_header_version( - HARD_FORK_INTERVAL * 4, - HeaderVersion(4) - )); - assert!(!valid_header_version( - HARD_FORK_INTERVAL * 4, - HeaderVersion(3) - )); - assert!(!valid_header_version( - HARD_FORK_INTERVAL * 4, - HeaderVersion(2) - )); - assert!(!valid_header_version( - HARD_FORK_INTERVAL * 4, - HeaderVersion(1) - )); + assert_eq!(header_version(HARD_FORK_INTERVAL * 3 - 1), HeaderVersion(3)); + assert_eq!(header_version(HARD_FORK_INTERVAL * 3), HeaderVersion(4)); + assert_eq!(header_version(HARD_FORK_INTERVAL * 3 + 1), HeaderVersion(4)); + + assert_eq!(header_version(HARD_FORK_INTERVAL * 4 - 1), HeaderVersion(4)); + assert_eq!(header_version(HARD_FORK_INTERVAL * 4), HeaderVersion(5)); + assert_eq!(header_version(HARD_FORK_INTERVAL * 4 + 1), HeaderVersion(5)); } diff --git a/core/tests/consensus_testnet.rs b/core/tests/consensus_testnet.rs index 2eb6ee961..a1ce758fe 100644 --- a/core/tests/consensus_testnet.rs +++ b/core/tests/consensus_testnet.rs @@ -12,8 +12,8 @@ // limitations under the License. use grin_core::consensus::{ - secondary_pow_ratio, valid_header_version, HARD_FORK_INTERVAL, TESTNET_FIRST_HARD_FORK, - TESTNET_SECOND_HARD_FORK, TESTNET_THIRD_HARD_FORK, + header_version, secondary_pow_ratio, HARD_FORK_INTERVAL, TESTNET_FIRST_HARD_FORK, + TESTNET_FOURTH_HARD_FORK, TESTNET_SECOND_HARD_FORK, TESTNET_THIRD_HARD_FORK, }; use grin_core::core::HeaderVersion; use grin_core::global; @@ -65,109 +65,62 @@ fn test_secondary_pow_ratio() { fn hard_forks() { global::set_local_chain_type(global::ChainTypes::Testnet); assert_eq!(global::is_testnet(), true); - assert!(valid_header_version(0, HeaderVersion(1))); - assert!(valid_header_version(10, HeaderVersion(1))); - assert!(!valid_header_version(10, HeaderVersion(2))); - assert!(valid_header_version( - TESTNET_FIRST_HARD_FORK - 1, - HeaderVersion(1) - )); - assert!(valid_header_version( - TESTNET_FIRST_HARD_FORK, - HeaderVersion(2) - )); - assert!(valid_header_version( - TESTNET_FIRST_HARD_FORK + 1, - HeaderVersion(2) - )); - assert!(!valid_header_version( - TESTNET_FIRST_HARD_FORK, - HeaderVersion(1) - )); - assert!(valid_header_version( - TESTNET_SECOND_HARD_FORK - 1, - HeaderVersion(2) - )); - assert!(valid_header_version( - TESTNET_SECOND_HARD_FORK, - HeaderVersion(3) - )); - assert!(valid_header_version( - TESTNET_SECOND_HARD_FORK + 1, - HeaderVersion(3) - )); - assert!(!valid_header_version( - TESTNET_SECOND_HARD_FORK, - HeaderVersion(2) - )); - assert!(!valid_header_version( - TESTNET_SECOND_HARD_FORK, - HeaderVersion(1) - )); - assert!(valid_header_version( - TESTNET_THIRD_HARD_FORK - 1, - HeaderVersion(3) - )); - assert!(valid_header_version( - TESTNET_THIRD_HARD_FORK, - HeaderVersion(4) - )); - assert!(valid_header_version( - TESTNET_THIRD_HARD_FORK + 1, - HeaderVersion(4) - )); - assert!(!valid_header_version( - TESTNET_THIRD_HARD_FORK, - HeaderVersion(3) - )); - assert!(!valid_header_version( - TESTNET_THIRD_HARD_FORK, - HeaderVersion(2) - )); - assert!(!valid_header_version( - TESTNET_THIRD_HARD_FORK, - HeaderVersion(1) - )); + assert_eq!(header_version(0), HeaderVersion(1)); + assert_eq!(header_version(10), HeaderVersion(1)); - assert!(!valid_header_version( - HARD_FORK_INTERVAL * 2 - 1, + assert_eq!( + header_version(TESTNET_FIRST_HARD_FORK - 1), HeaderVersion(1) - )); - assert!(!valid_header_version( - HARD_FORK_INTERVAL * 2 - 1, + ); + assert_eq!(header_version(TESTNET_FIRST_HARD_FORK), HeaderVersion(2)); + assert_eq!( + header_version(TESTNET_FIRST_HARD_FORK + 1), HeaderVersion(2) - )); - assert!(valid_header_version( - HARD_FORK_INTERVAL * 2 - 1, + ); + + assert_eq!( + header_version(TESTNET_SECOND_HARD_FORK - 1), + HeaderVersion(2) + ); + assert_eq!(header_version(TESTNET_SECOND_HARD_FORK), HeaderVersion(3)); + assert_eq!( + header_version(TESTNET_SECOND_HARD_FORK + 1), HeaderVersion(3) - )); - assert!(valid_header_version( - HARD_FORK_INTERVAL * 2, + ); + + assert_eq!( + header_version(TESTNET_THIRD_HARD_FORK - 1), HeaderVersion(3) - )); - assert!(valid_header_version( - HARD_FORK_INTERVAL * 2 + 1, - HeaderVersion(3) - )); - // v5 not active yet - assert!(!valid_header_version( - HARD_FORK_INTERVAL * 4, - HeaderVersion(5) - )); - assert!(!valid_header_version( - HARD_FORK_INTERVAL * 4, + ); + assert_eq!(header_version(TESTNET_THIRD_HARD_FORK), HeaderVersion(4)); + assert_eq!( + header_version(TESTNET_THIRD_HARD_FORK + 1), HeaderVersion(4) - )); - assert!(!valid_header_version( - HARD_FORK_INTERVAL * 4, - HeaderVersion(3) - )); - assert!(!valid_header_version( - HARD_FORK_INTERVAL * 4, - HeaderVersion(2) - )); - assert!(!valid_header_version( - HARD_FORK_INTERVAL * 4, - HeaderVersion(1) - )); + ); + + assert_eq!( + header_version(TESTNET_FOURTH_HARD_FORK - 1), + HeaderVersion(4) + ); + assert_eq!(header_version(TESTNET_FOURTH_HARD_FORK), HeaderVersion(5)); + assert_eq!( + header_version(TESTNET_FOURTH_HARD_FORK + 1), + HeaderVersion(5) + ); + + assert_eq!(header_version(HARD_FORK_INTERVAL - 1), HeaderVersion(2)); + assert_eq!(header_version(HARD_FORK_INTERVAL), HeaderVersion(2)); + assert_eq!(header_version(HARD_FORK_INTERVAL + 1), HeaderVersion(2)); + + assert_eq!(header_version(HARD_FORK_INTERVAL * 2 - 1), HeaderVersion(3)); + assert_eq!(header_version(HARD_FORK_INTERVAL * 2), HeaderVersion(3)); + assert_eq!(header_version(HARD_FORK_INTERVAL * 2 + 1), HeaderVersion(3)); + + assert_eq!(header_version(HARD_FORK_INTERVAL * 3 - 1), HeaderVersion(5)); + assert_eq!(header_version(HARD_FORK_INTERVAL * 3), HeaderVersion(5)); + assert_eq!(header_version(HARD_FORK_INTERVAL * 3 + 1), HeaderVersion(5)); + + assert_eq!(header_version(HARD_FORK_INTERVAL * 4 - 1), HeaderVersion(5)); + assert_eq!(header_version(HARD_FORK_INTERVAL * 4), HeaderVersion(5)); + assert_eq!(header_version(HARD_FORK_INTERVAL * 4 + 1), HeaderVersion(5)); } diff --git a/pool/tests/nrd_kernel_relative_height.rs b/pool/tests/nrd_kernel_relative_height.rs index 0caf5f65a..dff13c4a1 100644 --- a/pool/tests/nrd_kernel_relative_height.rs +++ b/pool/tests/nrd_kernel_relative_height.rs @@ -68,7 +68,7 @@ fn test_nrd_kernel_relative_height() -> Result<(), PoolError> { let header = chain.head_header().unwrap(); - assert_eq!(header.height, consensus::TESTING_THIRD_HARD_FORK); + assert_eq!(header.height, 3 * consensus::TESTING_HARD_FORK_INTERVAL); assert_eq!(header.version, HeaderVersion(4)); let (tx1, tx2, tx3) = { diff --git a/pool/tests/nrd_kernels_disabled.rs b/pool/tests/nrd_kernels_disabled.rs index 90d6ef0b5..058644b33 100644 --- a/pool/tests/nrd_kernels_disabled.rs +++ b/pool/tests/nrd_kernels_disabled.rs @@ -80,7 +80,7 @@ fn test_nrd_kernels_disabled() { // Now mine several more blocks out to HF3 add_some_blocks(&chain, 5, &keychain); let header = chain.head_header().unwrap(); - assert_eq!(header.height, consensus::TESTING_THIRD_HARD_FORK); + assert_eq!(header.height, 3 * consensus::TESTING_HARD_FORK_INTERVAL); assert_eq!(header.version, HeaderVersion(4)); // NRD kernel support not enabled via feature flag, so not valid. diff --git a/pool/tests/nrd_kernels_enabled.rs b/pool/tests/nrd_kernels_enabled.rs index 7fd77987a..21f87ab63 100644 --- a/pool/tests/nrd_kernels_enabled.rs +++ b/pool/tests/nrd_kernels_enabled.rs @@ -80,7 +80,7 @@ fn test_nrd_kernels_enabled() { // Now mine several more blocks out to HF3 add_some_blocks(&chain, 5, &keychain); let header = chain.head_header().unwrap(); - assert_eq!(header.height, consensus::TESTING_THIRD_HARD_FORK); + assert_eq!(header.height, 3 * consensus::TESTING_HARD_FORK_INTERVAL); assert_eq!(header.version, HeaderVersion(4)); // NRD kernel support not enabled via feature flag, so not valid.