core/txpool: address review comments

This commit is contained in:
Martin Holst Swende 2024-03-13 09:17:02 +01:00
parent 7e1d704c1d
commit bd057758a1
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
4 changed files with 18 additions and 18 deletions

View file

@ -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
}

View file

@ -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
}

View file

@ -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 {

View file

@ -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,