github.com/dim4egster/coreth@v0.10.2/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/dim4egster/coreth/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  	IncAtomicGossipReceived()
    19  	IncEthTxsGossipReceived()
    20  
    21  	// new vs. known txs received
    22  	IncAtomicGossipReceivedDropped()
    23  	IncAtomicGossipReceivedError()
    24  	IncAtomicGossipReceivedKnown()
    25  	IncAtomicGossipReceivedNew()
    26  	IncEthTxsGossipReceivedKnown()
    27  	IncEthTxsGossipReceivedNew()
    28  }
    29  
    30  // GossipSentStats groups functions for outgoing gossip stats.
    31  type GossipSentStats interface {
    32  	IncAtomicGossipSent()
    33  	IncEthTxsGossipSent()
    34  
    35  	// regossip
    36  	IncEthTxsRegossipQueued()
    37  	IncEthTxsRegossipQueuedLocal(count int)
    38  	IncEthTxsRegossipQueuedRemote(count int)
    39  }
    40  
    41  // gossipStats implements stats for incoming and outgoing gossip stats.
    42  type gossipStats struct {
    43  	// messages
    44  	atomicGossipSent     metrics.Counter
    45  	atomicGossipReceived metrics.Counter
    46  	ethTxsGossipSent     metrics.Counter
    47  	ethTxsGossipReceived metrics.Counter
    48  
    49  	// regossip
    50  	ethTxsRegossipQueued       metrics.Counter
    51  	ethTxsRegossipQueuedLocal  metrics.Counter
    52  	ethTxsRegossipQueuedRemote metrics.Counter
    53  
    54  	// new vs. known txs received
    55  	atomicGossipReceivedDropped metrics.Counter
    56  	atomicGossipReceivedError   metrics.Counter
    57  	atomicGossipReceivedKnown   metrics.Counter
    58  	atomicGossipReceivedNew     metrics.Counter
    59  	ethTxsGossipReceivedKnown   metrics.Counter
    60  	ethTxsGossipReceivedNew     metrics.Counter
    61  }
    62  
    63  func NewGossipStats() GossipStats {
    64  	return &gossipStats{
    65  		atomicGossipSent:     metrics.GetOrRegisterCounter("gossip_atomic_sent", nil),
    66  		atomicGossipReceived: metrics.GetOrRegisterCounter("gossip_atomic_received", nil),
    67  		ethTxsGossipSent:     metrics.GetOrRegisterCounter("gossip_eth_txs_sent", nil),
    68  		ethTxsGossipReceived: metrics.GetOrRegisterCounter("gossip_eth_txs_received", nil),
    69  
    70  		ethTxsRegossipQueued:       metrics.GetOrRegisterCounter("regossip_eth_txs_queued_attempts", nil),
    71  		ethTxsRegossipQueuedLocal:  metrics.GetOrRegisterCounter("regossip_eth_txs_queued_local_tx_count", nil),
    72  		ethTxsRegossipQueuedRemote: metrics.GetOrRegisterCounter("regossip_eth_txs_queued_remote_tx_count", nil),
    73  
    74  		atomicGossipReceivedDropped: metrics.GetOrRegisterCounter("gossip_atomic_received_dropped", nil),
    75  		atomicGossipReceivedError:   metrics.GetOrRegisterCounter("gossip_atomic_received_error", nil),
    76  		atomicGossipReceivedKnown:   metrics.GetOrRegisterCounter("gossip_atomic_received_known", nil),
    77  		atomicGossipReceivedNew:     metrics.GetOrRegisterCounter("gossip_atomic_received_new", nil),
    78  		ethTxsGossipReceivedKnown:   metrics.GetOrRegisterCounter("gossip_eth_txs_received_known", nil),
    79  		ethTxsGossipReceivedNew:     metrics.GetOrRegisterCounter("gossip_eth_txs_received_new", nil),
    80  	}
    81  }
    82  
    83  // incoming messages
    84  func (g *gossipStats) IncAtomicGossipReceived() { g.atomicGossipReceived.Inc(1) }
    85  func (g *gossipStats) IncEthTxsGossipReceived() { g.ethTxsGossipReceived.Inc(1) }
    86  
    87  // new vs. known txs received
    88  func (g *gossipStats) IncAtomicGossipReceivedDropped() { g.atomicGossipReceivedDropped.Inc(1) }
    89  func (g *gossipStats) IncAtomicGossipReceivedError()   { g.atomicGossipReceivedError.Inc(1) }
    90  func (g *gossipStats) IncAtomicGossipReceivedKnown()   { g.atomicGossipReceivedKnown.Inc(1) }
    91  func (g *gossipStats) IncAtomicGossipReceivedNew()     { g.atomicGossipReceivedNew.Inc(1) }
    92  func (g *gossipStats) IncEthTxsGossipReceivedKnown()   { g.ethTxsGossipReceivedKnown.Inc(1) }
    93  func (g *gossipStats) IncEthTxsGossipReceivedNew()     { g.ethTxsGossipReceivedNew.Inc(1) }
    94  
    95  // outgoing messages
    96  func (g *gossipStats) IncAtomicGossipSent() { g.atomicGossipSent.Inc(1) }
    97  func (g *gossipStats) IncEthTxsGossipSent() { g.ethTxsGossipSent.Inc(1) }
    98  
    99  // regossip
   100  func (g *gossipStats) IncEthTxsRegossipQueued() { g.ethTxsRegossipQueued.Inc(1) }
   101  func (g *gossipStats) IncEthTxsRegossipQueuedLocal(count int) {
   102  	g.ethTxsRegossipQueuedLocal.Inc(int64(count))
   103  }
   104  func (g *gossipStats) IncEthTxsRegossipQueuedRemote(count int) {
   105  	g.ethTxsRegossipQueuedRemote.Inc(int64(count))
   106  }