Skip to content

Commit 17ac3e6

Browse files
feat(txpool): add logs to track txns (#1046)
* add log for txpool tx track * chore: auto version bump [bot] * Update core/tx_pool.go Co-authored-by: colin <[email protected]> * Update core/tx_pool.go Co-authored-by: colin <[email protected]> * chore: auto version bump [bot] * address comment * update level * update * tweak logs and print whole tx hashes * fix a bug * tweaks * fix a nil pointer bug --------- Co-authored-by: georgehao <[email protected]> Co-authored-by: colin <[email protected]> Co-authored-by: colinlyguo <[email protected]>
1 parent d2fe42b commit 17ac3e6

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

core/tx_pool.go

+20-12
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ func (pool *TxPool) loop() {
431431
if time.Since(pool.beats[addr]) > pool.config.Lifetime {
432432
list := pool.queue[addr].Flatten()
433433
for _, tx := range list {
434+
log.Trace("Evicting transaction due to timeout", "account", addr.Hex(), "hash", tx.Hash().Hex(), "lifetime sec", time.Since(pool.beats[addr]).Seconds(), "lifetime limit sec", pool.config.Lifetime.Seconds())
434435
pool.removeTx(tx.Hash(), true)
435436
}
436437
queuedEvictionMeter.Mark(int64(len(list)))
@@ -787,13 +788,13 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
787788
// If the transaction is already known, discard it
788789
hash := tx.Hash()
789790
if pool.all.Get(hash) != nil {
790-
log.Trace("Discarding already known transaction", "hash", hash)
791+
log.Trace("Discarding already known transaction", "hash", hash.Hex())
791792
knownTxMeter.Mark(1)
792793
return false, ErrAlreadyKnown
793794
}
794795

795796
if pool.IsMiner() && rawdb.IsSkippedTransaction(pool.chain.Database(), hash) {
796-
log.Trace("Discarding already known skipped transaction", "hash", hash)
797+
log.Trace("Discarding already known skipped transaction", "hash", hash.Hex())
797798
knownSkippedTxMeter.Mark(1)
798799
return false, ErrAlreadyKnown
799800
}
@@ -804,15 +805,15 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
804805

805806
// If the transaction fails basic validation, discard it
806807
if err := pool.validateTx(tx, isLocal); err != nil {
807-
log.Trace("Discarding invalid transaction", "hash", hash, "err", err)
808+
log.Trace("Discarding invalid transaction", "hash", hash.Hex(), "err", err)
808809
invalidTxMeter.Mark(1)
809810
return false, err
810811
}
811812
// If the transaction pool is full, discard underpriced transactions
812813
if uint64(pool.all.Slots()+numSlots(tx)) > pool.config.GlobalSlots+pool.config.GlobalQueue {
813814
// If the new transaction is underpriced, don't accept it
814815
if !isLocal && pool.priced.Underpriced(tx) {
815-
log.Trace("Discarding underpriced transaction", "hash", hash, "gasTipCap", tx.GasTipCap(), "gasFeeCap", tx.GasFeeCap())
816+
log.Trace("Discarding underpriced transaction", "hash", hash.Hex(), "gasTipCap", tx.GasTipCap(), "gasFeeCap", tx.GasFeeCap())
816817
underpricedTxMeter.Mark(1)
817818
return false, ErrUnderpriced
818819
}
@@ -832,7 +833,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
832833

833834
// Special case, we still can't make the room for the new remote one.
834835
if !isLocal && !success {
835-
log.Trace("Discarding overflown transaction", "hash", hash)
836+
log.Trace("Discarding overflown transaction", "hash", hash.Hex())
836837
overflowedTxMeter.Mark(1)
837838
return false, ErrTxPoolOverflow
838839
}
@@ -865,7 +866,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
865866
pool.priced.Put(tx, isLocal)
866867
pool.journalTx(from, tx)
867868
pool.queueTxEvent(tx)
868-
log.Trace("Pooled new executable transaction", "hash", hash, "from", from, "to", tx.To())
869+
log.Trace("Pooled new executable transaction", "hash", hash.Hex(), "from", from.Hex(), "to", tx.To())
869870

870871
// Successful promotion, bump the heartbeat
871872
pool.beats[from] = time.Now()
@@ -887,7 +888,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
887888
}
888889
pool.journalTx(from, tx)
889890

890-
log.Trace("Pooled new future transaction", "hash", hash, "from", from, "to", tx.To())
891+
log.Trace("Pooled new future transaction", "hash", hash.Hex(), "from", from.Hex(), "to", tx.To())
891892
return replaced, nil
892893
}
893894

@@ -975,6 +976,7 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T
975976
// Nothing was replaced, bump the pending counter
976977
pendingGauge.Inc(1)
977978
}
979+
log.Trace("Transaction promoted from future queue to pending", "hash", hash.Hex(), "from", addr.Hex(), "to", tx.To())
978980
// Set the potentially new pending nonce and notify any subsystems of the new tx
979981
pool.pendingNonces.set(addr, tx.Nonce()+1)
980982

@@ -1146,6 +1148,9 @@ func (pool *TxPool) removeTx(hash common.Hash, outofbound bool) {
11461148
if tx == nil {
11471149
return
11481150
}
1151+
1152+
log.Trace("Removing transaction from pool", "hash", hash.Hex())
1153+
11491154
addr, _ := types.Sender(pool.signer, tx) // already validated during insertion
11501155

11511156
// Remove it from the list of known transactions
@@ -1526,7 +1531,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
15261531
hash := tx.Hash()
15271532
pool.all.Remove(hash)
15281533
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
1529-
log.Trace("Removed cap-exceeding queued transaction", "hash", hash)
1534+
log.Trace("Removed cap-exceeding queued transaction", "hash", hash.Hex())
15301535
}
15311536
queuedRateLimitMeter.Mark(int64(len(caps)))
15321537
}
@@ -1612,7 +1617,7 @@ func (pool *TxPool) truncatePending() {
16121617

16131618
// Update the account nonce to the dropped transaction
16141619
pool.pendingNonces.setIfLower(offenders[i], tx.Nonce())
1615-
log.Trace("Removed fairness-exceeding pending transaction", "hash", hash)
1620+
log.Trace("Removed fairness-exceeding pending transaction", "hash", hash.Hex())
16161621
}
16171622
pool.priced.Removed(len(caps))
16181623
pendingGauge.Dec(int64(len(caps)))
@@ -1717,22 +1722,22 @@ func (pool *TxPool) demoteUnexecutables() {
17171722
hash := tx.Hash()
17181723
pool.all.Remove(hash)
17191724
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
1720-
log.Trace("Removed old pending transaction", "hash", hash)
1725+
log.Trace("Removed old pending transaction", "hash", hash.Hex())
17211726
}
17221727
// Drop all transactions that are too costly (low balance or out of gas), and queue any invalids back for later
17231728
costLimit := pool.currentState.GetBalance(addr)
17241729
drops, invalids := list.FilterF(costLimit, pool.currentMaxGas, pool.executableTxFilter(costLimit))
17251730
for _, tx := range drops {
17261731
hash := tx.Hash()
1727-
log.Trace("Removed unpayable pending transaction", "hash", hash)
1732+
log.Trace("Removed unpayable pending transaction", "hash", hash.Hex())
17281733
pool.all.Remove(hash)
17291734
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
17301735
}
17311736
pendingNofundsMeter.Mark(int64(len(drops)))
17321737

