Skip to content

Commit

Permalink
add metrics for cacheForMiner
Browse files Browse the repository at this point in the history
  • Loading branch information
andyzhang2023 committed Mar 15, 2024
1 parent 4169362 commit 55aeb2d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions core/txpool/legacypool/cache_for_miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/txpool"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/metrics"
)

var (
pendingCacheGauge = metrics.NewRegisteredGauge("txpool/legacypool/pending/cache", nil)
localCacheGauge = metrics.NewRegisteredGauge("txpool/legacypool/local/cache", nil)
)

// copy of pending transactions
Expand All @@ -27,6 +33,7 @@ func (pc *cacheForMiner) add(txs types.Transactions, signer types.Signer) {
}
pc.txLock.Lock()
defer pc.txLock.Unlock()
pendingCacheGauge.Inc(int64(len(txs)))
for _, tx := range txs {
addr, _ := types.Sender(signer, tx)
slots, ok := pc.pending[addr]
Expand All @@ -50,6 +57,7 @@ func (pc *cacheForMiner) del(txs types.Transactions, signer types.Signer) {
if !ok {
continue
}
pendingCacheGauge.Dec(1)
delete(slots, tx)
if len(slots) == 0 {
delete(pc.pending, addr)
Expand Down Expand Up @@ -124,6 +132,7 @@ func (pc *cacheForMiner) pendingTxs(enforceTips bool) map[common.Address][]*txpo
func (pc *cacheForMiner) markLocal(addr common.Address) {
pc.addrLock.Lock()
defer pc.addrLock.Unlock()
localCacheGauge.Inc(1)
pc.locals[addr] = true
}

Expand Down

0 comments on commit 55aeb2d

Please sign in to comment.