From 7d5eb9cd36e2b6b8c43f893f1f720ac75d7c39dc Mon Sep 17 00:00:00 2001 From: Max <82761650+MaxMustermann2@users.noreply.github.com> Date: Wed, 5 Apr 2023 16:04:27 +0000 Subject: [PATCH] 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. --- consensus/consensus_service.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/consensus/consensus_service.go b/consensus/consensus_service.go index 0e4bb6814..aac91fbd1 100644 --- a/consensus/consensus_service.go +++ b/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