Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions internal/pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,17 +529,17 @@ func (d *Daemon) performUpgrade(
}

func (d *Daemon) updateHeightAndBlockSpeed(newHeight int64) {
// calculate block speed based on the last few observed blocks
if d.currHeight == newHeight {
return
}

lastBlockHeight := d.currHeight
lastHeightTime := d.currHeightTime
d.currHeight = newHeight
d.currHeightTime = time.Now()

// this may happen when polling
if d.currHeight != lastBlockHeight {
n := newHeight % int64(cap(d.observedBlockSpeeds))
d.observedBlockSpeeds[n] = time.Millisecond * time.Duration(d.currHeightTime.Sub(lastHeightTime).Milliseconds()/(d.currHeight-lastBlockHeight))
}
n := newHeight % int64(cap(d.observedBlockSpeeds))
d.observedBlockSpeeds[n] = time.Millisecond * time.Duration(d.currHeightTime.Sub(lastHeightTime).Milliseconds()/(d.currHeight-lastBlockHeight))

sum, cnt := 0.0, 0
for _, blockSpeed := range d.observedBlockSpeeds {
Expand Down
Loading