From f1a0036824a8a69ee374a5880d1a67c8db2e9a58 Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 21 Jul 2020 11:33:22 +1000 Subject: [PATCH] feature: Expect the hard-coded checkpoint lists to parse --- zebra-consensus/src/checkpoint.rs | 4 ++-- zebra-consensus/src/checkpoint/list.rs | 16 +++++++++++----- zebra-consensus/src/checkpoint/tests.rs | 3 +-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/zebra-consensus/src/checkpoint.rs b/zebra-consensus/src/checkpoint.rs index ebed8efb6..fe79b9ade 100644 --- a/zebra-consensus/src/checkpoint.rs +++ b/zebra-consensus/src/checkpoint.rs @@ -122,8 +122,8 @@ impl CheckpointVerifier { // Until we implement the overall verifier in #516, this function, and some of the // functions and enum variants it uses, are only used in the tests. #[allow(dead_code)] - pub fn new(network: Network) -> Result { - Ok(Self::from_checkpoint_list(CheckpointList::new(network)?)) + pub fn new(network: Network) -> Self { + Self::from_checkpoint_list(CheckpointList::new(network)) } /// Return a checkpoint verification service using `list`. diff --git a/zebra-consensus/src/checkpoint/list.rs b/zebra-consensus/src/checkpoint/list.rs index 0e5dbc635..45b1bdf47 100644 --- a/zebra-consensus/src/checkpoint/list.rs +++ b/zebra-consensus/src/checkpoint/list.rs @@ -61,16 +61,22 @@ impl FromStr for CheckpointList { impl CheckpointList { /// Returns the hard-coded checkpoint list for `network`. - pub fn new(network: Network) -> Result { + pub fn new(network: Network) -> Self { // parse calls CheckpointList::from_list let checkpoint_list: CheckpointList = match network { - Mainnet => MAINNET_CHECKPOINTS.parse()?, - Testnet => TESTNET_CHECKPOINTS.parse()?, + Mainnet => MAINNET_CHECKPOINTS + .parse() + .expect("Hard-coded Mainnet checkpoint list parses and validates"), + Testnet => TESTNET_CHECKPOINTS + .parse() + .expect("Hard-coded Testnet checkpoint list parses and validates"), }; match checkpoint_list.hash(BlockHeight(0)) { - Some(hash) if hash == parameters::genesis_hash(network) => Ok(checkpoint_list), - Some(_) => Err("the genesis checkpoint does not match the network genesis hash")?, + Some(hash) if hash == parameters::genesis_hash(network) => checkpoint_list, + Some(_) => { + panic!("The hard-coded genesis checkpoint does not match the network genesis hash") + } None => unreachable!("Parser should have checked for a missing genesis checkpoint"), } } diff --git a/zebra-consensus/src/checkpoint/tests.rs b/zebra-consensus/src/checkpoint/tests.rs index 3933fa368..2e883f0d3 100644 --- a/zebra-consensus/src/checkpoint/tests.rs +++ b/zebra-consensus/src/checkpoint/tests.rs @@ -688,8 +688,7 @@ async fn hard_coded_mainnet() -> Result<(), Report> { let hash0: BlockHeaderHash = block0.as_ref().into(); // Use the hard-coded checkpoint list - let mut checkpoint_verifier = - CheckpointVerifier::new(Network::Mainnet).map_err(|e| eyre!(e))?; + let mut checkpoint_verifier = CheckpointVerifier::new(Network::Mainnet); assert_eq!( checkpoint_verifier.previous_checkpoint_height(),