From bcabf75fe98071078f588d4d313e56500e965a63 Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 19 Nov 2020 11:06:28 +1000 Subject: [PATCH] Replace integer lengths with named constants --- zebra-state/src/service/check/difficulty.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/zebra-state/src/service/check/difficulty.rs b/zebra-state/src/service/check/difficulty.rs index a35c5c7a7..a8d34b0da 100644 --- a/zebra-state/src/service/check/difficulty.rs +++ b/zebra-state/src/service/check/difficulty.rs @@ -35,14 +35,15 @@ pub(super) struct AdjustedDifficulty { /// The `header.difficulty_threshold`s from the previous /// `PoWAveragingWindow + PoWMedianBlockSpan` (28) blocks, in reverse height /// order. - relevant_difficulty_thresholds: [CompactDifficulty; 28], + relevant_difficulty_thresholds: + [CompactDifficulty; POW_AVERAGING_WINDOW + POW_MEDIAN_BLOCK_SPAN], /// The `header.time`s from the previous /// `PoWAveragingWindow + PoWMedianBlockSpan` (28) blocks, in reverse height /// order. /// /// Only the first and last `PoWMedianBlockSpan` times are used. Times /// `11..=16` are ignored. - relevant_times: [DateTime; 28], + relevant_times: [DateTime; POW_AVERAGING_WINDOW + POW_MEDIAN_BLOCK_SPAN], } impl AdjustedDifficulty { @@ -216,7 +217,9 @@ impl AdjustedDifficulty { /// slice of `PoWMedianBlockSpan` (11) blocks in the relevant chain. /// /// Implements `MedianTime` from the Zcash specification. - fn median_time(mut median_block_span_times: [DateTime; 11]) -> DateTime { + fn median_time( + mut median_block_span_times: [DateTime; POW_MEDIAN_BLOCK_SPAN], + ) -> DateTime { median_block_span_times.sort_unstable(); median_block_span_times[POW_MEDIAN_BLOCK_SPAN / 2] }