fix: Hard-code the genesis previous block hash

This commit is contained in:
teor 2020-07-16 13:59:44 +10:00 committed by Henry de Valence
parent 39e67c8748
commit b648375bbe
2 changed files with 6 additions and 15 deletions

View File

@ -85,9 +85,6 @@ pub const MAX_QUEUED_BLOCKS_PER_HEIGHT: usize = 4;
struct CheckpointVerifier { struct CheckpointVerifier {
// Inputs // Inputs
// //
/// The network for this verifier.
network: Network,
/// The checkpoint list for this verifier. /// The checkpoint list for this verifier.
checkpoint_list: CheckpointList, checkpoint_list: CheckpointList,
@ -130,7 +127,6 @@ impl CheckpointVerifier {
checkpoint_list: impl IntoIterator<Item = (BlockHeight, BlockHeaderHash)>, checkpoint_list: impl IntoIterator<Item = (BlockHeight, BlockHeaderHash)>,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
Ok(CheckpointVerifier { Ok(CheckpointVerifier {
network,
checkpoint_list: CheckpointList::new(network, checkpoint_list)?, checkpoint_list: CheckpointList::new(network, checkpoint_list)?,
queued: BTreeMap::new(), queued: BTreeMap::new(),
// We start by verifying the genesis block, by itself // 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 // Since genesis blocks are hard-coded in zcashd, and not verified
// like other blocks, the genesis parent hash is set by the // like other blocks, the genesis parent hash is set by the
// consensus parameters. // consensus parameters.
BeforeGenesis => parameters::genesis_previous_block_hash(self.network), BeforeGenesis => parameters::GENESIS_PREVIOUS_BLOCK_HASH,
PreviousCheckpoint(hash) => hash, PreviousCheckpoint(hash) => hash,
FinalCheckpoint => return, FinalCheckpoint => return,
}; };

View File

@ -12,16 +12,11 @@
use zebra_chain::block::BlockHeaderHash; use zebra_chain::block::BlockHeaderHash;
use zebra_chain::{Network, Network::*}; use zebra_chain::{Network, Network::*};
/// Returns the previous block hash for the genesis block in `network`. /// The previous block hash for the genesis block.
pub fn genesis_previous_block_hash(network: Network) -> BlockHeaderHash { ///
// All current networks use all-zeroes for the parent of the genesis block. /// All known networks use the Bitcoin `null` value for the parent of the
// (In Bitcoin, `null` is `[0; 32]`.) /// genesis block. (In Bitcoin, `null` is `[0; 32]`.)
// pub const GENESIS_PREVIOUS_BLOCK_HASH: BlockHeaderHash = BlockHeaderHash([0; 32]);
// TODO: make this function const when feature(const_if_match) stabilises.
match network {
Mainnet | Testnet => BlockHeaderHash([0; 32]),
}
}
/// Returns the hash for the genesis block in `network`. /// Returns the hash for the genesis block in `network`.
pub fn genesis_hash(network: Network) -> BlockHeaderHash { pub fn genesis_hash(network: Network) -> BlockHeaderHash {