core/txpool/legacypool: add metric for accounts in txpool #33646 (#1980)

This commit is contained in:
Daniel Liu 2026-01-29 13:52:31 +08:00 committed by GitHub
parent b5e617fee0
commit 0206909058
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -122,6 +122,9 @@ var (
localGauge = metrics.NewRegisteredGauge("txpool/local", nil) localGauge = metrics.NewRegisteredGauge("txpool/local", nil)
slotsGauge = metrics.NewRegisteredGauge("txpool/slots", nil) 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) reheapTimer = metrics.NewRegisteredTimer("txpool/reheap", nil)
) )
@ -974,6 +977,7 @@ func (pool *LegacyPool) enqueueTx(hash common.Hash, tx *types.Transaction, local
from, _ := types.Sender(pool.signer, tx) // already validated from, _ := types.Sender(pool.signer, tx) // already validated
if pool.queue[from] == nil { if pool.queue[from] == nil {
pool.queue[from] = newList(false) pool.queue[from] = newList(false)
queuedAddrsGauge.Inc(1)
} }
inserted, old := pool.queue[from].Add(tx, pool.config.PriceBump) inserted, old := pool.queue[from].Add(tx, pool.config.PriceBump)
if !inserted { if !inserted {
@ -1026,6 +1030,7 @@ func (pool *LegacyPool) promoteTx(addr common.Address, hash common.Hash, tx *typ
// Try to insert the transaction into the pending queue // Try to insert the transaction into the pending queue
if pool.pending[addr] == nil { if pool.pending[addr] == nil {
pool.pending[addr] = newList(true) pool.pending[addr] = newList(true)
pendingAddrsGauge.Inc(1)
} }
list := pool.pending[addr] list := pool.pending[addr]
@ -1059,6 +1064,7 @@ func (pool *LegacyPool) promoteSpecialTx(addr common.Address, tx *types.Transact
// Try to insert the transaction into the pending queue // Try to insert the transaction into the pending queue
if pool.pending[addr] == nil { if pool.pending[addr] == nil {
pool.pending[addr] = newList(true) pool.pending[addr] = newList(true)
pendingAddrsGauge.Inc(1)
} }
list := pool.pending[addr] list := pool.pending[addr]
@ -1299,6 +1305,7 @@ func (pool *LegacyPool) removeTx(hash common.Hash, outofbound bool, unreserve bo
// If no more pending transactions are left, remove the list // If no more pending transactions are left, remove the list
if pending.Empty() { if pending.Empty() {
delete(pool.pending, addr) delete(pool.pending, addr)
pendingAddrsGauge.Dec(1)
} }
// Postpone any invalidated transactions // Postpone any invalidated transactions
for _, tx := range invalids { for _, tx := range invalids {
@ -1321,6 +1328,7 @@ func (pool *LegacyPool) removeTx(hash common.Hash, outofbound bool, unreserve bo
if future.Empty() { if future.Empty() {
delete(pool.queue, addr) delete(pool.queue, addr)
delete(pool.beats, addr) delete(pool.beats, addr)
queuedAddrsGauge.Dec(1)
} }
} }
return 0 return 0
@ -1676,6 +1684,7 @@ func (pool *LegacyPool) promoteExecutables(accounts []common.Address) []*types.T
if list.Empty() { if list.Empty() {
delete(pool.queue, addr) delete(pool.queue, addr)
delete(pool.beats, addr) delete(pool.beats, addr)
queuedAddrsGauge.Dec(1)
if _, ok := pool.pending[addr]; !ok { if _, ok := pool.pending[addr]; !ok {
pool.reserver.Release(addr) pool.reserver.Release(addr)
} }
@ -1876,6 +1885,7 @@ func (pool *LegacyPool) demoteUnexecutables() {
// Delete the entire pending entry if it became empty. // Delete the entire pending entry if it became empty.
if list.Empty() { if list.Empty() {
delete(pool.pending, addr) delete(pool.pending, addr)
pendingAddrsGauge.Dec(1)
if _, ok := pool.queue[addr]; !ok { if _, ok := pool.queue[addr]; !ok {
pool.reserver.Release(addr) pool.reserver.Release(addr)
} }
@ -2241,6 +2251,10 @@ func (pool *LegacyPool) Clear() {
pool.pending = make(map[common.Address]*list) pool.pending = make(map[common.Address]*list)
pool.queue = make(map[common.Address]*list) pool.queue = make(map[common.Address]*list)
pool.pendingNonces = newNoncer(pool.currentState) pool.pendingNonces = newNoncer(pool.currentState)
// Reset gauges
pendingAddrsGauge.Update(0)
queuedAddrsGauge.Update(0)
} }
// HasPendingAuth returns a flag indicating whether there are pending // HasPendingAuth returns a flag indicating whether there are pending