diff --git a/zebra-state/src/error.rs b/zebra-state/src/error.rs index 2b2bdb794..67d17f27f 100644 --- a/zebra-state/src/error.rs +++ b/zebra-state/src/error.rs @@ -42,4 +42,8 @@ pub enum ValidateContextError { /// block.height is not one greater than its parent block's height #[non_exhaustive] NonSequentialBlock, + + /// block.header.difficulty_threshold is not equal to the adjusted difficulty for the block + #[non_exhaustive] + InvalidDifficultyThreshold, } diff --git a/zebra-state/src/service/check.rs b/zebra-state/src/service/check.rs index c718e31ab..72808e704 100644 --- a/zebra-state/src/service/check.rs +++ b/zebra-state/src/service/check.rs @@ -110,20 +110,18 @@ fn height_one_more_than_parent_height( /// Validate the `difficulty_threshold` from a candidate block's header, based /// on an `expected_difficulty` for that block. /// -/// Uses `expected_difficulty` to calculate the expected `ToCompact(Threshold())` -/// value, then compares that value to the `difficulty_threshold`. -/// Returns `Ok(())` if the values are equal. +/// Uses `expected_difficulty` to calculate the expected difficulty value, then +/// compares that value to the `difficulty_threshold`. +/// +/// The check passes if the values are equal. fn difficulty_threshold_is_valid( difficulty_threshold: CompactDifficulty, expected_difficulty: AdjustedDifficulty, ) -> Result<(), ValidateContextError> { - // TODO: return an error on failure, after the calculation is implemented - #[allow(clippy::if_same_then_else)] if difficulty_threshold == expected_difficulty.expected_difficulty_threshold() { Ok(()) } else { - // This is the error case - Ok(()) + Err(ValidateContextError::InvalidDifficultyThreshold) } }