consensus: replace type assert with test (#4398)

If `consensus.finalityCounter` does not have anything stored (for
example in Syncing mode), the `Load()` returns an interface that cannot
be automatically asserted to an `int64`. This results in the node
crashing. This commit fixes that.
pull/4400/head
Max 2 years ago committed by GitHub
parent 941a92b744
commit 7d5eb9cd36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      consensus/consensus_service.go

@ -538,8 +538,10 @@ func (consensus *Consensus) StartFinalityCount() {
// FinishFinalityCount calculate the current finality
func (consensus *Consensus) FinishFinalityCount() {
d := time.Now().UnixNano()
consensus.finality = (d - consensus.finalityCounter.Load().(int64)) / 1000000
consensusFinalityHistogram.Observe(float64(consensus.finality))
if prior, ok := consensus.finalityCounter.Load().(int64); ok {
consensus.finality = (d - prior) / 1000000
consensusFinalityHistogram.Observe(float64(consensus.finality))
}
}
// GetFinality returns the finality time in milliseconds of previous consensus

Loading…
Cancel
Save