Skip to content

Commit 1df75db

Browse files
authored
Revert "core/txpool, eth/catalyst: ensure gas tip retains current value upon rollback" (#30521)
Reverts #30495 You are free to create a proper Clear method if that's the best way. But one that does a proper cleanup, not some hacky call to set gas which screws up logs, metrics and everything along the way. Also doesn't work for legacy pool local transactions. The current code had a hack in the simulated code, now we have a hack in live txpooling code. No, that's not acceptable. I want the live code to be proper, meaningful API, meaningful comments, meaningful implementation.
1 parent 52a9d89 commit 1df75db

File tree

5 files changed

+61
-86
lines changed

5 files changed

+61
-86
lines changed

core/txpool/blobpool/blobpool.go

+47-58
Original file line numberDiff line numberDiff line change
@@ -1011,56 +1011,6 @@ func (p *BlobPool) reinject(addr common.Address, txhash common.Hash) error {
10111011
return nil
10121012
}
10131013

1014-
func (p *BlobPool) flushTransactionsBelowTip(tip *uint256.Int) {
1015-
for addr, txs := range p.index {
1016-
for i, tx := range txs {
1017-
if tx.execTipCap.Cmp(tip) < 0 {
1018-
// Drop the offending transaction
1019-
var (
1020-
ids = []uint64{tx.id}
1021-
nonces = []uint64{tx.nonce}
1022-
)
1023-
p.spent[addr] = new(uint256.Int).Sub(p.spent[addr], txs[i].costCap)
1024-
p.stored -= uint64(tx.size)
1025-
delete(p.lookup, tx.hash)
1026-
txs[i] = nil
1027-
1028-
// Drop everything afterwards, no gaps allowed
1029-
for j, tx := range txs[i+1:] {
1030-
ids = append(ids, tx.id)
1031-
nonces = append(nonces, tx.nonce)
1032-
1033-
p.spent[addr] = new(uint256.Int).Sub(p.spent[addr], tx.costCap)
1034-
p.stored -= uint64(tx.size)
1035-
delete(p.lookup, tx.hash)
1036-
txs[i+1+j] = nil
1037-
}
1038-
// Clear out the dropped transactions from the index
1039-
if i > 0 {
1040-
p.index[addr] = txs[:i]
1041-
heap.Fix(p.evict, p.evict.index[addr])
1042-
} else {
1043-
delete(p.index, addr)
1044-
delete(p.spent, addr)
1045-
1046-
heap.Remove(p.evict, p.evict.index[addr])
1047-
p.reserve(addr, false)
1048-
}
1049-
// Clear out the transactions from the data store
1050-
log.Warn("Dropping underpriced blob transaction", "from", addr, "rejected", tx.nonce, "tip", tx.execTipCap, "want", tip, "drop", nonces, "ids", ids)
1051-
dropUnderpricedMeter.Mark(int64(len(ids)))
1052-
1053-
for _, id := range ids {
1054-
if err := p.store.Delete(id); err != nil {
1055-
log.Error("Failed to delete dropped transaction", "id", id, "err", err)
1056-
}
1057-
}
1058-
break
1059-
}
1060-
}
1061-
}
1062-
}
1063-
10641014
// SetGasTip implements txpool.SubPool, allowing the blob pool's gas requirements
10651015
// to be kept in sync with the main transaction pool's gas requirements.
10661016
func (p *BlobPool) SetGasTip(tip *big.Int) {
@@ -1073,20 +1023,59 @@ func (p *BlobPool) SetGasTip(tip *big.Int) {
10731023

10741024
// If the min miner fee increased, remove transactions below the new threshold
10751025
if old == nil || p.gasTip.Cmp(old) > 0 {
1076-
p.flushTransactionsBelowTip(p.gasTip)
1026+
for addr, txs := range p.index {
1027+
for i, tx := range txs {
1028+
if tx.execTipCap.Cmp(p.gasTip) < 0 {
1029+
// Drop the offending transaction
1030+
var (
1031+
ids = []uint64{tx.id}
1032+
nonces = []uint64{tx.nonce}
1033+
)
1034+
p.spent[addr] = new(uint256.Int).Sub(p.spent[addr], txs[i].costCap)
1035+
p.stored -= uint64(tx.size)
1036+
delete(p.lookup, tx.hash)
1037+
txs[i] = nil
1038+
1039+
// Drop everything afterwards, no gaps allowed
1040+
for j, tx := range txs[i+1:] {
1041+
ids = append(ids, tx.id)
1042+
nonces = append(nonces, tx.nonce)
1043+
1044+
p.spent[addr] = new(uint256.Int).Sub(p.spent[addr], tx.costCap)
1045+
p.stored -= uint64(tx.size)
1046+
delete(p.lookup, tx.hash)
1047+
txs[i+1+j] = nil
1048+
}
1049+
// Clear out the dropped transactions from the index
1050+
if i > 0 {
1051+
p.index[addr] = txs[:i]
1052+
heap.Fix(p.evict, p.evict.index[addr])
1053+
} else {
1054+
delete(p.index, addr)
1055+
delete(p.spent, addr)
1056+
1057+
heap.Remove(p.evict, p.evict.index[addr])
1058+
p.reserve(addr, false)
1059+
}
1060+
// Clear out the transactions from the data store
1061+
log.Warn("Dropping underpriced blob transaction", "from", addr, "rejected", tx.nonce, "tip", tx.execTipCap, "want", tip, "drop", nonces, "ids", ids)
1062+
dropUnderpricedMeter.Mark(int64(len(ids)))
1063+
1064+
for _, id := range ids {
1065+
if err := p.store.Delete(id); err != nil {
1066+
log.Error("Failed to delete dropped transaction", "id", id, "err", err)
1067+
}
1068+
}
1069+
break
1070+
}
1071+
}
1072+
}
10771073
}
10781074
log.Debug("Blobpool tip threshold updated", "tip", tip)
10791075
pooltipGauge.Update(tip.Int64())
10801076
p.updateStorageMetrics()
10811077
}
10821078

1083-
func (p *BlobPool) FlushAllTransactions() {
1084-
maxUint256 := uint256.MustFromBig(new(big.Int).Sub(new(big.Int).Lsh(common.Big1, 256), common.Big1))
1085-
p.lock.Lock()
1086-
defer p.lock.Unlock()
1087-
p.flushTransactionsBelowTip(maxUint256)
1088-
}
1089-
10901079
// validateTx checks whether a transaction is valid according to the consensus
10911080
// rules and adheres to some heuristic limits of the local node (price and size).
10921081
func (p *BlobPool) validateTx(tx *types.Transaction) error {

core/txpool/legacypool/legacypool.go

+6-17
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,6 @@ func (pool *LegacyPool) SubscribeTransactions(ch chan<- core.NewTxsEvent, reorgs
429429
return pool.txFeed.Subscribe(ch)
430430
}
431431

432-
func (pool *LegacyPool) flushTransactionsBelowTip(tip *big.Int) {
433-
// pool.priced is sorted by GasFeeCap, so we have to iterate through pool.all instead
434-
drop := pool.all.RemotesBelowTip(tip)
435-
for _, tx := range drop {
436-
pool.removeTx(tx.Hash(), false, true)
437-
}
438-
pool.priced.Removed(len(drop))
439-
}
440-
441432
// SetGasTip updates the minimum gas tip required by the transaction pool for a
442433
// new transaction, and drops all transactions below this threshold.
443434
func (pool *LegacyPool) SetGasTip(tip *big.Int) {
@@ -451,18 +442,16 @@ func (pool *LegacyPool) SetGasTip(tip *big.Int) {
451442
pool.gasTip.Store(newTip)
452443
// If the min miner fee increased, remove transactions below the new threshold
453444
if newTip.Cmp(old) > 0 {
454-
pool.flushTransactionsBelowTip(tip)
445+
// pool.priced is sorted by GasFeeCap, so we have to iterate through pool.all instead
446+
drop := pool.all.RemotesBelowTip(tip)
447+
for _, tx := range drop {
448+
pool.removeTx(tx.Hash(), false, true)
449+
}
450+
pool.priced.Removed(len(drop))
455451
}
456452
log.Info("Legacy pool tip threshold updated", "tip", newTip)
457453
}
458454

459-
func (pool *LegacyPool) FlushAllTransactions() {
460-
maxUint256 := new(big.Int).Sub(new(big.Int).Lsh(common.Big1, 256), common.Big1)
461-
pool.mu.Lock()
462-
defer pool.mu.Unlock()
463-
pool.flushTransactionsBelowTip(maxUint256)
464-
}
465-
466455
// Nonce returns the next nonce of an account, with all transactions executable
467456
// by the pool already applied on top.
468457
func (pool *LegacyPool) Nonce(addr common.Address) uint64 {

core/txpool/subpool.go

-3
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ type SubPool interface {
116116
// transaction, and drops all transactions below this threshold.
117117
SetGasTip(tip *big.Int)
118118

119-
// FlushAllTransactions drops all transactions in the pool.
120-
FlushAllTransactions()
121-
122119
// Has returns an indicator whether subpool has a transaction cached with the
123120
// given hash.
124121
Has(hash common.Hash) bool

core/txpool/txpool.go

-7
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,6 @@ func New(gasTip uint64, chain BlockChain, subpools []SubPool) (*TxPool, error) {
104104
return pool, nil
105105
}
106106

107-
// FlushAllTransactions removes all transactions from all subpools
108-
func (p *TxPool) FlushAllTransactions() {
109-
for _, subpool := range p.subpools {
110-
subpool.FlushAllTransactions()
111-
}
112-
}
113-
114107
// reserver is a method to create an address reservation callback to exclusively
115108
// assign/deassign addresses to/from subpools. This can ensure that at any point
116109
// in time, only a single subpool is able to manage an account, avoiding cross

eth/catalyst/simulated_beacon.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"crypto/sha256"
2222
"errors"
2323
"fmt"
24+
"math/big"
2425
"sync"
2526
"time"
2627

@@ -33,6 +34,7 @@ import (
3334
"github.com/ethereum/go-ethereum/event"
3435
"github.com/ethereum/go-ethereum/log"
3536
"github.com/ethereum/go-ethereum/node"
37+
"github.com/ethereum/go-ethereum/params"
3638
"github.com/ethereum/go-ethereum/rpc"
3739
)
3840

@@ -284,7 +286,12 @@ func (c *SimulatedBeacon) Commit() common.Hash {
284286

285287
// Rollback un-sends previously added transactions.
286288
func (c *SimulatedBeacon) Rollback() {
287-
c.eth.TxPool().FlushAllTransactions()
289+
// Flush all transactions from the transaction pools
290+
maxUint256 := new(big.Int).Sub(new(big.Int).Lsh(common.Big1, 256), common.Big1)
291+
c.eth.TxPool().SetGasTip(maxUint256)
292+
// Set the gas tip back to accept new transactions
293+
// TODO (Marius van der Wijden): set gas tip to parameter passed by config
294+
c.eth.TxPool().SetGasTip(big.NewInt(params.GWei))
288295
}
289296

290297
// Fork sets the head to the provided hash.

0 commit comments

Comments
 (0)