diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index 2c4b5f651..d69f6fe9d 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -651,7 +651,15 @@ func (pool *LegacyPool) Pending(filter txpool.PendingFilter) map[common.Address] var ( minTipBig *big.Int baseFeeBig *big.Int + + blockNumber uint64 = 0 + blockHash common.Hash = common.Hash{} + nonceTooLowCount = 0 + staled = make(map[common.Hash]struct{}) ) + defer func() { + log.Debug("perf-trace txpool-trace Pending() nonce too low", "blockNumber", blockNumber, "blockHash", blockHash, "nonceTooLowCount", nonceTooLowCount, "staled", len(staled)) + }() if filter.MinTip != nil { minTipBig = filter.MinTip.ToBig() } @@ -659,7 +667,28 @@ func (pool *LegacyPool) Pending(filter txpool.PendingFilter) map[common.Address] baseFeeBig = filter.BaseFee.ToBig() } pending := make(map[common.Address][]*txpool.LazyTransaction, len(pool.pending)) + if currHeader := pool.chain.CurrentBlock(); currHeader != nil { + blockNumber = currHeader.Number.Uint64() + blockHash = currHeader.Hash() + currBlock := pool.chain.GetBlock(blockHash, currHeader.Number.Uint64()) + staled = make(map[common.Hash]struct{}, len(currBlock.Transactions())) + for _, tx := range currBlock.Transactions() { + staled[tx.Hash()] = struct{}{} + } + } for addr, txs := range pool.pendingCache.dump() { + // remove nonce too low transactions + if len(staled) > 0 { + noncetoolow := -1 + for i, tx := range txs { + if _, hit := staled[tx.Hash()]; !hit { + break + } + noncetoolow = i + } + nonceTooLowCount += noncetoolow + 1 + txs = txs[noncetoolow+1:] + } // If the miner requests tip enforcement, cap the lists now if minTipBig != nil && !pool.locals.contains(addr) { diff --git a/miner/worker_builder.go b/miner/worker_builder.go index 61a5672c2..2055f67cc 100644 --- a/miner/worker_builder.go +++ b/miner/worker_builder.go @@ -2,15 +2,16 @@ package miner import ( "errors" - mapset "github.com/deckarep/golang-set/v2" - "github.com/ethereum/go-ethereum/consensus/misc/eip4844" - "github.com/holiman/uint256" "math/big" "slices" "sync" "sync/atomic" "time" + mapset "github.com/deckarep/golang-set/v2" + "github.com/ethereum/go-ethereum/consensus/misc/eip4844" + "github.com/holiman/uint256" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/state" @@ -78,7 +79,7 @@ func (w *worker) fillTransactionsAndBundles(interrupt *atomic.Int32, env *enviro pendingBlobTxs := w.eth.TxPool().Pending(filter) packFromTxpoolTimer.UpdateSince(start) - log.Debug("packFromTxpoolTimer", "duration", common.PrettyDuration(time.Since(start)), "hash", env.header.Hash()) + log.Debug("packFromTxpoolTimer", "duration", common.PrettyDuration(time.Since(start)), "hash", env.header.Hash(), "txs", len(pendingPlainTxs)) // Split the pending transactions into locals and remotes. localPlainTxs, remotePlainTxs := make(map[common.Address][]*txpool.LazyTransaction), pendingPlainTxs