mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core/txpool: address review comments
This commit is contained in:
parent
7e1d704c1d
commit
bd057758a1
4 changed files with 18 additions and 18 deletions
|
|
@ -540,6 +540,9 @@ func (pool *LegacyPool) Pending(filter txpool.PendingFilter) txpool.Pending {
|
||||||
if filter.MinTip != nil {
|
if filter.MinTip != nil {
|
||||||
minTip = filter.MinTip
|
minTip = filter.MinTip
|
||||||
}
|
}
|
||||||
|
if filter.BaseFee != nil {
|
||||||
|
baseFee = filter.BaseFee
|
||||||
|
}
|
||||||
baseFeeBig := baseFee.ToBig()
|
baseFeeBig := baseFee.ToBig()
|
||||||
for addr, list := range pool.pending {
|
for addr, list := range pool.pending {
|
||||||
if filter.NoLocals && pool.locals.contains(addr) {
|
if filter.NoLocals && pool.locals.contains(addr) {
|
||||||
|
|
@ -553,15 +556,11 @@ func (pool *LegacyPool) Pending(filter txpool.PendingFilter) txpool.Pending {
|
||||||
txs = list.Flatten()
|
txs = list.Flatten()
|
||||||
)
|
)
|
||||||
for i, tx := range txs {
|
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
|
break // basefee too low, cannot be included, discard rest of txs from the account
|
||||||
}
|
}
|
||||||
gasTipCap := uint256.MustFromBig(tx.GasTipCap())
|
tip := uint256.MustFromBig(bigTip)
|
||||||
gasFeeCap := uint256.MustFromBig(tx.GasFeeCap())
|
|
||||||
tip := new(uint256.Int).Sub(gasFeeCap, baseFee)
|
|
||||||
if tip.Gt(gasTipCap) {
|
|
||||||
tip = gasTipCap
|
|
||||||
}
|
|
||||||
if tip.Lt(minTip) {
|
if tip.Lt(minTip) {
|
||||||
break // allowed or remaining tip too low, cannot be included, discard rest of txs from the account
|
break // allowed or remaining tip too low, cannot be included, discard rest of txs from the account
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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.
|
// Shift replaces the current best head with the next one from the same account.
|
||||||
func (ps *pendingSet) Shift() {
|
func (ps *pendingSet) Shift() {
|
||||||
acc := ps.Heads[0].From
|
addr := ps.Heads[0].From
|
||||||
if txs, ok := ps.Tails[acc]; ok && len(txs) > 1 {
|
if txs, ok := ps.Tails[addr]; ok && len(txs) > 1 {
|
||||||
ps.Heads[0].Tips = txs[1].Fees
|
ps.Heads[0].Tips = txs[1].Fees
|
||||||
ps.Heads[0].Time = txs[1].Time.UnixNano()
|
ps.Heads[0].Time = txs[1].Time.UnixNano()
|
||||||
ps.Tails[acc] = txs[1:]
|
ps.Tails[addr] = txs[1:]
|
||||||
heap.Fix(&ps.Heads, 0)
|
heap.Fix(&ps.Heads, 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ func initLists() (heads TipList, tails map[common.Address][]*LazyTransaction) {
|
||||||
first = true
|
first = true
|
||||||
)
|
)
|
||||||
for j := 0; j < 25; j++ {
|
for j := 0; j < 25; j++ {
|
||||||
tip := uint256.NewInt(uint64(100*i + j))
|
tip := uint256.NewInt(uint64(100*i + 50 - j))
|
||||||
lazyTx := &LazyTransaction{
|
lazyTx := &LazyTransaction{
|
||||||
Pool: nil,
|
Pool: nil,
|
||||||
Hash: common.Hash{byte(i), byte(j)},
|
Hash: common.Hash{byte(i), byte(j)},
|
||||||
|
|
@ -90,6 +90,7 @@ func TestPendingSortAndShift(t *testing.T) {
|
||||||
if fee.Uint64() > prevFee {
|
if fee.Uint64() > prevFee {
|
||||||
t.Fatalf("tx %d: fee %d > previous fee %d", haveCount, fee, prevFee)
|
t.Fatalf("tx %d: fee %d > previous fee %d", haveCount, fee, prevFee)
|
||||||
}
|
}
|
||||||
|
prevFee = fee.Uint64()
|
||||||
txset.Shift()
|
txset.Shift()
|
||||||
}
|
}
|
||||||
if haveCount != expectedCount {
|
if haveCount != expectedCount {
|
||||||
|
|
@ -118,6 +119,7 @@ func TestPendingSortAndPop(t *testing.T) {
|
||||||
if fee.Uint64() > prevFee {
|
if fee.Uint64() > prevFee {
|
||||||
t.Fatalf("tx %d: fee %d > previous fee %d", haveCount, fee, prevFee)
|
t.Fatalf("tx %d: fee %d > previous fee %d", haveCount, fee, prevFee)
|
||||||
}
|
}
|
||||||
|
prevFee = fee.Uint64()
|
||||||
txset.Pop()
|
txset.Pop()
|
||||||
}
|
}
|
||||||
if haveCount != expectedCount {
|
if haveCount != expectedCount {
|
||||||
|
|
|
||||||
|
|
@ -109,20 +109,19 @@ func (p *testTxPool) Pending(filter txpool.PendingFilter) txpool.Pending {
|
||||||
heads txpool.TipList
|
heads txpool.TipList
|
||||||
baseFee = new(uint256.Int)
|
baseFee = new(uint256.Int)
|
||||||
)
|
)
|
||||||
|
|
||||||
if filter.BaseFee != nil {
|
if filter.BaseFee != nil {
|
||||||
baseFee = filter.BaseFee
|
baseFee = filter.BaseFee
|
||||||
}
|
}
|
||||||
|
baseFeeBig := baseFee.ToBig()
|
||||||
for addr, batch := range batches {
|
for addr, batch := range batches {
|
||||||
var tail []*txpool.LazyTransaction
|
var tail []*txpool.LazyTransaction
|
||||||
for i, tx := range batch {
|
for i, tx := range batch {
|
||||||
gasTipCap := uint256.MustFromBig(tx.GasTipCap())
|
bigTip, err := tx.EffectiveGasTip(baseFeeBig)
|
||||||
gasFeeCap := uint256.MustFromBig(tx.GasFeeCap())
|
if err != nil {
|
||||||
tip := new(uint256.Int).Sub(gasFeeCap, baseFee)
|
// to low for the given basefee
|
||||||
if tip.Gt(gasTipCap) {
|
break
|
||||||
tip = gasTipCap
|
|
||||||
}
|
}
|
||||||
|
tip := uint256.MustFromBig(bigTip)
|
||||||
ltx := &txpool.LazyTransaction{
|
ltx := &txpool.LazyTransaction{
|
||||||
Hash: tx.Hash(),
|
Hash: tx.Hash(),
|
||||||
Tx: tx,
|
Tx: tx,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue