From 07b27342f3fc3997629fd74e6720daae50ceda26 Mon Sep 17 00:00:00 2001 From: ucwong Date: Sat, 24 Jan 2026 10:48:03 +0800 Subject: [PATCH] new stats collector --- core/txpool/queue.go | 2 ++ core/txpool/txpool.go | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/core/txpool/queue.go b/core/txpool/queue.go index 8b0157807a..eb121c0e0c 100644 --- a/core/txpool/queue.go +++ b/core/txpool/queue.go @@ -120,6 +120,7 @@ func (q *queue) add(tx *types.Transaction) (*common.Hash, error) { from, _ := types.Sender(q.signer, tx) // already validated if q.queued[from] == nil { q.queued[from] = newList(false) + queuedAddrsGauge.Inc(1) } inserted, old := q.queued[from].Add(tx, q.config.PriceBump) if !inserted { @@ -196,6 +197,7 @@ func (q *queue) promoteExecutables(accounts []common.Address, gasLimit uint64, c if list.Empty() { delete(q.queued, addr) delete(q.beats, addr) + queuedAddrsGauge.Dec(1) removedAddresses = append(removedAddresses, addr) } } diff --git a/core/txpool/txpool.go b/core/txpool/txpool.go index fc6ff4c3a9..89f880bd13 100644 --- a/core/txpool/txpool.go +++ b/core/txpool/txpool.go @@ -134,6 +134,9 @@ var ( slotsGauge = metrics.NewRegisteredGauge("txpool/slots", nil) + pendingAddrsGauge = metrics.NewRegisteredGauge("txpool/pending/accounts", nil) + queuedAddrsGauge = metrics.NewRegisteredGauge("txpool/queued/accounts", nil) + reheapTimer = metrics.NewRegisteredTimer("txpool/reheap", nil) ) @@ -863,6 +866,7 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T // Try to insert the transaction into the pending queue if pool.pending[addr] == nil { pool.pending[addr] = newList(true) + pendingAddrsGauge.Inc(1) } list := pool.pending[addr] @@ -1073,6 +1077,7 @@ func (pool *TxPool) removeTx(hash common.Hash, outofbound bool, unreserve bool) // If no more pending transactions are left, remove the list if pending.Empty() { delete(pool.pending, addr) + pendingAddrsGauge.Dec(1) } // Postpone any invalidated transactions for _, tx := range invalids { @@ -1365,6 +1370,9 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) { pool.currentState = statedb pool.pendingNonces = newNoncer(statedb) + pendingAddrsGauge.Update(0) + queuedAddrsGauge.Update(0) + // Inject any transactions discarded due to reorgs log.Debug("Reinjecting stale transactions", "count", len(reinject)) core.SenderCacher.Recover(pool.signer, reinject) @@ -1568,6 +1576,7 @@ func (pool *TxPool) demoteUnexecutables() { // Delete the entire pending entry if it became empty. if list.Empty() { delete(pool.pending, addr) + pendingAddrsGauge.Dec(1) if _, ok := pool.queue.get(addr); !ok { pool.reserver.Release(addr) }