Skip to content
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
8 changes: 5 additions & 3 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ var (
MinerRecommitIntervalFlag = &cli.DurationFlag{
Name: "miner.recommit",
Usage: "Time interval to recreate the block being mined",
Value: ethconfig.Defaults.Miner.Recommit,
Value: *ethconfig.Defaults.Miner.Recommit,
Category: flags.MinerCategory,
}
MinerDelayLeftoverFlag = &cli.DurationFlag{
Expand Down Expand Up @@ -1908,7 +1908,8 @@ func setMiner(ctx *cli.Context, cfg *minerconfig.Config) {
cfg.GasPrice = flags.GlobalBig(ctx, MinerGasPriceFlag.Name)
}
if ctx.IsSet(MinerRecommitIntervalFlag.Name) {
cfg.Recommit = ctx.Duration(MinerRecommitIntervalFlag.Name)
recommitIntervalFlag := ctx.Duration(MinerRecommitIntervalFlag.Name)
cfg.Recommit = &recommitIntervalFlag
}
if ctx.IsSet(MinerDelayLeftoverFlag.Name) {
minerDelayLeftover := ctx.Duration(MinerDelayLeftoverFlag.Name)
Expand All @@ -1919,7 +1920,8 @@ func setMiner(ctx *cli.Context, cfg *minerconfig.Config) {
}
if ctx.IsSet(MinerNewPayloadTimeoutFlag.Name) {
log.Warn("The flag --miner.newpayload-timeout is deprecated and will be removed, please use --miner.recommit")
cfg.Recommit = ctx.Duration(MinerNewPayloadTimeoutFlag.Name)
recommitIntervalFlag := ctx.Duration(MinerRecommitIntervalFlag.Name)
cfg.Recommit = &recommitIntervalFlag
}
if ctx.Bool(DisableVoteAttestationFlag.Name) {
cfg.DisableVoteAttestation = true
Expand Down
2 changes: 1 addition & 1 deletion cmd/utils/flags_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ var (
MinerNewPayloadTimeoutFlag = &cli.DurationFlag{
Name: "miner.newpayload-timeout",
Usage: "Specify the maximum time allowance for creating a new payload (deprecated)",
Value: ethconfig.Defaults.Miner.Recommit,
Value: *ethconfig.Defaults.Miner.Recommit,
Category: flags.DeprecatedCategory,
}
MetricsEnabledExpensiveFlag = &cli.BoolFlag{
Expand Down
42 changes: 26 additions & 16 deletions miner/minerconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import (
)

var (
defaultDelayLeftOver = 50 * time.Millisecond
defaultDelayLeftOver = 50 * time.Millisecond
defaultRecommit = 10 * time.Second
defaultMaxWaitProposalInSecs = uint64(45)
// default configurations for MEV
defaultGreedyMergeTx bool = true
defaultValidatorCommission uint64 = 100
Expand All @@ -39,17 +41,16 @@ var (

// Config is the configuration parameters of mining.
type Config struct {
Etherbase common.Address `toml:",omitempty"` // Public address for block mining rewards
ExtraData hexutil.Bytes `toml:",omitempty"` // Block extra data set by the miner
DelayLeftOver *time.Duration `toml:",omitempty"` // Time reserved to finalize a block(calculate root, distribute income...)
GasFloor uint64 // Target gas floor for mined blocks.
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.
VoteEnable bool // Whether to vote when mining
MaxWaitProposalInSecs uint64 // The maximum time to wait for the proposal to be done, it's aimed to prevent validator being slashed when restarting

DisableVoteAttestation bool // Whether to skip assembling vote attestation
Etherbase common.Address `toml:",omitempty"` // Public address for block mining rewards
ExtraData hexutil.Bytes `toml:",omitempty"` // Block extra data set by the miner
DelayLeftOver *time.Duration `toml:",omitempty"` // Time reserved to finalize a block(calculate root, distribute income...)
GasFloor uint64 // Target gas floor for mined blocks.
GasCeil uint64 // Target gas ceiling for mined blocks.
GasPrice *big.Int // Minimum gas price for mining a transaction
Recommit *time.Duration `toml:",omitempty"` // The time interval for miner to re-create mining work.
VoteEnable bool // Whether to vote when mining
MaxWaitProposalInSecs *uint64 `toml:",omitempty"` // The maximum time to wait for the proposal to be done, it's aimed to prevent validator being slashed when restarting
DisableVoteAttestation bool // Whether to skip assembling vote attestation

Mev MevConfig // Mev configuration
}
Expand All @@ -63,12 +64,12 @@ var DefaultConfig = Config{
// consensus-layer usually will wait a half slot of time(6s)
// for payload generation. It should be enough for Geth to
// run 3 rounds.
Recommit: 3 * time.Second,
Recommit: &defaultRecommit,
DelayLeftOver: &defaultDelayLeftOver,

// The default value is set to 30 seconds.
// Because the avg restart time in mainnet is around 30s, so the node try to wait for the next multi-proposals to be done.
MaxWaitProposalInSecs: 30,
// The default value is set to 45 seconds.
// Because the avg restart time in mainnet could be 30+ seconds, so the node try to wait for the next multi-proposals to be done.
MaxWaitProposalInSecs: &defaultMaxWaitProposalInSecs,

Mev: DefaultMevConfig,
}
Expand Down Expand Up @@ -106,11 +107,20 @@ func ApplyDefaultMinerConfig(cfg *Config) {
log.Warn("ApplyDefaultMinerConfig cfg == nil")
return
}

// check [Eth.Miner]
if cfg.DelayLeftOver == nil {
cfg.DelayLeftOver = &defaultDelayLeftOver
log.Info("ApplyDefaultMinerConfig", "DelayLeftOver", *cfg.DelayLeftOver)
}
if cfg.MaxWaitProposalInSecs == nil {
cfg.MaxWaitProposalInSecs = &defaultMaxWaitProposalInSecs
log.Info("ApplyDefaultMinerConfig", "MaxWaitProposalInSecs", *cfg.MaxWaitProposalInSecs)
}
if cfg.Recommit == nil {
cfg.Recommit = &defaultRecommit
log.Info("ApplyDefaultMinerConfig", "Recommit", *cfg.Recommit)
}

// check [Eth.Miner.Mev]
if cfg.Mev.GreedyMergeTx == nil {
Expand Down
11 changes: 7 additions & 4 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,10 @@ func newWorker(config *minerconfig.Config, engine consensus.Engine, eth Backend,
worker.chainHeadSub = eth.BlockChain().SubscribeChainHeadEvent(worker.chainHeadCh)

// Sanitize recommit interval if the user-specified one is too short.
recommit := worker.config.Recommit
recommit := minRecommitInterval
if worker.config.Recommit != nil && *worker.config.Recommit > minRecommitInterval {
recommit = *worker.config.Recommit
}
if recommit < minRecommitInterval {
log.Warn("Sanitizing miner recommit interval", "provided", recommit, "updated", minRecommitInterval)
recommit = minRecommitInterval
Expand Down Expand Up @@ -1168,7 +1171,7 @@ func (w *worker) generateWork(params *generateParams, witness bool) *newPayloadR

if !params.noTxs {
interrupt := new(atomic.Int32)
timer := time.AfterFunc(w.config.Recommit, func() {
timer := time.AfterFunc(*w.config.Recommit, func() {
interrupt.Store(commitInterruptTimeout)
})
defer timer.Stop()
Expand Down Expand Up @@ -1547,7 +1550,7 @@ func (w *worker) tryWaitProposalDoneWhenStopping() {
}

log.Info("Checking miner's next proposal block", "current", currentBlock,
"proposalStart", startBlock, "proposalEnd", endBlock, "maxWait", w.config.MaxWaitProposalInSecs)
"proposalStart", startBlock, "proposalEnd", endBlock, "maxWait", *w.config.MaxWaitProposalInSecs)
if endBlock <= currentBlock {
log.Warn("next proposal end block has passed, ignore")
return
Expand All @@ -1556,7 +1559,7 @@ func (w *worker) tryWaitProposalDoneWhenStopping() {
if err != nil {
log.Debug("failed to get BlockInterval when tryWaitProposalDoneWhenStopping")
}
if startBlock > currentBlock && ((startBlock-currentBlock)*blockInterval/1000) > w.config.MaxWaitProposalInSecs {
if startBlock > currentBlock && ((startBlock-currentBlock)*blockInterval/1000) > *w.config.MaxWaitProposalInSecs {
log.Warn("the next proposal start block is too far, just skip waiting")
return
}
Expand Down
4 changes: 2 additions & 2 deletions miner/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ var (
// Test transactions
pendingTxs []*types.Transaction
newTxs []*types.Transaction

oneSecond = time.Second
testConfig = &minerconfig.Config{
Recommit: time.Second,
Recommit: &oneSecond,
GasCeil: params.GenesisGasLimit,
}
)
Expand Down