diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index 652045dad9..735eee425e 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -540,6 +540,9 @@ func (pool *LegacyPool) Pending(filter txpool.PendingFilter) txpool.Pending { if filter.MinTip != nil { minTip = filter.MinTip } + if filter.BaseFee != nil { + baseFee = filter.BaseFee + } baseFeeBig := baseFee.ToBig() for addr, list := range pool.pending { if filter.NoLocals && pool.locals.contains(addr) { @@ -553,15 +556,11 @@ func (pool *LegacyPool) Pending(filter txpool.PendingFilter) txpool.Pending { txs = list.Flatten() ) for i, tx := range txs { - if tx.GasFeeCapIntCmp(baseFeeBig) < 0 { + bigTip, err := tx.EffectiveGasTip(baseFeeBig) + if err != nil { break // basefee too low, cannot be included, discard rest of txs from the account } - gasTipCap := uint256.MustFromBig(tx.GasTipCap()) - gasFeeCap := uint256.MustFromBig(tx.GasFeeCap()) - tip := new(uint256.Int).Sub(gasFeeCap, baseFee) - if tip.Gt(gasTipCap) { - tip = gasTipCap - } + tip := uint256.MustFromBig(bigTip) if tip.Lt(minTip) { break // allowed or remaining tip too low, cannot be included, discard rest of txs from the account } diff --git a/core/txpool/pending.go b/core/txpool/pending.go index 6d62c26521..6e98ac1b87 100644 --- a/core/txpool/pending.go +++ b/core/txpool/pending.go @@ -115,11 +115,11 @@ func NewPendingSet(heads TipList, tails map[common.Address][]*LazyTransaction) * // Shift replaces the current best head with the next one from the same account. func (ps *pendingSet) Shift() { - acc := ps.Heads[0].From - if txs, ok := ps.Tails[acc]; ok && len(txs) > 1 { + addr := ps.Heads[0].From + if txs, ok := ps.Tails[addr]; ok && len(txs) > 1 { ps.Heads[0].Tips = txs[1].Fees ps.Heads[0].Time = txs[1].Time.UnixNano() - ps.Tails[acc] = txs[1:] + ps.Tails[addr] = txs[1:] heap.Fix(&ps.Heads, 0) return } diff --git a/core/txpool/pending_test.go b/core/txpool/pending_test.go index 98c7fa1ed3..fa70360dba 100644 --- a/core/txpool/pending_test.go +++ b/core/txpool/pending_test.go @@ -36,7 +36,7 @@ func initLists() (heads TipList, tails map[common.Address][]*LazyTransaction) { first = true ) for j := 0; j < 25; j++ { - tip := uint256.NewInt(uint64(100*i + j)) + tip := uint256.NewInt(uint64(100*i + 50 - j)) lazyTx := &LazyTransaction{ Pool: nil, Hash: common.Hash{byte(i), byte(j)}, @@ -90,6 +90,7 @@ func TestPendingSortAndShift(t *testing.T) { if fee.Uint64() > prevFee { t.Fatalf("tx %d: fee %d > previous fee %d", haveCount, fee, prevFee) } + prevFee = fee.Uint64() txset.Shift() } if haveCount != expectedCount { @@ -118,6 +119,7 @@ func TestPendingSortAndPop(t *testing.T) { if fee.Uint64() > prevFee { t.Fatalf("tx %d: fee %d > previous fee %d", haveCount, fee, prevFee) } + prevFee = fee.Uint64() txset.Pop() } if haveCount != expectedCount { diff --git a/eth/handler_test.go b/eth/handler_test.go index 1a33f01677..7b2b39ab6d 100644 --- a/eth/handler_test.go +++ b/eth/handler_test.go @@ -109,20 +109,19 @@ func (p *testTxPool) Pending(filter txpool.PendingFilter) txpool.Pending { heads txpool.TipList baseFee = new(uint256.Int) ) - if filter.BaseFee != nil { baseFee = filter.BaseFee } - + baseFeeBig := baseFee.ToBig() for addr, batch := range batches { var tail []*txpool.LazyTransaction for i, tx := range batch { - gasTipCap := uint256.MustFromBig(tx.GasTipCap()) - gasFeeCap := uint256.MustFromBig(tx.GasFeeCap()) - tip := new(uint256.Int).Sub(gasFeeCap, baseFee) - if tip.Gt(gasTipCap) { - tip = gasTipCap + bigTip, err := tx.EffectiveGasTip(baseFeeBig) + if err != nil { + // to low for the given basefee + break } + tip := uint256.MustFromBig(bigTip) ltx := &txpool.LazyTransaction{ Hash: tx.Hash(), Tx: tx,