diff --git a/node/metrics.go b/node/metrics.go index 800c4048e9..5b7fc53ce7 100644 --- a/node/metrics.go +++ b/node/metrics.go @@ -200,6 +200,7 @@ func (g *Metrics) collectOnchainMetrics() { } quorumIds := eth.BitmapToQuorumIds(bitmaps[0]) if len(quorumIds) == 0 { + g.ResetQuorumMetrics(blockNum) g.logger.Warn("This node is currently not in any quorum", "blockNumber", blockNum, "operatorId", g.operatorId.Hex()) continue } @@ -236,16 +237,20 @@ func (g *Metrics) collectOnchainMetrics() { } } // Check if operator deregistered for an existing quorum, set the stake share and rank to 0 - for q := range g.allQuorumCache { - // If this quorum was deregistered then set the stake share and rank to 0 - if !g.allQuorumCache[q] { - g.RegisteredQuorumsStakeShare.WithLabelValues(fmt.Sprintf("%d", q)).Set(0) - g.RegisteredQuorumsRank.WithLabelValues(fmt.Sprintf("%d", q)).Set(0) - g.logger.Info("Current operator deregistration onchain", "operatorId", g.operatorId.Hex(), "blockNumber", blockNum, "quorumId", q) - } else { - // Reset the cache to false for all quorum for next cycle - g.allQuorumCache[q] = false - } + g.ResetQuorumMetrics(blockNum) + } +} + +func (g *Metrics) ResetQuorumMetrics(blockNum uint32) { + // Check if operator deregistered for an existing quorum, set the stake share and rank to 0 + for q := range g.allQuorumCache { + // If this quorum was deregistered then set the stake share and rank to 0 + if !g.allQuorumCache[q] { + g.RegisteredQuorumsStakeShare.WithLabelValues(fmt.Sprintf("%d", q)).Set(0) + g.RegisteredQuorumsRank.WithLabelValues(fmt.Sprintf("%d", q)).Set(0) + g.logger.Info("Current operator deregistration onchain", "operatorId", g.operatorId.Hex(), "blockNumber", blockNum, "quorumId", q) } + // Reset the cache to false for all quorum for next cycle + g.allQuorumCache[q] = false } }