mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
calculate tx the lifecycle duration (#839)
* feat: add transactions len metrics of block processer * calculate tx lifecycle median duration * chore: auto version bump [bot] * fix * fix * fix * chore: auto version bump [bot] * address comments * remove error code * address comment * update * Update core/tx_pool.go Co-authored-by: colin <102356659+colinlyguo@users.noreply.github.com> * Update core/types/transaction.go Co-authored-by: colin <102356659+colinlyguo@users.noreply.github.com> * Update core/tx_pool.go Co-authored-by: colin <102356659+colinlyguo@users.noreply.github.com> * Update core/tx_pool.go --------- Co-authored-by: georgehao <georgehao@users.noreply.github.com> Co-authored-by: Ömer Faruk Irmak <omerfirmak@gmail.com> Co-authored-by: colin <102356659+colinlyguo@users.noreply.github.com>
This commit is contained in:
parent
096b98a85c
commit
4b85bbcbd8
3 changed files with 30 additions and 1 deletions
|
|
@ -129,6 +129,8 @@ var (
|
||||||
slotsGauge = metrics.NewRegisteredGauge("txpool/slots", nil)
|
slotsGauge = metrics.NewRegisteredGauge("txpool/slots", nil)
|
||||||
|
|
||||||
reheapTimer = metrics.NewRegisteredTimer("txpool/reheap", nil)
|
reheapTimer = metrics.NewRegisteredTimer("txpool/reheap", nil)
|
||||||
|
|
||||||
|
txLifecycleTimer = metrics.NewRegisteredTimer("txpool/txfifecycle", nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
// TxStatus is the current status of a transaction as seen by the pool.
|
// TxStatus is the current status of a transaction as seen by the pool.
|
||||||
|
|
@ -795,6 +797,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
|
||||||
// New transaction is better, replace old one
|
// New transaction is better, replace old one
|
||||||
if old != nil {
|
if old != nil {
|
||||||
pool.all.Remove(old.Hash())
|
pool.all.Remove(old.Hash())
|
||||||
|
pool.calculateTxsLifecycle(types.Transactions{old}, time.Now())
|
||||||
pool.priced.Removed(1)
|
pool.priced.Removed(1)
|
||||||
pendingReplaceMeter.Mark(1)
|
pendingReplaceMeter.Mark(1)
|
||||||
}
|
}
|
||||||
|
|
@ -848,6 +851,7 @@ func (pool *TxPool) enqueueTx(hash common.Hash, tx *types.Transaction, local boo
|
||||||
if old != nil {
|
if old != nil {
|
||||||
pool.all.Remove(old.Hash())
|
pool.all.Remove(old.Hash())
|
||||||
pool.priced.Removed(1)
|
pool.priced.Removed(1)
|
||||||
|
pool.calculateTxsLifecycle(types.Transactions{old}, time.Now())
|
||||||
queuedReplaceMeter.Mark(1)
|
queuedReplaceMeter.Mark(1)
|
||||||
} else {
|
} else {
|
||||||
// Nothing was replaced, bump the queued counter
|
// Nothing was replaced, bump the queued counter
|
||||||
|
|
@ -896,6 +900,7 @@ 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
|
||||||
pool.all.Remove(hash)
|
pool.all.Remove(hash)
|
||||||
|
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
|
||||||
pool.priced.Removed(1)
|
pool.priced.Removed(1)
|
||||||
pendingDiscardMeter.Mark(1)
|
pendingDiscardMeter.Mark(1)
|
||||||
return false
|
return false
|
||||||
|
|
@ -903,6 +908,7 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T
|
||||||
// Otherwise discard any previous transaction and mark this
|
// Otherwise discard any previous transaction and mark this
|
||||||
if old != nil {
|
if old != nil {
|
||||||
pool.all.Remove(old.Hash())
|
pool.all.Remove(old.Hash())
|
||||||
|
pool.calculateTxsLifecycle(types.Transactions{old}, time.Now())
|
||||||
pool.priced.Removed(1)
|
pool.priced.Removed(1)
|
||||||
pendingReplaceMeter.Mark(1)
|
pendingReplaceMeter.Mark(1)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1084,6 +1090,7 @@ func (pool *TxPool) removeTx(hash common.Hash, outofbound bool) {
|
||||||
|
|
||||||
// Remove it from the list of known transactions
|
// Remove it from the list of known transactions
|
||||||
pool.all.Remove(hash)
|
pool.all.Remove(hash)
|
||||||
|
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
|
||||||
if outofbound {
|
if outofbound {
|
||||||
pool.priced.Removed(1)
|
pool.priced.Removed(1)
|
||||||
}
|
}
|
||||||
|
|
@ -1418,6 +1425,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
|
||||||
for _, tx := range forwards {
|
for _, tx := range forwards {
|
||||||
hash := tx.Hash()
|
hash := tx.Hash()
|
||||||
pool.all.Remove(hash)
|
pool.all.Remove(hash)
|
||||||
|
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
|
||||||
}
|
}
|
||||||
log.Trace("Removed old queued transactions", "count", len(forwards))
|
log.Trace("Removed old queued transactions", "count", len(forwards))
|
||||||
|
|
||||||
|
|
@ -1427,6 +1435,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
|
||||||
for _, tx := range drops {
|
for _, tx := range drops {
|
||||||
hash := tx.Hash()
|
hash := tx.Hash()
|
||||||
pool.all.Remove(hash)
|
pool.all.Remove(hash)
|
||||||
|
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
|
||||||
}
|
}
|
||||||
log.Trace("Removed unpayable queued transactions", "count", len(drops))
|
log.Trace("Removed unpayable queued transactions", "count", len(drops))
|
||||||
queuedNofundsMeter.Mark(int64(len(drops)))
|
queuedNofundsMeter.Mark(int64(len(drops)))
|
||||||
|
|
@ -1449,6 +1458,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
|
||||||
for _, tx := range caps {
|
for _, tx := range caps {
|
||||||
hash := tx.Hash()
|
hash := tx.Hash()
|
||||||
pool.all.Remove(hash)
|
pool.all.Remove(hash)
|
||||||
|
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
|
||||||
log.Trace("Removed cap-exceeding queued transaction", "hash", hash)
|
log.Trace("Removed cap-exceeding queued transaction", "hash", hash)
|
||||||
}
|
}
|
||||||
queuedRateLimitMeter.Mark(int64(len(caps)))
|
queuedRateLimitMeter.Mark(int64(len(caps)))
|
||||||
|
|
@ -1531,6 +1541,7 @@ func (pool *TxPool) truncatePending() {
|
||||||
// Drop the transaction from the global pools too
|
// Drop the transaction from the global pools too
|
||||||
hash := tx.Hash()
|
hash := tx.Hash()
|
||||||
pool.all.Remove(hash)
|
pool.all.Remove(hash)
|
||||||
|
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
|
||||||
|
|
||||||
// Update the account nonce to the dropped transaction
|
// Update the account nonce to the dropped transaction
|
||||||
pool.pendingNonces.setIfLower(offenders[i], tx.Nonce())
|
pool.pendingNonces.setIfLower(offenders[i], tx.Nonce())
|
||||||
|
|
@ -1558,6 +1569,7 @@ func (pool *TxPool) truncatePending() {
|
||||||
// Drop the transaction from the global pools too
|
// Drop the transaction from the global pools too
|
||||||
hash := tx.Hash()
|
hash := tx.Hash()
|
||||||
pool.all.Remove(hash)
|
pool.all.Remove(hash)
|
||||||
|
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
|
||||||
|
|
||||||
// Update the account nonce to the dropped transaction
|
// Update the account nonce to the dropped transaction
|
||||||
pool.pendingNonces.setIfLower(addr, tx.Nonce())
|
pool.pendingNonces.setIfLower(addr, tx.Nonce())
|
||||||
|
|
@ -1637,6 +1649,7 @@ func (pool *TxPool) demoteUnexecutables() {
|
||||||
for _, tx := range olds {
|
for _, tx := range olds {
|
||||||
hash := tx.Hash()
|
hash := tx.Hash()
|
||||||
pool.all.Remove(hash)
|
pool.all.Remove(hash)
|
||||||
|
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
|
||||||
log.Trace("Removed old pending transaction", "hash", hash)
|
log.Trace("Removed old pending transaction", "hash", hash)
|
||||||
}
|
}
|
||||||
// Drop all transactions that are too costly (low balance or out of gas), and queue any invalids back for later
|
// Drop all transactions that are too costly (low balance or out of gas), and queue any invalids back for later
|
||||||
|
|
@ -1646,6 +1659,7 @@ func (pool *TxPool) demoteUnexecutables() {
|
||||||
hash := tx.Hash()
|
hash := tx.Hash()
|
||||||
log.Trace("Removed unpayable pending transaction", "hash", hash)
|
log.Trace("Removed unpayable pending transaction", "hash", hash)
|
||||||
pool.all.Remove(hash)
|
pool.all.Remove(hash)
|
||||||
|
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
|
||||||
}
|
}
|
||||||
pendingNofundsMeter.Mark(int64(len(drops)))
|
pendingNofundsMeter.Mark(int64(len(drops)))
|
||||||
|
|
||||||
|
|
@ -1681,6 +1695,16 @@ func (pool *TxPool) demoteUnexecutables() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// calculateTxsLifecycle calculates the lifecycle of given txs
|
||||||
|
func (pool *TxPool) calculateTxsLifecycle(txs types.Transactions, t time.Time) {
|
||||||
|
for _, tx := range txs {
|
||||||
|
if tx.Time().Before(t) {
|
||||||
|
txLifecycle := t.Sub(tx.Time())
|
||||||
|
txLifecycleTimer.Update(txLifecycle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// PauseReorgs stops any new reorg jobs to be started but doesn't interrupt any existing ones that are in flight
|
// PauseReorgs stops any new reorg jobs to be started but doesn't interrupt any existing ones that are in flight
|
||||||
// Keep in mind this function might block, although it is not expected to block for any significant amount of time
|
// Keep in mind this function might block, although it is not expected to block for any significant amount of time
|
||||||
func (pool *TxPool) PauseReorgs() {
|
func (pool *TxPool) PauseReorgs() {
|
||||||
|
|
|
||||||
|
|
@ -184,6 +184,11 @@ func (tx *Transaction) UnmarshalBinary(b []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Time retrieves the time first seen locally
|
||||||
|
func (tx *Transaction) Time() time.Time {
|
||||||
|
return tx.time
|
||||||
|
}
|
||||||
|
|
||||||
// decodeTyped decodes a typed transaction from the canonical format.
|
// decodeTyped decodes a typed transaction from the canonical format.
|
||||||
func (tx *Transaction) decodeTyped(b []byte) (TxData, error) {
|
func (tx *Transaction) decodeTyped(b []byte) (TxData, error) {
|
||||||
if len(b) <= 1 {
|
if len(b) <= 1 {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
const (
|
const (
|
||||||
VersionMajor = 5 // Major version component of the current release
|
VersionMajor = 5 // Major version component of the current release
|
||||||
VersionMinor = 6 // Minor version component of the current release
|
VersionMinor = 6 // Minor version component of the current release
|
||||||
VersionPatch = 0 // Patch version component of the current release
|
VersionPatch = 1 // Patch version component of the current release
|
||||||
VersionMeta = "mainnet" // Version metadata to append to the version string
|
VersionMeta = "mainnet" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue