From fadd748a7e49bb91e3ff6d8212e557ce36c4feb4 Mon Sep 17 00:00:00 2001 From: irrun Date: Tue, 7 Jan 2025 10:02:39 +0800 Subject: [PATCH] fix: temporarily reduce gaslimit when fill txs for builder block (#64) --- core/block_validator.go | 5 ----- miner/miner.go | 2 +- miner/worker.go | 5 +++-- miner/worker_builder.go | 8 ++++++++ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/core/block_validator.go b/core/block_validator.go index bac3386c7f..d15e2cd786 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -256,8 +256,3 @@ func CalcGasLimit(parentGasLimit, desiredLimit uint64) uint64 { } return limit } - -// CalcGasLimitForBuilder computes the gas limit of the next block. -func CalcGasLimitForBuilder(parentGasLimit, desiredLimit uint64) uint64 { - return CalcGasLimit(parentGasLimit, desiredLimit) / 2 -} diff --git a/miner/miner.go b/miner/miner.go index bf76104687..61a9ac28b8 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -373,7 +373,7 @@ func (miner *Miner) prepareSimulationEnv(parent *types.Header, state *state.Stat header := &types.Header{ ParentHash: parent.Hash(), Number: new(big.Int).Add(parent.Number, common.Big1), - GasLimit: core.CalcGasLimitForBuilder(parent.GasLimit, miner.worker.config.GasCeil), + GasLimit: core.CalcGasLimit(parent.GasLimit, miner.worker.config.GasCeil), Extra: miner.worker.extra, Time: uint64(timestamp), Coinbase: coinbase, diff --git a/miner/worker.go b/miner/worker.go index 7831f9f7ea..e1f6c3c47c 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1033,10 +1033,11 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) { header := &types.Header{ ParentHash: parent.Hash(), Number: new(big.Int).Add(parent.Number, common.Big1), - GasLimit: core.CalcGasLimitForBuilder(parent.GasLimit, w.config.GasCeil), + GasLimit: core.CalcGasLimit(parent.GasLimit, w.config.GasCeil), Time: timestamp, Coinbase: genParams.coinbase, } + // Set the extra field. if len(w.extra) != 0 { header.Extra = w.extra @@ -1050,7 +1051,7 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) { header.BaseFee = eip1559.CalcBaseFee(w.chainConfig, parent) if w.chainConfig.Parlia == nil && !w.chainConfig.IsLondon(parent.Number) { parentGasLimit := parent.GasLimit * w.chainConfig.ElasticityMultiplier() - header.GasLimit = core.CalcGasLimitForBuilder(parentGasLimit, w.config.GasCeil) + header.GasLimit = core.CalcGasLimit(parentGasLimit, w.config.GasCeil) } } // Run the consensus preparation with the default or customized consensus engine. diff --git a/miner/worker_builder.go b/miner/worker_builder.go index abd562f67b..c4043089b9 100644 --- a/miner/worker_builder.go +++ b/miner/worker_builder.go @@ -32,6 +32,14 @@ var ( func (w *worker) fillTransactionsAndBundles(interruptCh chan int32, env *environment, stopTimer *time.Timer) error { env.state.StopPrefetcher() // no need to prefetch txs for a builder + // reduce gas limit for builder block + fullGasLimit := env.header.GasLimit + env.header.GasLimit /= 2 + + defer func() { + env.header.GasLimit = fullGasLimit + }() + var ( localPlainTxs map[common.Address][]*txpool.LazyTransaction remotePlainTxs map[common.Address][]*txpool.LazyTransaction