mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-20 19:11:08 +03:00
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
This commit is contained in:
parent
2125c05020
commit
a5b8968826
12 changed files with 127 additions and 243 deletions
|
@ -18,7 +18,9 @@ use crate::core::consensus;
|
||||||
use crate::core::core::hash::Hashed;
|
use crate::core::core::hash::Hashed;
|
||||||
use crate::core::core::verifier_cache::VerifierCache;
|
use crate::core::core::verifier_cache::VerifierCache;
|
||||||
use crate::core::core::Committed;
|
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::global;
|
||||||
use crate::core::pow;
|
use crate::core::pow;
|
||||||
use crate::error::{Error, ErrorKind};
|
use crate::error::{Error, ErrorKind};
|
||||||
|
@ -394,7 +396,9 @@ fn validate_header(header: &BlockHeader, ctx: &mut BlockContext<'_>) -> Result<(
|
||||||
return Err(ErrorKind::WrongTotalDifficulty.into());
|
return Err(ErrorKind::WrongTotalDifficulty.into());
|
||||||
}
|
}
|
||||||
// check the secondary PoW scaling factor if applicable
|
// 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!(
|
info!(
|
||||||
"validate_header: header secondary scaling {} != {}",
|
"validate_header: header secondary scaling {} != {}",
|
||||||
header.pow.secondary_scaling, next_header_info.secondary_scaling
|
header.pow.secondary_scaling, next_header_info.secondary_scaling
|
||||||
|
|
|
@ -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
|
/// Testnet second hard fork height, set to happen around 2020-06-20
|
||||||
pub const TESTNET_THIRD_HARD_FORK: u64 = 552_960;
|
pub const TESTNET_THIRD_HARD_FORK: u64 = 552_960;
|
||||||
|
|
||||||
/// AutomatedTesting and UserTesting HF1 height.
|
/// Testnet second hard fork height, set to happen around 2020-12-8
|
||||||
pub const TESTING_FIRST_HARD_FORK: u64 = 3;
|
pub const TESTNET_FOURTH_HARD_FORK: u64 = 642_240;
|
||||||
|
|
||||||
/// AutomatedTesting and UserTesting HF2 height.
|
/// Fork every 3 blocks
|
||||||
pub const TESTING_SECOND_HARD_FORK: u64 = 6;
|
pub const TESTING_HARD_FORK_INTERVAL: u64 = 3;
|
||||||
|
|
||||||
/// AutomatedTesting and UserTesting HF3 height.
|
|
||||||
pub const TESTING_THIRD_HARD_FORK: u64 = 9;
|
|
||||||
|
|
||||||
/// Compute possible block version at a given height, implements
|
/// Compute possible block version at a given height, implements
|
||||||
/// 6 months interval scheduled hard forks for the first 2 years.
|
/// 6 months interval scheduled hard forks for the first 2 years.
|
||||||
pub fn header_version(height: u64) -> HeaderVersion {
|
pub fn header_version(height: u64) -> HeaderVersion {
|
||||||
let chain_type = global::get_chain_type();
|
|
||||||
let hf_interval = (1 + height / HARD_FORK_INTERVAL) as u16;
|
let hf_interval = (1 + height / HARD_FORK_INTERVAL) as u16;
|
||||||
match chain_type {
|
match global::get_chain_type() {
|
||||||
global::ChainTypes::Mainnet => HeaderVersion(hf_interval),
|
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 => {
|
global::ChainTypes::Testnet => {
|
||||||
if height < TESTNET_FIRST_HARD_FORK {
|
if height < TESTNET_FIRST_HARD_FORK {
|
||||||
HeaderVersion(1)
|
HeaderVersion(1)
|
||||||
|
@ -159,20 +159,7 @@ pub fn header_version(height: u64) -> HeaderVersion {
|
||||||
HeaderVersion(2)
|
HeaderVersion(2)
|
||||||
} else if height < TESTNET_THIRD_HARD_FORK {
|
} else if height < TESTNET_THIRD_HARD_FORK {
|
||||||
HeaderVersion(3)
|
HeaderVersion(3)
|
||||||
} else if height < 4 * HARD_FORK_INTERVAL {
|
} else if height < TESTNET_FOURTH_HARD_FORK {
|
||||||
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 {
|
|
||||||
HeaderVersion(4)
|
HeaderVersion(4)
|
||||||
} else {
|
} else {
|
||||||
HeaderVersion(5)
|
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
|
/// Check whether the block version is valid at a given height, implements
|
||||||
/// 6 months interval scheduled hard forks for the first 2 years.
|
/// 6 months interval scheduled hard forks for the first 2 years.
|
||||||
pub fn valid_header_version(height: u64, version: HeaderVersion) -> bool {
|
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
|
/// Number of blocks used to calculate difficulty adjustments
|
||||||
|
|
|
@ -17,19 +17,17 @@
|
||||||
//! should be used sparingly.
|
//! should be used sparingly.
|
||||||
|
|
||||||
use crate::consensus::{
|
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,
|
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,
|
DEFAULT_MIN_EDGE_BITS, DIFFICULTY_ADJUST_WINDOW, INITIAL_DIFFICULTY, MAX_BLOCK_WEIGHT,
|
||||||
PROOFSIZE, SECOND_POW_EDGE_BITS, STATE_SYNC_THRESHOLD,
|
PROOFSIZE, SECOND_POW_EDGE_BITS, STATE_SYNC_THRESHOLD,
|
||||||
};
|
};
|
||||||
use crate::core::block::HeaderVersion;
|
use crate::core::block::HeaderVersion;
|
||||||
use crate::{
|
use crate::pow::{
|
||||||
pow::{
|
self, new_cuckaroo_ctx, new_cuckarood_ctx, new_cuckaroom_ctx, new_cuckarooz_ctx,
|
||||||
self, new_cuckaroo_ctx, new_cuckarood_ctx, new_cuckaroom_ctx, new_cuckarooz_ctx,
|
new_cuckatoo_ctx, no_cuckaroo_ctx, BitVec, PoWContext,
|
||||||
new_cuckatoo_ctx, BitVec, PoWContext,
|
|
||||||
},
|
|
||||||
ser::ProtocolVersion,
|
|
||||||
};
|
};
|
||||||
|
use crate::ser::ProtocolVersion;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use util::OneTime;
|
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
|
/// Single change point
|
||||||
pub fn create_pow_context<T>(
|
pub fn create_pow_context<T>(
|
||||||
height: u64,
|
height: u64,
|
||||||
|
@ -224,35 +222,22 @@ pub fn create_pow_context<T>(
|
||||||
max_sols: u32,
|
max_sols: u32,
|
||||||
) -> Result<Box<dyn PoWContext>, pow::Error> {
|
) -> Result<Box<dyn PoWContext>, pow::Error> {
|
||||||
let chain_type = get_chain_type();
|
let chain_type = get_chain_type();
|
||||||
match chain_type {
|
if chain_type == ChainTypes::Mainnet || chain_type == ChainTypes::Testnet {
|
||||||
// Mainnet has Cuckaroo{,d,m,z}29 for AR and Cuckatoo31+ for AF
|
// Mainnet and Testnet have Cuckatoo31+ for AF and Cuckaroo{,d,m,z}29 for AR
|
||||||
ChainTypes::Mainnet if edge_bits > 29 => new_cuckatoo_ctx(edge_bits, proof_size, max_sols),
|
if edge_bits > 29 {
|
||||||
ChainTypes::Mainnet if valid_header_version(height, HeaderVersion(4)) => {
|
new_cuckatoo_ctx(edge_bits, proof_size, max_sols)
|
||||||
new_cuckarooz_ctx(edge_bits, proof_size)
|
} 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)) => {
|
} else {
|
||||||
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),
|
|
||||||
|
|
||||||
// Everything else is Cuckatoo only
|
// Everything else is Cuckatoo only
|
||||||
_ => new_cuckatoo_ctx(edge_bits, proof_size, max_sols),
|
new_cuckatoo_ctx(edge_bits, proof_size, max_sols)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ pub mod lean;
|
||||||
mod siphash;
|
mod siphash;
|
||||||
mod types;
|
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::cuckarood::{new_cuckarood_ctx, CuckaroodContext};
|
||||||
pub use crate::pow::cuckaroom::{new_cuckaroom_ctx, CuckaroomContext};
|
pub use crate::pow::cuckaroom::{new_cuckaroom_ctx, CuckaroomContext};
|
||||||
pub use crate::pow::cuckarooz::{new_cuckarooz_ctx, CuckaroozContext};
|
pub use crate::pow::cuckarooz::{new_cuckarooz_ctx, CuckaroozContext};
|
||||||
|
|
|
@ -37,6 +37,11 @@ pub fn new_cuckaroo_ctx(edge_bits: u8, proof_size: usize) -> Result<Box<dyn PoWC
|
||||||
Ok(Box::new(CuckarooContext { params }))
|
Ok(Box::new(CuckarooContext { params }))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Error returned for cuckaroo request beyond HardFork4
|
||||||
|
pub fn no_cuckaroo_ctx() -> Result<Box<dyn PoWContext>, Error> {
|
||||||
|
Err(ErrorKind::Verification("no cuckaroo past HardFork4".to_owned()).into())
|
||||||
|
}
|
||||||
|
|
||||||
/// Cuckaroo cycle context. Only includes the verifier for now.
|
/// Cuckaroo cycle context. Only includes the verifier for now.
|
||||||
pub struct CuckarooContext {
|
pub struct CuckarooContext {
|
||||||
params: CuckooParams,
|
params: CuckooParams,
|
||||||
|
|
|
@ -214,6 +214,8 @@ pub struct ProofOfWork {
|
||||||
/// Total accumulated difficulty since genesis block
|
/// Total accumulated difficulty since genesis block
|
||||||
pub total_difficulty: Difficulty,
|
pub total_difficulty: Difficulty,
|
||||||
/// Variable difficulty scaling factor fo secondary proof of work
|
/// 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,
|
pub secondary_scaling: u32,
|
||||||
/// Nonce increment used to mine this block.
|
/// Nonce increment used to mine this block.
|
||||||
pub nonce: u64,
|
pub nonce: u64,
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
use crate::common::{new_block, tx1i2o, tx2i1o, txspend1i1o};
|
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::block::{Block, BlockHeader, Error, HeaderVersion, UntrustedBlockHeader};
|
||||||
use crate::core::core::hash::Hashed;
|
use crate::core::core::hash::Hashed;
|
||||||
use crate::core::core::id::ShortIdentifiable;
|
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.
|
// 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_chain_type(global::ChainTypes::AutomatedTesting);
|
||||||
global::set_local_nrd_enabled(true);
|
global::set_local_nrd_enabled(true);
|
||||||
|
|
||||||
let keychain = ExtKeychain::from_random_seed(false).unwrap();
|
let keychain = ExtKeychain::from_random_seed(false).unwrap();
|
||||||
let builder = ProofBuilder::new(&keychain);
|
let builder = ProofBuilder::new(&keychain);
|
||||||
let key_id1 = ExtKeychain::derive_key_id(1, 1, 0, 0, 0);
|
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();
|
.unwrap();
|
||||||
let txs = &[tx];
|
let txs = &[tx];
|
||||||
|
|
||||||
let prev_height = TESTING_THIRD_HARD_FORK - 2;
|
let prev_height = 3 * TESTING_HARD_FORK_INTERVAL - 2;
|
||||||
let prev = BlockHeader {
|
let prev = BlockHeader {
|
||||||
height: prev_height,
|
height: prev_height,
|
||||||
version: consensus::header_version(prev_height),
|
version: consensus::header_version(prev_height),
|
||||||
|
@ -134,7 +133,7 @@ fn block_with_nrd_kernel_pre_post_hf3() {
|
||||||
Err(Error::NRDKernelPreHF3)
|
Err(Error::NRDKernelPreHF3)
|
||||||
);
|
);
|
||||||
|
|
||||||
let prev_height = TESTING_THIRD_HARD_FORK - 1;
|
let prev_height = 3 * TESTING_HARD_FORK_INTERVAL - 1;
|
||||||
let prev = BlockHeader {
|
let prev = BlockHeader {
|
||||||
height: prev_height,
|
height: prev_height,
|
||||||
version: consensus::header_version(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.
|
// 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_eq!(b.header.version, HeaderVersion(4));
|
||||||
assert!(b
|
assert!(b
|
||||||
.validate(&BlindingFactor::zero(), verifier_cache())
|
.validate(&BlindingFactor::zero(), verifier_cache())
|
||||||
.is_ok());
|
.is_ok());
|
||||||
|
|
||||||
let prev_height = TESTING_THIRD_HARD_FORK;
|
let prev_height = 3 * TESTING_HARD_FORK_INTERVAL;
|
||||||
let prev = BlockHeader {
|
let prev = BlockHeader {
|
||||||
height: prev_height,
|
height: prev_height,
|
||||||
version: consensus::header_version(prev_height),
|
version: consensus::header_version(prev_height),
|
||||||
|
@ -199,7 +198,7 @@ fn block_with_nrd_kernel_nrd_not_enabled() {
|
||||||
|
|
||||||
let txs = &[tx];
|
let txs = &[tx];
|
||||||
|
|
||||||
let prev_height = TESTING_THIRD_HARD_FORK - 2;
|
let prev_height = 3 * TESTING_HARD_FORK_INTERVAL - 2;
|
||||||
let prev = BlockHeader {
|
let prev = BlockHeader {
|
||||||
height: prev_height,
|
height: prev_height,
|
||||||
version: consensus::header_version(prev_height),
|
version: consensus::header_version(prev_height),
|
||||||
|
@ -220,7 +219,7 @@ fn block_with_nrd_kernel_nrd_not_enabled() {
|
||||||
Err(Error::NRDKernelNotEnabled)
|
Err(Error::NRDKernelNotEnabled)
|
||||||
);
|
);
|
||||||
|
|
||||||
let prev_height = TESTING_THIRD_HARD_FORK - 1;
|
let prev_height = 3 * TESTING_HARD_FORK_INTERVAL - 1;
|
||||||
let prev = BlockHeader {
|
let prev = BlockHeader {
|
||||||
height: prev_height,
|
height: prev_height,
|
||||||
version: consensus::header_version(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.
|
// 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.header.version, HeaderVersion(4));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
b.validate(&BlindingFactor::zero(), verifier_cache()),
|
b.validate(&BlindingFactor::zero(), verifier_cache()),
|
||||||
Err(Error::NRDKernelNotEnabled)
|
Err(Error::NRDKernelNotEnabled)
|
||||||
);
|
);
|
||||||
|
|
||||||
let prev_height = TESTING_THIRD_HARD_FORK;
|
let prev_height = 3 * TESTING_HARD_FORK_INTERVAL;
|
||||||
let prev = BlockHeader {
|
let prev = BlockHeader {
|
||||||
height: prev_height,
|
height: prev_height,
|
||||||
version: consensus::header_version(prev_height),
|
version: consensus::header_version(prev_height),
|
||||||
|
|
|
@ -435,73 +435,22 @@ fn test_secondary_pow_scale() {
|
||||||
fn hard_forks() {
|
fn hard_forks() {
|
||||||
global::set_local_chain_type(global::ChainTypes::Mainnet);
|
global::set_local_chain_type(global::ChainTypes::Mainnet);
|
||||||
|
|
||||||
assert!(valid_header_version(0, HeaderVersion(1)));
|
assert_eq!(header_version(0), HeaderVersion(1));
|
||||||
assert!(valid_header_version(10, HeaderVersion(1)));
|
assert_eq!(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!(valid_header_version(
|
assert_eq!(header_version(HARD_FORK_INTERVAL - 1), HeaderVersion(1));
|
||||||
HARD_FORK_INTERVAL * 2 - 1,
|
assert_eq!(header_version(HARD_FORK_INTERVAL), HeaderVersion(2));
|
||||||
HeaderVersion(2)
|
assert_eq!(header_version(HARD_FORK_INTERVAL + 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!(valid_header_version(
|
assert_eq!(header_version(HARD_FORK_INTERVAL * 2 - 1), HeaderVersion(2));
|
||||||
HARD_FORK_INTERVAL * 3 - 1,
|
assert_eq!(header_version(HARD_FORK_INTERVAL * 2), HeaderVersion(3));
|
||||||
HeaderVersion(3)
|
assert_eq!(header_version(HARD_FORK_INTERVAL * 2 + 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)
|
|
||||||
));
|
|
||||||
|
|
||||||
// v5 not active yet
|
assert_eq!(header_version(HARD_FORK_INTERVAL * 3 - 1), HeaderVersion(3));
|
||||||
assert!(!valid_header_version(
|
assert_eq!(header_version(HARD_FORK_INTERVAL * 3), HeaderVersion(4));
|
||||||
HARD_FORK_INTERVAL * 4,
|
assert_eq!(header_version(HARD_FORK_INTERVAL * 3 + 1), HeaderVersion(4));
|
||||||
HeaderVersion(5)
|
|
||||||
));
|
assert_eq!(header_version(HARD_FORK_INTERVAL * 4 - 1), HeaderVersion(4));
|
||||||
assert!(!valid_header_version(
|
assert_eq!(header_version(HARD_FORK_INTERVAL * 4), HeaderVersion(5));
|
||||||
HARD_FORK_INTERVAL * 4,
|
assert_eq!(header_version(HARD_FORK_INTERVAL * 4 + 1), HeaderVersion(5));
|
||||||
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)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use grin_core::consensus::{
|
use grin_core::consensus::{
|
||||||
secondary_pow_ratio, valid_header_version, HARD_FORK_INTERVAL, TESTNET_FIRST_HARD_FORK,
|
header_version, secondary_pow_ratio, HARD_FORK_INTERVAL, TESTNET_FIRST_HARD_FORK,
|
||||||
TESTNET_SECOND_HARD_FORK, TESTNET_THIRD_HARD_FORK,
|
TESTNET_FOURTH_HARD_FORK, TESTNET_SECOND_HARD_FORK, TESTNET_THIRD_HARD_FORK,
|
||||||
};
|
};
|
||||||
use grin_core::core::HeaderVersion;
|
use grin_core::core::HeaderVersion;
|
||||||
use grin_core::global;
|
use grin_core::global;
|
||||||
|
@ -65,109 +65,62 @@ fn test_secondary_pow_ratio() {
|
||||||
fn hard_forks() {
|
fn hard_forks() {
|
||||||
global::set_local_chain_type(global::ChainTypes::Testnet);
|
global::set_local_chain_type(global::ChainTypes::Testnet);
|
||||||
assert_eq!(global::is_testnet(), true);
|
assert_eq!(global::is_testnet(), true);
|
||||||
assert!(valid_header_version(0, HeaderVersion(1)));
|
assert_eq!(header_version(0), HeaderVersion(1));
|
||||||
assert!(valid_header_version(10, HeaderVersion(1)));
|
assert_eq!(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!(!valid_header_version(
|
assert_eq!(
|
||||||
HARD_FORK_INTERVAL * 2 - 1,
|
header_version(TESTNET_FIRST_HARD_FORK - 1),
|
||||||
HeaderVersion(1)
|
HeaderVersion(1)
|
||||||
));
|
);
|
||||||
assert!(!valid_header_version(
|
assert_eq!(header_version(TESTNET_FIRST_HARD_FORK), HeaderVersion(2));
|
||||||
HARD_FORK_INTERVAL * 2 - 1,
|
assert_eq!(
|
||||||
|
header_version(TESTNET_FIRST_HARD_FORK + 1),
|
||||||
HeaderVersion(2)
|
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)
|
HeaderVersion(3)
|
||||||
));
|
);
|
||||||
assert!(valid_header_version(
|
|
||||||
HARD_FORK_INTERVAL * 2,
|
assert_eq!(
|
||||||
|
header_version(TESTNET_THIRD_HARD_FORK - 1),
|
||||||
HeaderVersion(3)
|
HeaderVersion(3)
|
||||||
));
|
);
|
||||||
assert!(valid_header_version(
|
assert_eq!(header_version(TESTNET_THIRD_HARD_FORK), HeaderVersion(4));
|
||||||
HARD_FORK_INTERVAL * 2 + 1,
|
assert_eq!(
|
||||||
HeaderVersion(3)
|
header_version(TESTNET_THIRD_HARD_FORK + 1),
|
||||||
));
|
|
||||||
// v5 not active yet
|
|
||||||
assert!(!valid_header_version(
|
|
||||||
HARD_FORK_INTERVAL * 4,
|
|
||||||
HeaderVersion(5)
|
|
||||||
));
|
|
||||||
assert!(!valid_header_version(
|
|
||||||
HARD_FORK_INTERVAL * 4,
|
|
||||||
HeaderVersion(4)
|
HeaderVersion(4)
|
||||||
));
|
);
|
||||||
assert!(!valid_header_version(
|
|
||||||
HARD_FORK_INTERVAL * 4,
|
assert_eq!(
|
||||||
HeaderVersion(3)
|
header_version(TESTNET_FOURTH_HARD_FORK - 1),
|
||||||
));
|
HeaderVersion(4)
|
||||||
assert!(!valid_header_version(
|
);
|
||||||
HARD_FORK_INTERVAL * 4,
|
assert_eq!(header_version(TESTNET_FOURTH_HARD_FORK), HeaderVersion(5));
|
||||||
HeaderVersion(2)
|
assert_eq!(
|
||||||
));
|
header_version(TESTNET_FOURTH_HARD_FORK + 1),
|
||||||
assert!(!valid_header_version(
|
HeaderVersion(5)
|
||||||
HARD_FORK_INTERVAL * 4,
|
);
|
||||||
HeaderVersion(1)
|
|
||||||
));
|
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));
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ fn test_nrd_kernel_relative_height() -> Result<(), PoolError> {
|
||||||
|
|
||||||
let header = chain.head_header().unwrap();
|
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));
|
assert_eq!(header.version, HeaderVersion(4));
|
||||||
|
|
||||||
let (tx1, tx2, tx3) = {
|
let (tx1, tx2, tx3) = {
|
||||||
|
|
|
@ -80,7 +80,7 @@ fn test_nrd_kernels_disabled() {
|
||||||
// Now mine several more blocks out to HF3
|
// Now mine several more blocks out to HF3
|
||||||
add_some_blocks(&chain, 5, &keychain);
|
add_some_blocks(&chain, 5, &keychain);
|
||||||
let header = chain.head_header().unwrap();
|
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));
|
assert_eq!(header.version, HeaderVersion(4));
|
||||||
|
|
||||||
// NRD kernel support not enabled via feature flag, so not valid.
|
// NRD kernel support not enabled via feature flag, so not valid.
|
||||||
|
|
|
@ -80,7 +80,7 @@ fn test_nrd_kernels_enabled() {
|
||||||
// Now mine several more blocks out to HF3
|
// Now mine several more blocks out to HF3
|
||||||
add_some_blocks(&chain, 5, &keychain);
|
add_some_blocks(&chain, 5, &keychain);
|
||||||
let header = chain.head_header().unwrap();
|
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));
|
assert_eq!(header.version, HeaderVersion(4));
|
||||||
|
|
||||||
// NRD kernel support not enabled via feature flag, so not valid.
|
// NRD kernel support not enabled via feature flag, so not valid.
|
||||||
|
|
Loading…
Reference in a new issue