Skip to content

Commit

Permalink
Update the V4 start height
Browse files Browse the repository at this point in the history
  • Loading branch information
raychu86 committed Nov 30, 2022
1 parent 6bea98b commit 6b4de5f
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions node/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ use time::OffsetDateTime;
use rayon::prelude::*;

// TODO (raychu86): Remove this after Phase 2.
/// The block height to start preparing the new coinbase targeting algorithm.
const PREPARE_V4_START_HEIGHT: u32 = 120000;
/// The block height to start checking the new coinbase targeting algorithm.
const CHECK_V4_START_HEIGHT: u32 = 127500;
/// The block height to start using new coinbase targeting algorithm.
const V4_START_HEIGHT: u32 = 123478;

#[derive(Clone)]
pub struct Consensus<N: Network, C: ConsensusStorage<N>> {
Expand Down Expand Up @@ -248,7 +246,7 @@ impl<N: Network, C: ConsensusStorage<N>> Consensus<N, C> {
}

// Construct the next coinbase target.
let next_coinbase_target = match next_height >= PREPARE_V4_START_HEIGHT {
let next_coinbase_target = match next_height >= V4_START_HEIGHT {
true => coinbase_target::<true>(
latest_block.last_coinbase_target(),
latest_block.last_coinbase_timestamp(),
Expand Down Expand Up @@ -453,7 +451,7 @@ impl<N: Network, C: ConsensusStorage<N>> Consensus<N, C> {
}

// Construct the next coinbase target.
let expected_coinbase_target = match block.height() >= PREPARE_V4_START_HEIGHT {
let expected_coinbase_target = match block.height() >= V4_START_HEIGHT {
true => coinbase_target::<true>(
self.ledger.last_coinbase_target(),
self.ledger.last_coinbase_timestamp(),
Expand All @@ -470,18 +468,14 @@ impl<N: Network, C: ConsensusStorage<N>> Consensus<N, C> {
),
}?;

// TODO (raychu86): Remove this if statement after Phase 2.
// Do not check the coinbase target between `PREPARE_V4_START_HEIGHT` and `CHECK_V4_START_HEIGHT`
if block.height() < PREPARE_V4_START_HEIGHT || block.height() > CHECK_V4_START_HEIGHT {
if block.coinbase_target() != expected_coinbase_target {
bail!("Invalid coinbase target: expected {}, got {}", expected_coinbase_target, block.coinbase_target())
}
if block.coinbase_target() != expected_coinbase_target {
bail!("Invalid coinbase target: expected {}, got {}", expected_coinbase_target, block.coinbase_target())
}

// Ensure the proof target is correct.
let expected_proof_target = proof_target(expected_coinbase_target);
if block.proof_target() != expected_proof_target {
bail!("Invalid proof target: expected {}, got {}", expected_proof_target, block.proof_target())
}
// Ensure the proof target is correct.
let expected_proof_target = proof_target(expected_coinbase_target);
if block.proof_target() != expected_proof_target {
bail!("Invalid proof target: expected {}, got {}", expected_proof_target, block.proof_target())
}

/* Block Hash */
Expand Down

0 comments on commit 6b4de5f

Please sign in to comment.