Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge of #8491
Browse files Browse the repository at this point in the history
mergify[bot] authored May 7, 2024
2 parents 3e264c7 + 1822439 commit 27daad9
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions zebra-state/src/service/check/difficulty.rs
Original file line number Diff line number Diff line change
@@ -295,15 +295,23 @@ impl AdjustedDifficulty {
fn median_timespan(&self) -> Duration {
let newer_median = self.median_time_past();

let older_times: Vec<_> = self
.relevant_times
.iter()
.rev()
.cloned()
.take(POW_MEDIAN_BLOCK_SPAN)
.collect();

let older_median = AdjustedDifficulty::median_time(older_times);
// MedianTime(height : N) := median([ nTime(𝑖) for 𝑖 from max(0, height − PoWMedianBlockSpan) up to max(0, height − 1) ])
let older_median = if self.relevant_times.len() > POW_AVERAGING_WINDOW {
let older_times: Vec<_> = self
.relevant_times
.iter()
.skip(POW_AVERAGING_WINDOW)
.cloned()
.take(POW_MEDIAN_BLOCK_SPAN)
.collect();

AdjustedDifficulty::median_time(older_times)
} else {
self.relevant_times
.last()
.cloned()
.expect("there must be a Genesis block")
};

// `ActualTimespan` in the Zcash specification
newer_median - older_median

0 comments on commit 27daad9

Please sign in to comment.