Skip to content

Commit

Permalink
Merge branch 'develop' into feat-migrate-logs-and-log-fixes-from-upst…
Browse files Browse the repository at this point in the history
…ream-active
  • Loading branch information
colinlyguo authored Dec 6, 2024
2 parents ebb932e + 17ac3e6 commit 9a04d2b
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ func (pool *TxPool) loop() {
if time.Since(pool.beats[addr]) > pool.config.Lifetime {
list := pool.queue[addr].Flatten()
for _, tx := range list {
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())
pool.removeTx(tx.Hash(), true)
}
queuedEvictionMeter.Mark(int64(len(list)))
Expand Down Expand Up @@ -787,13 +788,13 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
// If the transaction is already known, discard it
hash := tx.Hash()
if pool.all.Get(hash) != nil {
log.Trace("Discarding already known transaction", "hash", hash)
log.Trace("Discarding already known transaction", "hash", hash.Hex())
knownTxMeter.Mark(1)
return false, ErrAlreadyKnown
}

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

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

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

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

log.Trace("Pooled new future transaction", "hash", hash, "from", from, "to", tx.To())
log.Trace("Pooled new future transaction", "hash", hash.Hex(), "from", from.Hex(), "to", tx.To())
return replaced, nil
}

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

Expand Down Expand Up @@ -1146,6 +1148,9 @@ func (pool *TxPool) removeTx(hash common.Hash, outofbound bool) {
if tx == nil {
return
}

log.Trace("Removing transaction from pool", "hash", hash.Hex())

addr, _ := types.Sender(pool.signer, tx) // already validated during insertion

// Remove it from the list of known transactions
Expand Down Expand Up @@ -1526,7 +1531,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
hash := tx.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.Hex())
}
queuedRateLimitMeter.Mark(int64(len(caps)))
}
Expand Down Expand Up @@ -1612,7 +1617,7 @@ func (pool *TxPool) truncatePending() {

// Update the account nonce to the dropped transaction
pool.pendingNonces.setIfLower(offenders[i], tx.Nonce())
log.Trace("Removed fairness-exceeding pending transaction", "hash", hash)
log.Trace("Removed fairness-exceeding pending transaction", "hash", hash.Hex())
}
pool.priced.Removed(len(caps))
pendingGauge.Dec(int64(len(caps)))
Expand Down Expand Up @@ -1717,22 +1722,22 @@ func (pool *TxPool) demoteUnexecutables() {
hash := tx.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.Hex())
}
// Drop all transactions that are too costly (low balance or out of gas), and queue any invalids back for later
costLimit := pool.currentState.GetBalance(addr)
drops, invalids := list.FilterF(costLimit, pool.currentMaxGas, pool.executableTxFilter(costLimit))
for _, tx := range drops {
hash := tx.Hash()
log.Trace("Removed unpayable pending transaction", "hash", hash)
log.Trace("Removed unpayable pending transaction", "hash", hash.Hex())
pool.all.Remove(hash)
pool.calculateTxsLifecycle(types.Transactions{tx}, time.Now())
}
pendingNofundsMeter.Mark(int64(len(drops)))

for _, tx := range invalids {
hash := tx.Hash()
log.Trace("Demoting pending transaction", "hash", hash)
log.Trace("Demoting pending transaction", "hash", hash.Hex())

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

0 comments on commit 9a04d2b

Please sign in to comment.