mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
core: Add metrics collection for transaction events; replace/discard for pending and future queues, as well as invalid transactions
This commit is contained in:
parent
6952fe3a5c
commit
523c411517
1 changed files with 15 additions and 0 deletions
|
|
@ -30,6 +30,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/logger/glog"
|
"github.com/ethereum/go-ethereum/logger/glog"
|
||||||
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
|
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -55,6 +56,15 @@ var (
|
||||||
evictionInterval = time.Minute // Time interval to check for evictable transactions
|
evictionInterval = time.Minute // Time interval to check for evictable transactions
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Metrics
|
||||||
|
pendingDiscardMeter = metrics.NewMeter("core/txpool/transactions/pending/discard")
|
||||||
|
pendingReplaceMeter = metrics.NewMeter("core/txpool/transactions/pending/replace")
|
||||||
|
queuedDiscardMeter = metrics.NewMeter("core/txpool/transactions/queued/discard")
|
||||||
|
queuedReplaceMeter = metrics.NewMeter("core/txpool/transactions/queued/replace")
|
||||||
|
invalidTxMeter = metrics.NewMeter("core/txpool/transactions/invalid")
|
||||||
|
)
|
||||||
|
|
||||||
type stateFn func() (*state.StateDB, error)
|
type stateFn func() (*state.StateDB, error)
|
||||||
|
|
||||||
// TxPool contains all currently known transactions. Transactions
|
// TxPool contains all currently known transactions. Transactions
|
||||||
|
|
@ -306,6 +316,7 @@ func (pool *TxPool) add(tx *types.Transaction) error {
|
||||||
}
|
}
|
||||||
// Otherwise ensure basic validation passes and queue it up
|
// Otherwise ensure basic validation passes and queue it up
|
||||||
if err := pool.validateTx(tx); err != nil {
|
if err := pool.validateTx(tx); err != nil {
|
||||||
|
invalidTxMeter.Mark(1)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
pool.enqueueTx(hash, tx)
|
pool.enqueueTx(hash, tx)
|
||||||
|
|
@ -333,11 +344,13 @@ func (pool *TxPool) enqueueTx(hash common.Hash, tx *types.Transaction) {
|
||||||
}
|
}
|
||||||
inserted, old := pool.queue[from].Add(tx)
|
inserted, old := pool.queue[from].Add(tx)
|
||||||
if !inserted {
|
if !inserted {
|
||||||
|
queuedDiscardMeter.Mark(1)
|
||||||
return // An older transaction was better, discard this
|
return // An older transaction was better, discard this
|
||||||
}
|
}
|
||||||
// Discard any previous transaction and mark this
|
// Discard any previous transaction and mark this
|
||||||
if old != nil {
|
if old != nil {
|
||||||
delete(pool.all, old.Hash())
|
delete(pool.all, old.Hash())
|
||||||
|
queuedReplaceMeter.Mark(1)
|
||||||
}
|
}
|
||||||
pool.all[hash] = tx
|
pool.all[hash] = tx
|
||||||
}
|
}
|
||||||
|
|
@ -360,11 +373,13 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T
|
||||||
if !inserted {
|
if !inserted {
|
||||||
// An older transaction was better, discard this
|
// An older transaction was better, discard this
|
||||||
delete(pool.all, hash)
|
delete(pool.all, hash)
|
||||||
|
pendingDiscardMeter.Mark(1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Otherwise discard any previous transaction and mark this
|
// Otherwise discard any previous transaction and mark this
|
||||||
if old != nil {
|
if old != nil {
|
||||||
delete(pool.all, old.Hash())
|
delete(pool.all, old.Hash())
|
||||||
|
pendingReplaceMeter.Mark(1)
|
||||||
}
|
}
|
||||||
pool.all[hash] = tx // Failsafe to work around direct pending inserts (tests)
|
pool.all[hash] = tx // Failsafe to work around direct pending inserts (tests)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue