Node/EVM: Fix race in network stats (#3493)
This commit is contained in:
parent
33c0adbf82
commit
4f9400ca3d
|
@ -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(),
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue