Add a comment explaining the issues in ZIPs 205 and 208

And add the network to the difficulty filter error.
This commit is contained in:
teor 2020-11-05 12:57:31 +10:00
parent a7ad73feac
commit 405c0644f9
3 changed files with 14 additions and 3 deletions

View File

@ -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,
))?;
}

View File

@ -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(())

View File

@ -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,
),
}