From c13907d1af8ae96346dbe32216374780d99316e6 Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 16 Jul 2020 14:04:27 +1000 Subject: [PATCH] fix: Combine two matches --- zebra-consensus/src/checkpoint/list.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/zebra-consensus/src/checkpoint/list.rs b/zebra-consensus/src/checkpoint/list.rs index cbaf5fc00..2e5e70465 100644 --- a/zebra-consensus/src/checkpoint/list.rs +++ b/zebra-consensus/src/checkpoint/list.rs @@ -50,18 +50,14 @@ impl CheckpointList { let checkpoints: BTreeMap = original_checkpoints.into_iter().collect(); - // An empty checkpoint list can't actually verify any blocks. - match checkpoints.keys().next() { - Some(BlockHeight(0)) => {} + // Check that the list starts with the correct genesis block + match checkpoints.iter().next() { + Some((BlockHeight(0), h)) if h == ¶meters::genesis_hash(network) => {} + Some((BlockHeight(0), _)) => { + Err("the genesis checkpoint does not match the network genesis hash")? + } + Some(_) => Err("checkpoints must start at the genesis block height 0")?, None => Err("there must be at least one checkpoint, for the genesis block")?, - _ => Err("checkpoints must start at the genesis block height 0")?, - }; - - // Check the hash of the genesis block against the supplied network - match checkpoints.values().next() { - Some(h) if h == ¶meters::genesis_hash(network) => {} - Some(_) => Err("the genesis checkpoint does not match the network genesis hash")?, - _ => unreachable!("already checked for an empty list"), }; // This check rejects duplicate heights, whether they have the same or