Implement difficulty_threshold_is_valid
This commit is contained in:
parent
750f096a99
commit
678e6ad090
|
|
@ -42,4 +42,8 @@ pub enum ValidateContextError {
|
||||||
/// block.height is not one greater than its parent block's height
|
/// block.height is not one greater than its parent block's height
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
NonSequentialBlock,
|
NonSequentialBlock,
|
||||||
|
|
||||||
|
/// block.header.difficulty_threshold is not equal to the adjusted difficulty for the block
|
||||||
|
#[non_exhaustive]
|
||||||
|
InvalidDifficultyThreshold,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,20 +110,18 @@ fn height_one_more_than_parent_height(
|
||||||
/// Validate the `difficulty_threshold` from a candidate block's header, based
|
/// Validate the `difficulty_threshold` from a candidate block's header, based
|
||||||
/// on an `expected_difficulty` for that block.
|
/// on an `expected_difficulty` for that block.
|
||||||
///
|
///
|
||||||
/// Uses `expected_difficulty` to calculate the expected `ToCompact(Threshold())`
|
/// Uses `expected_difficulty` to calculate the expected difficulty value, then
|
||||||
/// value, then compares that value to the `difficulty_threshold`.
|
/// compares that value to the `difficulty_threshold`.
|
||||||
/// Returns `Ok(())` if the values are equal.
|
///
|
||||||
|
/// The check passes if the values are equal.
|
||||||
fn difficulty_threshold_is_valid(
|
fn difficulty_threshold_is_valid(
|
||||||
difficulty_threshold: CompactDifficulty,
|
difficulty_threshold: CompactDifficulty,
|
||||||
expected_difficulty: AdjustedDifficulty,
|
expected_difficulty: AdjustedDifficulty,
|
||||||
) -> Result<(), ValidateContextError> {
|
) -> 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() {
|
if difficulty_threshold == expected_difficulty.expected_difficulty_threshold() {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
// This is the error case
|
Err(ValidateContextError::InvalidDifficultyThreshold)
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue