Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set half block gas limit for builder #53

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading