height (header version) specific output PMMR root rules (#3147)

* height (header version) specific output PMMR root rules

* cleanup

* cleanup based on PR feedback

* address feedback
This commit is contained in:
Antioch Peverell
2019-12-05 11:55:10 +00:00
committed by GitHub
parent 3a333ae00f
commit 0b21ee607a
7 changed files with 74 additions and 38 deletions
+18 -2
View File
@@ -133,12 +133,19 @@ pub const FLOONET_FIRST_HARD_FORK: u64 = 185_040;
/// Floonet second hard fork height, set to happen around 2019-12-19
pub const FLOONET_SECOND_HARD_FORK: u64 = 298_080;
/// AutomatedTesting and UserTesting first hard fork height.
pub const TESTING_FIRST_HARD_FORK: u64 = 3;
/// AutomatedTesting and UserTesting second hard fork height.
pub const TESTING_SECOND_HARD_FORK: u64 = 6;
/// 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::CHAIN_TYPE.read().clone();
let hf_interval = (1 + height / HARD_FORK_INTERVAL) as u16;
match chain_type {
global::ChainTypes::Mainnet => HeaderVersion(hf_interval),
global::ChainTypes::Floonet => {
if height < FLOONET_FIRST_HARD_FORK {
(HeaderVersion(1))
@@ -150,8 +157,17 @@ pub fn header_version(height: u64) -> HeaderVersion {
HeaderVersion(hf_interval)
}
}
// everything else just like mainnet
_ => 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 < 3 * HARD_FORK_INTERVAL {
(HeaderVersion(3))
} else {
HeaderVersion(hf_interval)
}
}
}
}
+1 -1
View File
@@ -176,7 +176,7 @@ impl Hashed for HeaderEntry {
}
/// Some type safety around header versioning.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Serialize)]
pub struct HeaderVersion(pub u16);
impl From<HeaderVersion> for u16 {