Skip to content

Commit 4dd4821

Browse files
MariusVanDerWijdenfjl
authored andcommitted
miner: add --miner.maxblobs flag (ethereum#33129)
Adds a flag to specify how many blobs a node is willing to include in their locally build block as specified in https://eips.ethereum.org/EIPS/eip-7872 I deviated from the EIP in one case, I allowed for specifying 0 as the minimum blobs/block
1 parent 23ee186 commit 4dd4821

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ var (
118118
utils.MinerGasPriceFlag,
119119
utils.MinerEtherbaseFlag, // deprecated
120120
utils.MinerExtraDataFlag,
121+
utils.MinerMaxBlobsFlag,
121122
utils.MinerRecommitIntervalFlag,
122123
utils.MinerPendingFeeRecipientFlag,
123124
utils.MinerNewPayloadTimeoutFlag, // deprecated

cmd/utils/flags.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,11 @@ var (
553553
Usage: "0x prefixed public address for the pending block producer (not used for actual block production)",
554554
Category: flags.MinerCategory,
555555
}
556+
MinerMaxBlobsFlag = &cli.IntFlag{
557+
Name: "miner.maxblobs",
558+
Usage: "Maximum number of blobs per block (falls back to protocol maximum if unspecified)",
559+
Category: flags.MinerCategory,
560+
}
556561

557562
// Account settings
558563
PasswordFileFlag = &cli.PathFlag{
@@ -1571,6 +1576,10 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) {
15711576
log.Warn("The flag --miner.newpayload-timeout is deprecated and will be removed, please use --miner.recommit")
15721577
cfg.Recommit = ctx.Duration(MinerNewPayloadTimeoutFlag.Name)
15731578
}
1579+
if ctx.IsSet(MinerMaxBlobsFlag.Name) {
1580+
maxBlobs := ctx.Int(MinerMaxBlobsFlag.Name)
1581+
cfg.MaxBlobsPerBlock = &maxBlobs
1582+
}
15741583
}
15751584

15761585
func setRequiredBlocks(ctx *cli.Context, cfg *ethconfig.Config) {

miner/miner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type Config struct {
4848
GasCeil uint64 // Target gas ceiling for mined blocks.
4949
GasPrice *big.Int // Minimum gas price for mining a transaction
5050
Recommit time.Duration // The time interval for miner to re-create mining work.
51+
MaxBlobsPerBlock *int // Maximum number of blobs per block (unset uses protocol default)
5152
}
5253

5354
// DefaultConfig contains default settings for miner.

miner/worker.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ var (
4343
errBlockInterruptedByTimeout = errors.New("timeout while building block")
4444
)
4545

46+
// maxBlobsPerBlock returns the maximum number of blobs per block.
47+
// Users can specify the maximum number of blobs per block if necessary.
48+
func (miner *Miner) maxBlobsPerBlock(time uint64) int {
49+
maxBlobs := eip4844.MaxBlobsPerBlock(miner.chainConfig, time)
50+
if miner.config.MaxBlobsPerBlock != nil {
51+
maxBlobs = *miner.config.MaxBlobsPerBlock
52+
}
53+
return maxBlobs
54+
}
55+
4656
// environment is the worker's current environment and holds all
4757
// information of the sealing block generation.
4858
type environment struct {
@@ -309,7 +319,7 @@ func (miner *Miner) commitBlobTransaction(env *environment, tx *types.Transactio
309319
// isn't really a better place right now. The blob gas limit is checked at block validation time
310320
// and not during execution. This means core.ApplyTransaction will not return an error if the
311321
// tx has too many blobs. So we have to explicitly check it here.
312-
maxBlobs := eip4844.MaxBlobsPerBlock(miner.chainConfig, env.header.Time)
322+
maxBlobs := miner.maxBlobsPerBlock(env.header.Time)
313323
if env.blobs+len(sc.Blobs) > maxBlobs {
314324
return errors.New("max data blobs reached")
315325
}
@@ -364,7 +374,7 @@ func (miner *Miner) commitTransactions(env *environment, plainTxs, blobTxs *tran
364374
}
365375
// If we don't have enough blob space for any further blob transactions,
366376
// skip that list altogether
367-
if !blobTxs.Empty() && env.blobs >= eip4844.MaxBlobsPerBlock(miner.chainConfig, env.header.Time) {
377+
if !blobTxs.Empty() && env.blobs >= miner.maxBlobsPerBlock(env.header.Time) {
368378
log.Trace("Not enough blob space for further blob transactions")
369379
blobTxs.Clear()
370380
// Fall though to pick up any plain txs
@@ -403,7 +413,7 @@ func (miner *Miner) commitTransactions(env *environment, plainTxs, blobTxs *tran
403413
// blobs or not, however the max check panics when called on a chain without
404414
// a defined schedule, so we need to verify it's safe to call.
405415
if isCancun {
406-
left := eip4844.MaxBlobsPerBlock(miner.chainConfig, env.header.Time) - env.blobs
416+
left := miner.maxBlobsPerBlock(env.header.Time) - env.blobs
407417
if left < int(ltx.BlobGas/params.BlobTxBlobGasPerBlob) {
408418
log.Trace("Not enough blob space left for transaction", "hash", ltx.Hash, "left", left, "needed", ltx.BlobGas/params.BlobTxBlobGasPerBlob)
409419
txs.Pop()

0 commit comments

Comments
 (0)