From 405c0644f9fdc4eee7e248d3600d9ca4e665eabd Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 5 Nov 2020 12:57:31 +1000 Subject: [PATCH] Add a comment explaining the issues in ZIPs 205 and 208 And add the network to the difficulty filter error. --- zebra-consensus/src/block/check.rs | 9 ++++++++- zebra-consensus/src/block/tests.rs | 3 ++- zebra-consensus/src/error.rs | 5 ++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/zebra-consensus/src/block/check.rs b/zebra-consensus/src/block/check.rs index eb1ef1bb..b522d0f3 100644 --- a/zebra-consensus/src/block/check.rs +++ b/zebra-consensus/src/block/check.rs @@ -70,12 +70,19 @@ pub fn difficulty_is_valid( ))?; } - // Difficulty filter + // The difficulty filter is also context-free. + // + // ZIP 205 and ZIP 208 incorrectly describe testnet minimum difficulty blocks + // as a change to the difficulty filter. But in `zcashd`, it is implemented + // as a change to the difficulty adjustment algorithm. So we don't need to + // do anything special for testnet here. + // For details, see https://github.com/zcash/zips/issues/416 if hash > &difficulty_threshold { Err(BlockError::DifficultyFilter( *height, *hash, difficulty_threshold, + network, ))?; } diff --git a/zebra-consensus/src/block/tests.rs b/zebra-consensus/src/block/tests.rs index 174d7319..82c8c0d1 100644 --- a/zebra-consensus/src/block/tests.rs +++ b/zebra-consensus/src/block/tests.rs @@ -234,7 +234,8 @@ fn difficulty_validation_failure() -> Result<(), Report> { // Validate the block let result = check::difficulty_is_valid(&block.header, Network::Mainnet, &height, &bad_hash) .unwrap_err(); - let expected = BlockError::DifficultyFilter(height, bad_hash, difficulty_threshold); + let expected = + BlockError::DifficultyFilter(height, bad_hash, difficulty_threshold, Network::Mainnet); assert_eq!(expected, result); Ok(()) diff --git a/zebra-consensus/src/error.rs b/zebra-consensus/src/error.rs index bee2f187..70c002c3 100644 --- a/zebra-consensus/src/error.rs +++ b/zebra-consensus/src/error.rs @@ -108,10 +108,13 @@ pub enum BlockError { zebra_chain::work::difficulty::ExpandedDifficulty, ), - #[error("block {0:?} has a hash {1:?} that is easier than the difficulty threshold {2:?}")] + #[error( + "block {0:?} on {3:?} has a hash {1:?} that is easier than its difficulty threshold {2:?}" + )] DifficultyFilter( zebra_chain::block::Height, zebra_chain::block::Hash, zebra_chain::work::difficulty::ExpandedDifficulty, + zebra_chain::parameters::Network, ), }