From b648375bbe0749c3906d70f922cff091b21c9ab1 Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 16 Jul 2020 13:59:44 +1000 Subject: [PATCH] fix: Hard-code the genesis previous block hash --- zebra-consensus/src/checkpoint.rs | 6 +----- zebra-consensus/src/parameters.rs | 15 +++++---------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/zebra-consensus/src/checkpoint.rs b/zebra-consensus/src/checkpoint.rs index 7de82be84..587ac7b49 100644 --- a/zebra-consensus/src/checkpoint.rs +++ b/zebra-consensus/src/checkpoint.rs @@ -85,9 +85,6 @@ pub const MAX_QUEUED_BLOCKS_PER_HEIGHT: usize = 4; struct CheckpointVerifier { // Inputs // - /// The network for this verifier. - network: Network, - /// The checkpoint list for this verifier. checkpoint_list: CheckpointList, @@ -130,7 +127,6 @@ impl CheckpointVerifier { checkpoint_list: impl IntoIterator, ) -> Result { Ok(CheckpointVerifier { - network, checkpoint_list: CheckpointList::new(network, checkpoint_list)?, queued: BTreeMap::new(), // We start by verifying the genesis block, by itself @@ -422,7 +418,7 @@ impl CheckpointVerifier { // Since genesis blocks are hard-coded in zcashd, and not verified // like other blocks, the genesis parent hash is set by the // consensus parameters. - BeforeGenesis => parameters::genesis_previous_block_hash(self.network), + BeforeGenesis => parameters::GENESIS_PREVIOUS_BLOCK_HASH, PreviousCheckpoint(hash) => hash, FinalCheckpoint => return, }; diff --git a/zebra-consensus/src/parameters.rs b/zebra-consensus/src/parameters.rs index 488cfdcb7..53391a70a 100644 --- a/zebra-consensus/src/parameters.rs +++ b/zebra-consensus/src/parameters.rs @@ -12,16 +12,11 @@ use zebra_chain::block::BlockHeaderHash; use zebra_chain::{Network, Network::*}; -/// Returns the previous block hash for the genesis block in `network`. -pub fn genesis_previous_block_hash(network: Network) -> BlockHeaderHash { - // All current networks use all-zeroes for the parent of the genesis block. - // (In Bitcoin, `null` is `[0; 32]`.) - // - // TODO: make this function const when feature(const_if_match) stabilises. - match network { - Mainnet | Testnet => BlockHeaderHash([0; 32]), - } -} +/// The previous block hash for the genesis block. +/// +/// All known networks use the Bitcoin `null` value for the parent of the +/// genesis block. (In Bitcoin, `null` is `[0; 32]`.) +pub const GENESIS_PREVIOUS_BLOCK_HASH: BlockHeaderHash = BlockHeaderHash([0; 32]); /// Returns the hash for the genesis block in `network`. pub fn genesis_hash(network: Network) -> BlockHeaderHash {