Skip to content

Commit 92b8f28

Browse files
authored
Merge pull request #22995 from karalabe/enforce-miner-tip
core, eth, miner: enforce configured mining reward post 1559 too
2 parents 71ff65b + 7e915ee commit 92b8f28

File tree

9 files changed

+39
-12
lines changed

9 files changed

+39
-12
lines changed

core/tx_pool.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/ethereum/go-ethereum/common"
2828
"github.com/ethereum/go-ethereum/common/prque"
29+
"github.com/ethereum/go-ethereum/consensus/misc"
2930
"github.com/ethereum/go-ethereum/core/state"
3031
"github.com/ethereum/go-ethereum/core/types"
3132
"github.com/ethereum/go-ethereum/event"
@@ -496,13 +497,30 @@ func (pool *TxPool) Content() (map[common.Address]types.Transactions, map[common
496497
// Pending retrieves all currently processable transactions, grouped by origin
497498
// account and sorted by nonce. The returned transaction set is a copy and can be
498499
// freely modified by calling code.
499-
func (pool *TxPool) Pending() (map[common.Address]types.Transactions, error) {
500+
//
501+
// The enforceTips parameter can be used to do an extra filtering on the pending
502+
// transactions and only return those whose **effective** tip is large enough in
503+
// the next pending execution environment.
504+
func (pool *TxPool) Pending(enforceTips bool) (map[common.Address]types.Transactions, error) {
500505
pool.mu.Lock()
501506
defer pool.mu.Unlock()
502507

503508
pending := make(map[common.Address]types.Transactions)
504509
for addr, list := range pool.pending {
505-
pending[addr] = list.Flatten()
510+
txs := list.Flatten()
511+
512+
// If the miner requests tip enforcement, cap the lists now
513+
if enforceTips && !pool.locals.contains(addr) {
514+
for i, tx := range txs {
515+
if tx.EffectiveTipIntCmp(pool.gasPrice, pool.priced.urgent.baseFee) < 0 {
516+
txs = txs[:i]
517+
break
518+
}
519+
}
520+
}
521+
if len(txs) > 0 {
522+
pending[addr] = txs
523+
}
506524
}
507525
return pending, nil
508526
}
@@ -562,7 +580,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
562580
if tx.Tip().BitLen() > 256 {
563581
return ErrTipVeryHigh
564582
}
565-
// Ensure feeCap is less than or equal to tip.
583+
// Ensure feeCap is greater than or equal to tip.
566584
if tx.FeeCapIntCmp(tx.Tip()) < 0 {
567585
return ErrTipAboveFeeCap
568586
}
@@ -1114,8 +1132,9 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt
11141132
// because of another transaction (e.g. higher gas price).
11151133
if reset != nil {
11161134
pool.demoteUnexecutables()
1117-
if reset.newHead != nil {
1118-
pool.priced.SetBaseFee(reset.newHead.BaseFee)
1135+
if reset.newHead != nil && pool.chainconfig.IsLondon(new(big.Int).Add(reset.newHead.Number, big.NewInt(1))) {
1136+
pendingBaseFee := misc.CalcBaseFee(pool.chainconfig, reset.newHead)
1137+
pool.priced.SetBaseFee(pendingBaseFee)
11191138
}
11201139
}
11211140
// Ensure pool.queue and pool.pending sizes stay within the configured limits.

core/tx_pool_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func TestStateChangeDuringTransactionPoolReset(t *testing.T) {
252252
trigger = true
253253
<-pool.requestReset(nil, nil)
254254

255-
_, err := pool.Pending()
255+
_, err := pool.Pending(false)
256256
if err != nil {
257257
t.Fatalf("Could not fetch pending transactions: %v", err)
258258
}

core/types/transaction.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,14 @@ func (tx *Transaction) EffectiveTipCmp(other *Transaction, baseFee *big.Int) int
356356
return tx.EffectiveTipValue(baseFee).Cmp(other.EffectiveTipValue(baseFee))
357357
}
358358

359+
// EffectiveTipIntCmp compares the effective tip of a transaction to the given tip.
360+
func (tx *Transaction) EffectiveTipIntCmp(other *big.Int, baseFee *big.Int) int {
361+
if baseFee == nil {
362+
return tx.TipIntCmp(other)
363+
}
364+
return tx.EffectiveTipValue(baseFee).Cmp(other)
365+
}
366+
359367
// Hash returns the transaction hash.
360368
func (tx *Transaction) Hash() common.Hash {
361369
if hash := tx.hash.Load(); hash != nil {

eth/api_backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction)
231231
}
232232

233233
func (b *EthAPIBackend) GetPoolTransactions() (types.Transactions, error) {
234-
pending, err := b.eth.txPool.Pending()
234+
pending, err := b.eth.txPool.Pending(false)
235235
if err != nil {
236236
return nil, err
237237
}

eth/catalyst/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (api *consensusAPI) AssembleBlock(params assembleBlockParams) (*executableD
127127
time.Sleep(wait)
128128
}
129129

130-
pending, err := pool.Pending()
130+
pending, err := pool.Pending(true)
131131
if err != nil {
132132
return nil, err
133133
}

eth/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type txPool interface {
6666

6767
// Pending should return pending transactions.
6868
// The slice should be modifiable by the caller.
69-
Pending() (map[common.Address]types.Transactions, error)
69+
Pending(enforceTips bool) (map[common.Address]types.Transactions, error)
7070

7171
// SubscribeNewTxsEvent should return an event subscription of
7272
// NewTxsEvent and send events to the given channel.

eth/handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (p *testTxPool) AddRemotes(txs []*types.Transaction) []error {
9191
}
9292

9393
// Pending returns all the transactions known to the pool
94-
func (p *testTxPool) Pending() (map[common.Address]types.Transactions, error) {
94+
func (p *testTxPool) Pending(enforceTips bool) (map[common.Address]types.Transactions, error) {
9595
p.lock.RLock()
9696
defer p.lock.RUnlock()
9797

eth/sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (h *handler) syncTransactions(p *eth.Peer) {
5454
//
5555
// TODO(karalabe): Figure out if we could get away with random order somehow
5656
var txs types.Transactions
57-
pending, _ := h.txpool.Pending()
57+
pending, _ := h.txpool.Pending(false)
5858
for _, batch := range pending {
5959
txs = append(txs, batch...)
6060
}

miner/worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
963963
}
964964

965965
// Fill the block with all available pending transactions.
966-
pending, err := w.eth.TxPool().Pending()
966+
pending, err := w.eth.TxPool().Pending(true)
967967
if err != nil {
968968
log.Error("Failed to fetch pending transactions", "err", err)
969969
return

0 commit comments

Comments
 (0)