core/txpool, eth/catalyst: ensure gas tip retains current value upon rollback (#30495)

Here we move the method that drops all transactions by temporarily increasing the fee
into the TxPool itself. It's better to have it there because we can set it back to the
configured value afterwards. This resolves a TODO in the simulated backend.
pull/30512/head
jwasinger 1 month ago committed by GitHub
parent 93675d1da7
commit bb9897f11b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 37
      core/txpool/blobpool/blobpool.go
  2. 23
      core/txpool/legacypool/legacypool.go
  3. 3
      core/txpool/subpool.go
  4. 7
      core/txpool/txpool.go
  5. 9
      eth/catalyst/simulated_beacon.go

@ -1013,21 +1013,10 @@ func (p *BlobPool) reinject(addr common.Address, txhash common.Hash) error {
return nil return nil
} }
// SetGasTip implements txpool.SubPool, allowing the blob pool's gas requirements func (p *BlobPool) flushTransactionsBelowTip(tip *uint256.Int) {
// to be kept in sync with the main transaction pool's gas requirements.
func (p *BlobPool) SetGasTip(tip *big.Int) {
p.lock.Lock()
defer p.lock.Unlock()
// Store the new minimum gas tip
old := p.gasTip
p.gasTip = uint256.MustFromBig(tip)
// If the min miner fee increased, remove transactions below the new threshold
if old == nil || p.gasTip.Cmp(old) > 0 {
for addr, txs := range p.index { for addr, txs := range p.index {
for i, tx := range txs { for i, tx := range txs {
if tx.execTipCap.Cmp(p.gasTip) < 0 { if tx.execTipCap.Cmp(tip) < 0 {
// Drop the offending transaction // Drop the offending transaction
var ( var (
ids = []uint64{tx.id} ids = []uint64{tx.id}
@ -1072,12 +1061,34 @@ func (p *BlobPool) SetGasTip(tip *big.Int) {
} }
} }
} }
}
// SetGasTip implements txpool.SubPool, allowing the blob pool's gas requirements
// to be kept in sync with the main transaction pool's gas requirements.
func (p *BlobPool) SetGasTip(tip *big.Int) {
p.lock.Lock()
defer p.lock.Unlock()
// Store the new minimum gas tip
old := p.gasTip
p.gasTip = uint256.MustFromBig(tip)
// If the min miner fee increased, remove transactions below the new threshold
if old == nil || p.gasTip.Cmp(old) > 0 {
p.flushTransactionsBelowTip(p.gasTip)
} }
log.Debug("Blobpool tip threshold updated", "tip", tip) log.Debug("Blobpool tip threshold updated", "tip", tip)
pooltipGauge.Update(tip.Int64()) pooltipGauge.Update(tip.Int64())
p.updateStorageMetrics() p.updateStorageMetrics()
} }
func (p *BlobPool) FlushAllTransactions() {
maxUint256 := uint256.MustFromBig(new(big.Int).Sub(new(big.Int).Lsh(common.Big1, 256), common.Big1))
p.lock.Lock()
defer p.lock.Unlock()
p.flushTransactionsBelowTip(maxUint256)
}
// validateTx checks whether a transaction is valid according to the consensus // validateTx checks whether a transaction is valid according to the consensus
// rules and adheres to some heuristic limits of the local node (price and size). // rules and adheres to some heuristic limits of the local node (price and size).
func (p *BlobPool) validateTx(tx *types.Transaction) error { func (p *BlobPool) validateTx(tx *types.Transaction) error {

@ -429,6 +429,15 @@ func (pool *LegacyPool) SubscribeTransactions(ch chan<- core.NewTxsEvent, reorgs
return pool.txFeed.Subscribe(ch) return pool.txFeed.Subscribe(ch)
} }
func (pool *LegacyPool) flushTransactionsBelowTip(tip *big.Int) {
// pool.priced is sorted by GasFeeCap, so we have to iterate through pool.all instead
drop := pool.all.RemotesBelowTip(tip)
for _, tx := range drop {
pool.removeTx(tx.Hash(), false, true)
}
pool.priced.Removed(len(drop))
}
// SetGasTip updates the minimum gas tip required by the transaction pool for a // SetGasTip updates the minimum gas tip required by the transaction pool for a
// new transaction, and drops all transactions below this threshold. // new transaction, and drops all transactions below this threshold.
func (pool *LegacyPool) SetGasTip(tip *big.Int) { func (pool *LegacyPool) SetGasTip(tip *big.Int) {
@ -442,16 +451,18 @@ func (pool *LegacyPool) SetGasTip(tip *big.Int) {
pool.gasTip.Store(newTip) pool.gasTip.Store(newTip)
// If the min miner fee increased, remove transactions below the new threshold // If the min miner fee increased, remove transactions below the new threshold
if newTip.Cmp(old) > 0 { if newTip.Cmp(old) > 0 {
// pool.priced is sorted by GasFeeCap, so we have to iterate through pool.all instead pool.flushTransactionsBelowTip(tip)
drop := pool.all.RemotesBelowTip(tip)
for _, tx := range drop {
pool.removeTx(tx.Hash(), false, true)
}
pool.priced.Removed(len(drop))
} }
log.Info("Legacy pool tip threshold updated", "tip", newTip) log.Info("Legacy pool tip threshold updated", "tip", newTip)
} }
func (pool *LegacyPool) FlushAllTransactions() {
maxUint256 := new(big.Int).Sub(new(big.Int).Lsh(common.Big1, 256), common.Big1)
pool.mu.Lock()
defer pool.mu.Unlock()
pool.flushTransactionsBelowTip(maxUint256)
}
// Nonce returns the next nonce of an account, with all transactions executable // Nonce returns the next nonce of an account, with all transactions executable
// by the pool already applied on top. // by the pool already applied on top.
func (pool *LegacyPool) Nonce(addr common.Address) uint64 { func (pool *LegacyPool) Nonce(addr common.Address) uint64 {

@ -116,6 +116,9 @@ type SubPool interface {
// transaction, and drops all transactions below this threshold. // transaction, and drops all transactions below this threshold.
SetGasTip(tip *big.Int) SetGasTip(tip *big.Int)
// FlushAllTransactions drops all transactions in the pool.
FlushAllTransactions()
// Has returns an indicator whether subpool has a transaction cached with the // Has returns an indicator whether subpool has a transaction cached with the
// given hash. // given hash.
Has(hash common.Hash) bool Has(hash common.Hash) bool

@ -104,6 +104,13 @@ func New(gasTip uint64, chain BlockChain, subpools []SubPool) (*TxPool, error) {
return pool, nil return pool, nil
} }
// FlushAllTransactions removes all transactions from all subpools
func (p *TxPool) FlushAllTransactions() {
for _, subpool := range p.subpools {
subpool.FlushAllTransactions()
}
}
// reserver is a method to create an address reservation callback to exclusively // reserver is a method to create an address reservation callback to exclusively
// assign/deassign addresses to/from subpools. This can ensure that at any point // assign/deassign addresses to/from subpools. This can ensure that at any point
// in time, only a single subpool is able to manage an account, avoiding cross // in time, only a single subpool is able to manage an account, avoiding cross

@ -21,7 +21,6 @@ import (
"crypto/sha256" "crypto/sha256"
"errors" "errors"
"fmt" "fmt"
"math/big"
"sync" "sync"
"time" "time"
@ -34,7 +33,6 @@ import (
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
) )
@ -286,12 +284,7 @@ func (c *SimulatedBeacon) Commit() common.Hash {
// Rollback un-sends previously added transactions. // Rollback un-sends previously added transactions.
func (c *SimulatedBeacon) Rollback() { func (c *SimulatedBeacon) Rollback() {
// Flush all transactions from the transaction pools c.eth.TxPool().FlushAllTransactions()
maxUint256 := new(big.Int).Sub(new(big.Int).Lsh(common.Big1, 256), common.Big1)
c.eth.TxPool().SetGasTip(maxUint256)
// Set the gas tip back to accept new transactions
// TODO (Marius van der Wijden): set gas tip to parameter passed by config
c.eth.TxPool().SetGasTip(big.NewInt(params.GWei))
} }
// Fork sets the head to the provided hash. // Fork sets the head to the provided hash.

Loading…
Cancel
Save