mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-22 07:49:26 +00:00
core/txpool/legacypool: add metric for accounts in txpool (#33646)
This PR adds metrics that count the number of accounts having transactions in the txpool. Together with the transaction count this can be used as a simple indicator of the diversity of transactions in the pool. Note: as an alternative implementation, we could use a periodic or event driven update of these Gauges using len. I've preferred this implementation to match what we have for the pool sizes. --------- Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
2eb1ccc6c4
commit
54ab4e3c7d
2 changed files with 12 additions and 0 deletions
|
|
@ -114,6 +114,9 @@ var (
|
||||||
queuedGauge = metrics.NewRegisteredGauge("txpool/queued", nil)
|
queuedGauge = metrics.NewRegisteredGauge("txpool/queued", 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)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -844,6 +847,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]
|
||||||
|
|
||||||
|
|
@ -1083,6 +1087,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 {
|
||||||
|
|
@ -1580,6 +1585,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.get(addr); !ok {
|
if _, ok := pool.queue.get(addr); !ok {
|
||||||
pool.reserver.Release(addr)
|
pool.reserver.Release(addr)
|
||||||
}
|
}
|
||||||
|
|
@ -1839,6 +1845,9 @@ func (pool *LegacyPool) Clear() {
|
||||||
pool.pending = make(map[common.Address]*list)
|
pool.pending = make(map[common.Address]*list)
|
||||||
pool.queue = newQueue(pool.config, pool.signer)
|
pool.queue = newQueue(pool.config, pool.signer)
|
||||||
pool.pendingNonces = newNoncer(pool.currentState)
|
pool.pendingNonces = newNoncer(pool.currentState)
|
||||||
|
|
||||||
|
pendingAddrsGauge.Update(0)
|
||||||
|
queuedAddrsGauge.Update(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasPendingAuth returns a flag indicating whether there are pending
|
// HasPendingAuth returns a flag indicating whether there are pending
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,7 @@ func (q *queue) remove(addr common.Address, tx *types.Transaction) {
|
||||||
if future.Empty() {
|
if future.Empty() {
|
||||||
delete(q.queued, addr)
|
delete(q.queued, addr)
|
||||||
delete(q.beats, addr)
|
delete(q.beats, addr)
|
||||||
|
queuedAddrsGauge.Dec(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -123,6 +124,7 @@ func (q *queue) add(tx *types.Transaction) (*common.Hash, error) {
|
||||||
from, _ := types.Sender(q.signer, tx) // already validated
|
from, _ := types.Sender(q.signer, tx) // already validated
|
||||||
if q.queued[from] == nil {
|
if q.queued[from] == nil {
|
||||||
q.queued[from] = newList(false)
|
q.queued[from] = newList(false)
|
||||||
|
queuedAddrsGauge.Inc(1)
|
||||||
}
|
}
|
||||||
inserted, old := q.queued[from].Add(tx, q.config.PriceBump)
|
inserted, old := q.queued[from].Add(tx, q.config.PriceBump)
|
||||||
if !inserted {
|
if !inserted {
|
||||||
|
|
@ -200,6 +202,7 @@ func (q *queue) promoteExecutables(accounts []common.Address, gasLimit uint64, c
|
||||||
if list.Empty() {
|
if list.Empty() {
|
||||||
delete(q.queued, addr)
|
delete(q.queued, addr)
|
||||||
delete(q.beats, addr)
|
delete(q.beats, addr)
|
||||||
|
queuedAddrsGauge.Dec(1)
|
||||||
removedAddresses = append(removedAddresses, addr)
|
removedAddresses = append(removedAddresses, addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue