Skip to content

Commit

Permalink
feat: set half block gas limit for builder (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
irrun committed Oct 18, 2024
1 parent f19a025 commit 3042456
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
5 changes: 5 additions & 0 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,8 @@ 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
}
6 changes: 1 addition & 5 deletions miner/bidder.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,7 @@ func (b *Bidder) mainLoop() {
betterBidBefore = bidutil.BidBetterBefore(parentHeader, b.chain.Config().Parlia.Period, b.delayLeftOver,
bidSimulationLeftOver)

if time.Now().After(betterBidBefore) {
timer.Reset(0)
} else {
timer.Reset(time.Until(betterBidBefore) / time.Duration(maxBid))
}
timer.Reset(0)
}
if bidNum < maxBid && b.isBestWork(work) {
// update the bestWork and do bid
Expand Down
2 changes: 1 addition & 1 deletion miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,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.CalcGasLimit(parent.GasLimit, miner.worker.config.GasCeil),
GasLimit: core.CalcGasLimitForBuilder(parent.GasLimit, miner.worker.config.GasCeil),
Extra: miner.worker.extra,
Time: uint64(timestamp),
Coinbase: miner.worker.etherbase(),
Expand Down
4 changes: 2 additions & 2 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ 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.CalcGasLimit(parent.GasLimit, w.config.GasCeil),
GasLimit: core.CalcGasLimitForBuilder(parent.GasLimit, w.config.GasCeil),
Time: timestamp,
Coinbase: genParams.coinbase,
}
Expand All @@ -1034,7 +1034,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.CalcGasLimit(parentGasLimit, w.config.GasCeil)
header.GasLimit = core.CalcGasLimitForBuilder(parentGasLimit, w.config.GasCeil)
}
}
// Run the consensus preparation with the default or customized consensus engine.
Expand Down
7 changes: 7 additions & 0 deletions miner/worker_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"github.com/ethereum/go-ethereum/params"
)

const smallBundleGas = 10 * params.TxGas

var (
errNonRevertingTxInBundleFailed = errors.New("non-reverting tx in bundle failed")
errBundlePriceTooLow = errors.New("bundle price too low")
Expand Down Expand Up @@ -349,6 +351,11 @@ func (w *worker) mergeBundles(
}

for _, bundle := range bundles {
// if we don't have enough gas for any further transactions then we're done
if gasPool.Gas() < smallBundleGas {
break
}

prevState := currentState.Copy()
prevGasPool := new(core.GasPool).AddGas(gasPool.Gas())

Expand Down

0 comments on commit 3042456

Please sign in to comment.