github.com/MetalBlockchain/subnet-evm@v0.4.9/plugin/evm/gossip_stats.go (about) 1 // (c) 2022, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package evm 5 6 import "github.com/MetalBlockchain/subnet-evm/metrics" 7 8 var _ GossipStats = &gossipStats{} 9 10 // GossipStats contains methods for updating incoming and outgoing gossip stats. 11 type GossipStats interface { 12 GossipReceivedStats 13 GossipSentStats 14 } 15 16 // GossipReceivedStats groups functions for incoming gossip stats. 17 type GossipReceivedStats interface { 18 IncEthTxsGossipReceived() 19 20 // new vs. known txs received 21 IncEthTxsGossipReceivedKnown() 22 IncEthTxsGossipReceivedNew() 23 } 24 25 // GossipSentStats groups functions for outgoing gossip stats. 26 type GossipSentStats interface { 27 IncEthTxsGossipSent() 28 29 // regossip 30 IncEthTxsRegossipQueued() 31 IncEthTxsRegossipQueuedLocal(count int) 32 IncEthTxsRegossipQueuedRemote(count int) 33 } 34 35 // gossipStats implements stats for incoming and outgoing gossip stats. 36 type gossipStats struct { 37 // messages 38 ethTxsGossipSent metrics.Counter 39 ethTxsGossipReceived metrics.Counter 40 41 // regossip 42 ethTxsRegossipQueued metrics.Counter 43 ethTxsRegossipQueuedLocal metrics.Counter 44 ethTxsRegossipQueuedRemote metrics.Counter 45 46 // new vs. known txs received 47 ethTxsGossipReceivedKnown metrics.Counter 48 ethTxsGossipReceivedNew metrics.Counter 49 } 50 51 func NewGossipStats() GossipStats { 52 return &gossipStats{ 53 ethTxsGossipSent: metrics.GetOrRegisterCounter("gossip_eth_txs_sent", nil), 54 ethTxsGossipReceived: metrics.GetOrRegisterCounter("gossip_eth_txs_received", nil), 55 56 ethTxsRegossipQueued: metrics.GetOrRegisterCounter("regossip_eth_txs_queued_attempts", nil), 57 ethTxsRegossipQueuedLocal: metrics.GetOrRegisterCounter("regossip_eth_txs_queued_local_tx_count", nil), 58 ethTxsRegossipQueuedRemote: metrics.GetOrRegisterCounter("regossip_eth_txs_queued_remote_tx_count", nil), 59 60 ethTxsGossipReceivedKnown: metrics.GetOrRegisterCounter("gossip_eth_txs_received_known", nil), 61 ethTxsGossipReceivedNew: metrics.GetOrRegisterCounter("gossip_eth_txs_received_new", nil), 62 } 63 } 64 65 // incoming messages 66 func (g *gossipStats) IncEthTxsGossipReceived() { g.ethTxsGossipReceived.Inc(1) } 67 68 // new vs. known txs received 69 func (g *gossipStats) IncEthTxsGossipReceivedKnown() { g.ethTxsGossipReceivedKnown.Inc(1) } 70 func (g *gossipStats) IncEthTxsGossipReceivedNew() { g.ethTxsGossipReceivedNew.Inc(1) } 71 72 // outgoing messages 73 func (g *gossipStats) IncEthTxsGossipSent() { g.ethTxsGossipSent.Inc(1) } 74 75 // regossip 76 func (g *gossipStats) IncEthTxsRegossipQueued() { g.ethTxsRegossipQueued.Inc(1) } 77 func (g *gossipStats) IncEthTxsRegossipQueuedLocal(count int) { 78 g.ethTxsRegossipQueuedLocal.Inc(int64(count)) 79 } 80 func (g *gossipStats) IncEthTxsRegossipQueuedRemote(count int) { 81 g.ethTxsRegossipQueuedRemote.Inc(int64(count)) 82 }