From 4f9400ca3d6ca636369c105edac28059b0816ddd Mon Sep 17 00:00:00 2001 From: bruce-riley <96066700+bruce-riley@users.noreply.github.com> Date: Thu, 2 Nov 2023 16:05:07 -0500 Subject: [PATCH] Node/EVM: Fix race in network stats (#3493) --- node/pkg/watchers/evm/watcher.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/node/pkg/watchers/evm/watcher.go b/node/pkg/watchers/evm/watcher.go index 17eb4fb1e..2b6303715 100644 --- a/node/pkg/watchers/evm/watcher.go +++ b/node/pkg/watchers/evm/watcher.go @@ -615,7 +615,7 @@ func (w *Watcher) Run(parentCtx context.Context) error { atomic.StoreUint64(&w.latestBlockNumber, blockNumberU) currentEthHeight.WithLabelValues(w.networkName).Set(float64(blockNumberU)) stats.Height = int64(blockNumberU) - p2p.DefaultRegistry.SetNetworkStats(w.chainID, &stats) + w.updateNetworkStats(&stats) continue } @@ -630,7 +630,7 @@ func (w *Watcher) Run(parentCtx context.Context) error { currentEthFinalizedHeight.WithLabelValues(w.networkName).Set(float64(blockNumberU)) stats.FinalizedHeight = int64(blockNumberU) } - p2p.DefaultRegistry.SetNetworkStats(w.chainID, &stats) + w.updateNetworkStats(&stats) w.pendingMu.Lock() for key, pLock := range w.pending { @@ -926,3 +926,12 @@ func (w *Watcher) SetWaitForConfirmations(waitForConfirmations bool) { func (w *Watcher) SetMaxWaitConfirmations(maxWaitConfirmations uint64) { w.maxWaitConfirmations = maxWaitConfirmations } + +func (w *Watcher) updateNetworkStats(stats *gossipv1.Heartbeat_Network) { + p2p.DefaultRegistry.SetNetworkStats(w.chainID, &gossipv1.Heartbeat_Network{ + Height: stats.Height, + SafeHeight: stats.SafeHeight, + FinalizedHeight: stats.FinalizedHeight, + ContractAddress: w.contract.Hex(), + }) +}