mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 15:47:21 +00:00
miner: add --miner.maxblobs flag (#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
This commit is contained in:
parent
1468331f9d
commit
ed4d00fd83
4 changed files with 24 additions and 3 deletions
|
|
@ -118,6 +118,7 @@ var (
|
|||
utils.MinerGasPriceFlag,
|
||||
utils.MinerEtherbaseFlag, // deprecated
|
||||
utils.MinerExtraDataFlag,
|
||||
utils.MinerMaxBlobsFlag,
|
||||
utils.MinerRecommitIntervalFlag,
|
||||
utils.MinerPendingFeeRecipientFlag,
|
||||
utils.MinerNewPayloadTimeoutFlag, // deprecated
|
||||
|
|
|
|||
|
|
@ -553,6 +553,11 @@ var (
|
|||
Usage: "0x prefixed public address for the pending block producer (not used for actual block production)",
|
||||
Category: flags.MinerCategory,
|
||||
}
|
||||
MinerMaxBlobsFlag = &cli.IntFlag{
|
||||
Name: "miner.maxblobs",
|
||||
Usage: "Maximum number of blobs per block (falls back to protocol maximum if unspecified)",
|
||||
Category: flags.MinerCategory,
|
||||
}
|
||||
|
||||
// Account settings
|
||||
PasswordFileFlag = &cli.PathFlag{
|
||||
|
|
@ -1571,6 +1576,10 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) {
|
|||
log.Warn("The flag --miner.newpayload-timeout is deprecated and will be removed, please use --miner.recommit")
|
||||
cfg.Recommit = ctx.Duration(MinerNewPayloadTimeoutFlag.Name)
|
||||
}
|
||||
if ctx.IsSet(MinerMaxBlobsFlag.Name) {
|
||||
maxBlobs := ctx.Int(MinerMaxBlobsFlag.Name)
|
||||
cfg.MaxBlobsPerBlock = &maxBlobs
|
||||
}
|
||||
}
|
||||
|
||||
func setRequiredBlocks(ctx *cli.Context, cfg *ethconfig.Config) {
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ type Config struct {
|
|||
GasCeil uint64 // Target gas ceiling for mined blocks.
|
||||
GasPrice *big.Int // Minimum gas price for mining a transaction
|
||||
Recommit time.Duration // The time interval for miner to re-create mining work.
|
||||
MaxBlobsPerBlock *int // Maximum number of blobs per block (unset uses protocol default)
|
||||
}
|
||||
|
||||
// DefaultConfig contains default settings for miner.
|
||||
|
|
|
|||
|
|
@ -43,6 +43,16 @@ var (
|
|||
errBlockInterruptedByTimeout = errors.New("timeout while building block")
|
||||
)
|
||||
|
||||
// maxBlobsPerBlock returns the maximum number of blobs per block.
|
||||
// Users can specify the maximum number of blobs per block if necessary.
|
||||
func (miner *Miner) maxBlobsPerBlock(time uint64) int {
|
||||
maxBlobs := eip4844.MaxBlobsPerBlock(miner.chainConfig, time)
|
||||
if miner.config.MaxBlobsPerBlock != nil {
|
||||
maxBlobs = *miner.config.MaxBlobsPerBlock
|
||||
}
|
||||
return maxBlobs
|
||||
}
|
||||
|
||||
// environment is the worker's current environment and holds all
|
||||
// information of the sealing block generation.
|
||||
type environment struct {
|
||||
|
|
@ -309,7 +319,7 @@ func (miner *Miner) commitBlobTransaction(env *environment, tx *types.Transactio
|
|||
// isn't really a better place right now. The blob gas limit is checked at block validation time
|
||||
// and not during execution. This means core.ApplyTransaction will not return an error if the
|
||||
// tx has too many blobs. So we have to explicitly check it here.
|
||||
maxBlobs := eip4844.MaxBlobsPerBlock(miner.chainConfig, env.header.Time)
|
||||
maxBlobs := miner.maxBlobsPerBlock(env.header.Time)
|
||||
if env.blobs+len(sc.Blobs) > maxBlobs {
|
||||
return errors.New("max data blobs reached")
|
||||
}
|
||||
|
|
@ -364,7 +374,7 @@ func (miner *Miner) commitTransactions(env *environment, plainTxs, blobTxs *tran
|
|||
}
|
||||
// If we don't have enough blob space for any further blob transactions,
|
||||
// skip that list altogether
|
||||
if !blobTxs.Empty() && env.blobs >= eip4844.MaxBlobsPerBlock(miner.chainConfig, env.header.Time) {
|
||||
if !blobTxs.Empty() && env.blobs >= miner.maxBlobsPerBlock(env.header.Time) {
|
||||
log.Trace("Not enough blob space for further blob transactions")
|
||||
blobTxs.Clear()
|
||||
// Fall though to pick up any plain txs
|
||||
|
|
@ -403,7 +413,7 @@ func (miner *Miner) commitTransactions(env *environment, plainTxs, blobTxs *tran
|
|||
// blobs or not, however the max check panics when called on a chain without
|
||||
// a defined schedule, so we need to verify it's safe to call.
|
||||
if isCancun {
|
||||
left := eip4844.MaxBlobsPerBlock(miner.chainConfig, env.header.Time) - env.blobs
|
||||
left := miner.maxBlobsPerBlock(env.header.Time) - env.blobs
|
||||
if left < int(ltx.BlobGas/params.BlobTxBlobGasPerBlob) {
|
||||
log.Trace("Not enough blob space left for transaction", "hash", ltx.Hash, "left", left, "needed", ltx.BlobGas/params.BlobTxBlobGasPerBlob)
|
||||
txs.Pop()
|
||||
|
|
|
|||
Loading…
Reference in a new issue