Skip to content

Commit e9f1eed

Browse files
Issue 1004 - prevent "Mining too far in future" message when using allowedfutureblocktime parameter (#1023)
* Use AllowedFutureBlockTime value in miner to avoid "Mining too far in the future" when nodes are not in time sync. Also fix issue where zero value of AllowedFutureBlockTime is always shown when using `admin.nodeInfo.protocols.istanbul` in console.
1 parent 8d20f8e commit e9f1eed

File tree

7 files changed

+23
-20
lines changed

7 files changed

+23
-20
lines changed

cmd/utils/flags.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,9 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) {
14941494
if ctx.GlobalIsSet(MinerNoVerfiyFlag.Name) {
14951495
cfg.Noverify = ctx.Bool(MinerNoVerfiyFlag.Name)
14961496
}
1497+
if ctx.GlobalIsSet(AllowedFutureBlockTimeFlag.Name) {
1498+
cfg.AllowedFutureBlockTime = ctx.GlobalUint64(AllowedFutureBlockTimeFlag.Name) //Quorum
1499+
}
14971500
}
14981501

14991502
func setWhitelist(ctx *cli.Context, cfg *eth.Config) {
@@ -1610,8 +1613,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
16101613
setIstanbul(ctx, cfg)
16111614
setRaft(ctx, cfg)
16121615

1613-
cfg.AllowedFutureBlockTime = ctx.GlobalUint64(AllowedFutureBlockTimeFlag.Name) //Quorum
1614-
16151616
if ctx.GlobalIsSet(SyncModeFlag.Name) {
16161617
cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode)
16171618
}

eth/backend.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func makeExtraData(extra []byte, isQuorum bool) []byte {
284284
func CreateConsensusEngine(ctx *node.ServiceContext, chainConfig *params.ChainConfig, config *Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
285285
// If proof-of-authority is requested, set it up
286286
if chainConfig.Clique != nil {
287-
chainConfig.Clique.AllowedFutureBlockTime = config.AllowedFutureBlockTime //Quorum
287+
chainConfig.Clique.AllowedFutureBlockTime = config.Miner.AllowedFutureBlockTime //Quorum
288288
return clique.New(chainConfig.Clique, db)
289289
}
290290
// If Istanbul is requested, set it up
@@ -294,7 +294,7 @@ func CreateConsensusEngine(ctx *node.ServiceContext, chainConfig *params.ChainCo
294294
}
295295
config.Istanbul.ProposerPolicy = istanbul.ProposerPolicy(chainConfig.Istanbul.ProposerPolicy)
296296
config.Istanbul.Ceil2Nby3Block = chainConfig.Istanbul.Ceil2Nby3Block
297-
config.Istanbul.AllowedFutureBlockTime = config.AllowedFutureBlockTime
297+
config.Istanbul.AllowedFutureBlockTime = config.Miner.AllowedFutureBlockTime //Quorum
298298

299299
return istanbulBackend.New(&config.Istanbul, ctx.NodeKey(), db)
300300
}

eth/config.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ type Config struct {
146146
Istanbul istanbul.Config
147147

148148
// Miscellaneous options
149-
DocRoot string `toml:"-"`
150-
AllowedFutureBlockTime uint64 //Quorum
149+
DocRoot string `toml:"-"`
151150

152151
// Type of the EWASM interpreter ("" for default)
153152
EWASMInterpreter string

eth/handler_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestNodeInfo(t *testing.T) {
5151
}{
5252
{"ethash", nil, nil, false},
5353
{"raft", nil, nil, true},
54-
{"istanbul", nil, &params.IstanbulConfig{1, 1, big.NewInt(0), 0}, false},
54+
{"istanbul", nil, &params.IstanbulConfig{1, 1, big.NewInt(0)}, false},
5555
{"clique", &params.CliqueConfig{1, 1, 0}, nil, false},
5656
}
5757

miner/miner.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ type Backend interface {
4545

4646
// Config is the configuration parameters of mining.
4747
type Config struct {
48-
Etherbase common.Address `toml:",omitempty"` // Public address for block mining rewards (default = first account)
49-
Notify []string `toml:",omitempty"` // HTTP URL list to be notified of new work packages(only useful in ethash).
50-
ExtraData hexutil.Bytes `toml:",omitempty"` // Block extra data set by the miner
51-
GasFloor uint64 // Target gas floor for mined blocks.
52-
GasCeil uint64 // Target gas ceiling for mined blocks.
53-
GasPrice *big.Int // Minimum gas price for mining a transaction
54-
Recommit time.Duration // The time interval for miner to re-create mining work.
55-
Noverify bool // Disable remote mining solution verification(only useful in ethash).
48+
Etherbase common.Address `toml:",omitempty"` // Public address for block mining rewards (default = first account)
49+
Notify []string `toml:",omitempty"` // HTTP URL list to be notified of new work packages(only useful in ethash).
50+
ExtraData hexutil.Bytes `toml:",omitempty"` // Block extra data set by the miner
51+
GasFloor uint64 // Target gas floor for mined blocks.
52+
GasCeil uint64 // Target gas ceiling for mined blocks.
53+
GasPrice *big.Int // Minimum gas price for mining a transaction
54+
Recommit time.Duration // The time interval for miner to re-create mining work.
55+
Noverify bool // Disable remote mining solution verification(only useful in ethash).
56+
AllowedFutureBlockTime uint64 // Max time (in seconds) from current time allowed for blocks, before they're considered future blocks
5657
}
5758

5859
// Miner creates blocks and searches for proof-of-work values.

miner/worker.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,11 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
916916
if parent.Time() >= uint64(timestamp) {
917917
timestamp = int64(parent.Time() + 1)
918918
}
919+
920+
allowedFutureBlockTime := int64(w.config.AllowedFutureBlockTime) //Quorum - get AllowedFutureBlockTime to fix issue # 1004
921+
919922
// this will ensure we're not going off too far in the future
920-
if now := time.Now().Unix(); timestamp > now+1 {
923+
if now := time.Now().Unix(); timestamp > now+1+allowedFutureBlockTime {
921924
wait := time.Duration(timestamp-now) * time.Second
922925
log.Info("Mining too far in the future", "wait", common.PrettyDuration(wait))
923926
time.Sleep(wait)

params/config.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,9 @@ func (c *CliqueConfig) String() string {
342342

343343
// IstanbulConfig is the consensus engine configs for Istanbul based sealing.
344344
type IstanbulConfig struct {
345-
Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint
346-
ProposerPolicy uint64 `json:"policy"` // The policy for proposer selection
347-
Ceil2Nby3Block *big.Int `json:"ceil2Nby3Block,omitempty"` // Number of confirmations required to move from one state to next [2F + 1 to Ceil(2N/3)]
348-
AllowedFutureBlockTime uint64 `json:"allowedFutureBlockTime"` // Max time (in seconds) from current time allowed for blocks, before they're considered future blocks
345+
Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint
346+
ProposerPolicy uint64 `json:"policy"` // The policy for proposer selection
347+
Ceil2Nby3Block *big.Int `json:"ceil2Nby3Block,omitempty"` // Number of confirmations required to move from one state to next [2F + 1 to Ceil(2N/3)]
349348
}
350349

351350
// String implements the stringer interface, returning the consensus engine details.

0 commit comments

Comments
 (0)