feat(worker): allow empty blocks (#1153)

This commit is contained in:
Péter Garamvölgyi 2025-03-21 13:44:59 +01:00 committed by GitHub
parent e1e578d99d
commit 019e52cb0c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 14 additions and 1 deletions

View file

@ -133,6 +133,7 @@ var (
utils.MinerNoVerifyFlag, utils.MinerNoVerifyFlag,
utils.MinerStoreSkippedTxTracesFlag, utils.MinerStoreSkippedTxTracesFlag,
utils.MinerMaxAccountsNumFlag, utils.MinerMaxAccountsNumFlag,
utils.MinerAllowEmptyFlag,
utils.NATFlag, utils.NATFlag,
utils.NoDiscoverFlag, utils.NoDiscoverFlag,
utils.DiscoveryV5Flag, utils.DiscoveryV5Flag,

View file

@ -197,6 +197,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.MinerNoVerifyFlag, utils.MinerNoVerifyFlag,
utils.MinerStoreSkippedTxTracesFlag, utils.MinerStoreSkippedTxTracesFlag,
utils.MinerMaxAccountsNumFlag, utils.MinerMaxAccountsNumFlag,
utils.MinerAllowEmptyFlag,
}, },
}, },
{ {

View file

@ -515,6 +515,10 @@ var (
Usage: "Maximum number of accounts that miner will fetch the pending transactions of when building a new block", Usage: "Maximum number of accounts that miner will fetch the pending transactions of when building a new block",
Value: math.MaxInt, Value: math.MaxInt,
} }
MinerAllowEmptyFlag = cli.BoolFlag{
Name: "miner.allowempty",
Usage: "Allow sealing empty blocks",
}
// Account settings // Account settings
UnlockedAccountFlag = cli.StringFlag{ UnlockedAccountFlag = cli.StringFlag{
Name: "unlock", Name: "unlock",
@ -1620,6 +1624,9 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) {
if ctx.GlobalIsSet(MinerMaxAccountsNumFlag.Name) { if ctx.GlobalIsSet(MinerMaxAccountsNumFlag.Name) {
cfg.MaxAccountsNum = ctx.GlobalInt(MinerMaxAccountsNumFlag.Name) cfg.MaxAccountsNum = ctx.GlobalInt(MinerMaxAccountsNumFlag.Name)
} }
if ctx.GlobalIsSet(MinerAllowEmptyFlag.Name) {
cfg.AllowEmpty = ctx.GlobalBool(MinerAllowEmptyFlag.Name)
}
if ctx.GlobalIsSet(LegacyMinerGasTargetFlag.Name) { if ctx.GlobalIsSet(LegacyMinerGasTargetFlag.Name) {
log.Warn("The generic --miner.gastarget flag is deprecated and will be removed in the future!") log.Warn("The generic --miner.gastarget flag is deprecated and will be removed in the future!")
} }

View file

@ -60,6 +60,7 @@ type Config struct {
StoreSkippedTxTraces bool // Whether store the wrapped traces when storing a skipped tx StoreSkippedTxTraces bool // Whether store the wrapped traces when storing a skipped tx
MaxAccountsNum int // Maximum number of accounts that miner will fetch the pending transactions of when building a new block MaxAccountsNum int // Maximum number of accounts that miner will fetch the pending transactions of when building a new block
CCCMaxWorkers int // Maximum number of workers to use for async CCC tasks CCCMaxWorkers int // Maximum number of workers to use for async CCC tasks
AllowEmpty bool // If true, then we allow sealing empty blocks
SigningDisabled bool // Whether to disable signing blocks with consensus enginek SigningDisabled bool // Whether to disable signing blocks with consensus enginek
} }

View file

@ -400,6 +400,9 @@ func (w *worker) mainLoop() {
w.current.deadlineReached = true w.current.deadlineReached = true
if len(w.current.txs) > 0 { if len(w.current.txs) > 0 {
_, err = w.commit() _, err = w.commit()
} else if w.config.AllowEmpty {
log.Warn("Committing empty block", "number", w.current.header.Number)
_, err = w.commit()
} }
case ev := <-w.txsCh: case ev := <-w.txsCh:
idleTimer.UpdateSince(idleStart) idleTimer.UpdateSince(idleStart)

View file

@ -24,7 +24,7 @@ import (
const ( const (
VersionMajor = 5 // Major version component of the current release VersionMajor = 5 // Major version component of the current release
VersionMinor = 8 // Minor version component of the current release VersionMinor = 8 // Minor version component of the current release
VersionPatch = 28 // Patch version component of the current release VersionPatch = 29 // Patch version component of the current release
VersionMeta = "mainnet" // Version metadata to append to the version string VersionMeta = "mainnet" // Version metadata to append to the version string
) )