Skip to content

Commit

Permalink
fix: temporarily reduce gaslimit when fill txs for builder block (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
irrun authored Jan 7, 2025
1 parent 9fca860 commit fadd748
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
5 changes: 0 additions & 5 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions miner/worker_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fadd748

Please sign in to comment.