Skip to content

Commit 1798eec

Browse files
committed
fix DifficultyMetrics off-by-1
1 parent 0538280 commit 1798eec

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

persist/sqlite/metrics.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,10 @@ func (s *Store) DifficultyMetrics(start, end, step uint64, n *consensus.Network)
286286
return nil
287287
}
288288

289-
// We need blocktime deltas, so offset the range by 1 (if possible)
289+
// We need blocktime deltas, so offset the range by one step (if possible)
290290
queryStart := start
291-
if start > 0 {
292-
queryStart = start - 1
291+
if start >= step {
292+
queryStart = start - step
293293
}
294294
query := `SELECT nm.difficulty, b.timestamp
295295
FROM network_metrics nm
@@ -334,7 +334,7 @@ func (s *Store) DifficultyMetrics(start, end, step uint64, n *consensus.Network)
334334
}
335335

336336
// trim if necessary
337-
if start > 0 {
337+
if start >= step {
338338
result.Difficulties = result.Difficulties[1:]
339339
result.BlockTimes = result.BlockTimes[1:]
340340
result.Drifts = result.Drifts[1:]

0 commit comments

Comments
 (0)