17331738
for _, tx := range invalids {
17341739
hash := tx.Hash()
1735-
log.Trace("Demoting pending transaction", "hash", hash)
1740+
log.Trace("Demoting pending transaction", "hash", hash.Hex())
17361741

17371742
// Internal shuffle shouldn't touch the lookup set.
17381743
pool.enqueueTx(hash, tx, false, false)
@@ -1767,6 +1772,9 @@ func (pool *TxPool) calculateTxsLifecycle(txs types.Transactions, t time.Time) {
17671772
for _, tx := range txs {
17681773
if tx.Time().Before(t) {
17691774
txLifecycle := t.Sub(tx.Time())
1775+
if txLifecycle >= time.Minute*30 {
1776+
log.Debug("Transaction lifecycle exceeds 30 minutes", "hash", tx.Hash().Hex(), "duration seconds", txLifecycle.Seconds())
1777+
}
17701778
txLifecycleTimer.Update(txLifecycle)
17711779
}
17721780
}

params/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
const (
2525
VersionMajor = 5 // Major version component of the current release
2626
VersionMinor = 7 // Minor version component of the current release
27-
VersionPatch = 26 // Patch version component of the current release
27+
VersionPatch = 27 // Patch version component of the current release
2828
VersionMeta = "mainnet" // Version metadata to append to the version string
2929
)
3030

0 commit comments

Comments
 (0)