Skip to content

Commit 3e69459

Browse files
authored
Add configurable MaxRequestTimeoutSeconds on transitions (#1624)
1 parent 3594225 commit 3e69459

File tree

5 files changed

+44
-27
lines changed

5 files changed

+44
-27
lines changed

consensus/istanbul/config.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,23 @@ func (p *ProposerPolicy) ClearRegistry() {
123123
}
124124

125125
type Config struct {
126-
RequestTimeout uint64 `toml:",omitempty"` // The timeout for each Istanbul round in milliseconds.
127-
BlockPeriod uint64 `toml:",omitempty"` // Default minimum difference between two consecutive block's timestamps in second
128-
EmptyBlockPeriod uint64 `toml:",omitempty"` // Default minimum difference between a block and empty block's timestamps in second
129-
ProposerPolicy *ProposerPolicy `toml:",omitempty"` // The policy for proposer selection
130-
Epoch uint64 `toml:",omitempty"` // The number of blocks after which to checkpoint and reset the pending votes
131-
Ceil2Nby3Block *big.Int `toml:",omitempty"` // Number of confirmations required to move from one state to next [2F + 1 to Ceil(2N/3)]
132-
AllowedFutureBlockTime uint64 `toml:",omitempty"` // Max time (in seconds) from current time allowed for blocks, before they're considered future blocks
133-
TestQBFTBlock *big.Int `toml:",omitempty"` // Fork block at which block confirmations are done using qbft consensus instead of ibft
134-
BeneficiaryMode *string `toml:",omitempty"` // Mode for setting the beneficiary, either: list, besu, validators (beneficiary list is the list of validators)
135-
BlockReward *math.HexOrDecimal256 `toml:",omitempty"` // Reward
136-
MiningBeneficiary *common.Address `toml:",omitempty"` // Wallet address that benefits at every new block (besu mode)
137-
ValidatorContract common.Address `toml:",omitempty"`
138-
Validators []common.Address `toml:",omitempty"`
139-
ValidatorSelectionMode *string `toml:",omitempty"`
140-
Client bind.ContractCaller `toml:",omitempty"`
141-
Transitions []params.Transition
126+
RequestTimeout uint64 `toml:",omitempty"` // The timeout for each Istanbul round in milliseconds.
127+
BlockPeriod uint64 `toml:",omitempty"` // Default minimum difference between two consecutive block's timestamps in second
128+
EmptyBlockPeriod uint64 `toml:",omitempty"` // Default minimum difference between a block and empty block's timestamps in second
129+
ProposerPolicy *ProposerPolicy `toml:",omitempty"` // The policy for proposer selection
130+
Epoch uint64 `toml:",omitempty"` // The number of blocks after which to checkpoint and reset the pending votes
131+
Ceil2Nby3Block *big.Int `toml:",omitempty"` // Number of confirmations required to move from one state to next [2F + 1 to Ceil(2N/3)]
132+
AllowedFutureBlockTime uint64 `toml:",omitempty"` // Max time (in seconds) from current time allowed for blocks, before they're considered future blocks
133+
TestQBFTBlock *big.Int `toml:",omitempty"` // Fork block at which block confirmations are done using qbft consensus instead of ibft
134+
BeneficiaryMode *string `toml:",omitempty"` // Mode for setting the beneficiary, either: list, besu, validators (beneficiary list is the list of validators)
135+
BlockReward *math.HexOrDecimal256 `toml:",omitempty"` // Reward
136+
MiningBeneficiary *common.Address `toml:",omitempty"` // Wallet address that benefits at every new block (besu mode)
137+
ValidatorContract common.Address `toml:",omitempty"`
138+
Validators []common.Address `toml:",omitempty"`
139+
ValidatorSelectionMode *string `toml:",omitempty"`
140+
Client bind.ContractCaller `toml:",omitempty"`
141+
MaxRequestTimeoutSeconds uint64 `toml:",omitempty"`
142+
Transitions []params.Transition
142143
}
143144

144145
var DefaultConfig = &Config{
@@ -189,7 +190,8 @@ func (c Config) GetConfig(blockNumber *big.Int) Config {
189190

190191
c.getTransitionValue(blockNumber, func(transition params.Transition) {
191192
if transition.RequestTimeoutSeconds != 0 {
192-
newConfig.RequestTimeout = transition.RequestTimeoutSeconds
193+
// RequestTimeout is on milliseconds
194+
newConfig.RequestTimeout = transition.RequestTimeoutSeconds * 1000
193195
}
194196
if transition.EpochLength != 0 {
195197
newConfig.Epoch = transition.EpochLength
@@ -218,6 +220,9 @@ func (c Config) GetConfig(blockNumber *big.Int) Config {
218220
if len(transition.Validators) > 0 {
219221
newConfig.Validators = transition.Validators
220222
}
223+
if transition.MaxRequestTimeoutSeconds != nil {
224+
newConfig.MaxRequestTimeoutSeconds = *transition.MaxRequestTimeoutSeconds
225+
}
221226
})
222227

223228
return newConfig

consensus/istanbul/qbft/core/core.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@ func (c *core) newRoundChangeTimer() {
264264

265265
timeout := baseTimeout * time.Duration(math.Pow(2, float64(round)))
266266

267+
maxRequestTimeout := time.Duration(c.config.GetConfig(c.current.Sequence()).MaxRequestTimeoutSeconds) * time.Second
268+
269+
if maxRequestTimeout > time.Duration(0) && timeout > maxRequestTimeout {
270+
timeout = maxRequestTimeout
271+
}
272+
267273
c.currentLogger(true, nil).Trace("QBFT: start new ROUND-CHANGE timer", "timeout", timeout.Seconds())
268274
c.roundChangeTimer = time.AfterFunc(timeout, func() {
269275
c.sendEvent(timeoutEvent{})

eth/ethconfig/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ func CreateConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, co
302302
config.Istanbul.ValidatorSelectionMode = chainConfig.QBFT.ValidatorSelectionMode
303303
config.Istanbul.Validators = chainConfig.QBFT.Validators
304304

305+
if chainConfig.QBFT.MaxRequestTimeoutSeconds != nil && *chainConfig.QBFT.MaxRequestTimeoutSeconds > 0 {
306+
config.Istanbul.MaxRequestTimeoutSeconds = *chainConfig.QBFT.MaxRequestTimeoutSeconds
307+
}
308+
305309
return istanbulBackend.New(&config.Istanbul, stack.GetNodeKey(), db)
306310
}
307311
// For Quorum, Raft run as a separate service, so

params/config.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,12 @@ func (c IBFTConfig) String() string {
429429

430430
type QBFTConfig struct {
431431
*BFTConfig
432-
BlockReward *math.HexOrDecimal256 `json:"blockReward,omitempty"` // Reward from start, works only on QBFT consensus protocol
433-
BeneficiaryMode *string `json:"beneficiaryMode,omitempty"` // Mode for setting the beneficiary, either: list, besu, validators (beneficiary list is the list of validators)
434-
MiningBeneficiary *common.Address `json:"miningBeneficiary,omitempty"` // Wallet address that benefits at every new block (besu mode)
435-
ValidatorSelectionMode *string `json:"validatorselectionmode,omitempty"` // Select model for validators
436-
Validators []common.Address `json:"validators"` // Validators list
432+
BlockReward *math.HexOrDecimal256 `json:"blockReward,omitempty"` // Reward from start, works only on QBFT consensus protocol
433+
BeneficiaryMode *string `json:"beneficiaryMode,omitempty"` // Mode for setting the beneficiary, either: list, besu, validators (beneficiary list is the list of validators)
434+
MiningBeneficiary *common.Address `json:"miningBeneficiary,omitempty"` // Wallet address that benefits at every new block (besu mode)
435+
ValidatorSelectionMode *string `json:"validatorselectionmode,omitempty"` // Select model for validators
436+
Validators []common.Address `json:"validators"` // Validators list
437+
MaxRequestTimeoutSeconds *uint64 `json:"maxRequestTimeoutSeconds"` // The max round time
437438
}
438439

439440
func (c QBFTConfig) String() string {
@@ -469,6 +470,7 @@ type Transition struct {
469470
BlockReward *math.HexOrDecimal256 `json:"blockReward,omitempty"` // validation rewards
470471
BeneficiaryMode *string `json:"beneficiaryMode,omitempty"` // Mode for setting the beneficiary, either: list, besu, validators (beneficiary list is the list of validators)
471472
MiningBeneficiary *common.Address `json:"miningBeneficiary,omitempty"` // Wallet address that benefits at every new block (besu mode)
473+
MaxRequestTimeoutSeconds *uint64 `json:"maxRequestTimeoutSeconds,omitempty"` // The max a timeout should be for a round change
472474
}
473475

474476
// String implements the fmt.Stringer interface.

params/config_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,10 @@ func TestCheckTransitionsData(t *testing.T) {
332332
var ibftTransitionsConfig, qbftTransitionsConfig, invalidTransition, invalidBlockOrder []Transition
333333
var emptyBlockPeriodSeconds uint64 = 10
334334

335-
tranI0 := Transition{big.NewInt(0), IBFT, 30000, 5, nil, 10, 50, common.Address{}, nil, "", nil, nil, nil, nil, 0, nil, 0, nil, nil, nil}
336-
tranQ5 := Transition{big.NewInt(5), QBFT, 30000, 5, &emptyBlockPeriodSeconds, 10, 50, common.Address{}, nil, "", nil, nil, nil, nil, 0, nil, 0, nil, nil, nil}
337-
tranI10 := Transition{big.NewInt(10), IBFT, 30000, 5, nil, 10, 50, common.Address{}, nil, "", nil, nil, nil, nil, 0, nil, 0, nil, nil, nil}
338-
tranQ8 := Transition{big.NewInt(8), QBFT, 30000, 5, &emptyBlockPeriodSeconds, 10, 50, common.Address{}, nil, "", nil, nil, nil, nil, 0, nil, 0, nil, nil, nil}
335+
tranI0 := Transition{big.NewInt(0), IBFT, 30000, 5, nil, 10, 50, common.Address{}, nil, "", nil, nil, nil, nil, 0, nil, 0, nil, nil, nil, nil}
336+
tranQ5 := Transition{big.NewInt(5), QBFT, 30000, 5, &emptyBlockPeriodSeconds, 10, 50, common.Address{}, nil, "", nil, nil, nil, nil, 0, nil, 0, nil, nil, nil, nil}
337+
tranI10 := Transition{big.NewInt(10), IBFT, 30000, 5, nil, 10, 50, common.Address{}, nil, "", nil, nil, nil, nil, 0, nil, 0, nil, nil, nil, nil}
338+
tranQ8 := Transition{big.NewInt(8), QBFT, 30000, 5, &emptyBlockPeriodSeconds, 10, 50, common.Address{}, nil, "", nil, nil, nil, nil, 0, nil, 0, nil, nil, nil, nil}
339339

340340
ibftTransitionsConfig = append(ibftTransitionsConfig, tranI0, tranI10)
341341
qbftTransitionsConfig = append(qbftTransitionsConfig, tranQ5, tranQ8)
@@ -395,7 +395,7 @@ func TestCheckTransitionsData(t *testing.T) {
395395
wantErr: ErrBlockOrder,
396396
},
397397
{
398-
stored: &ChainConfig{Transitions: []Transition{{nil, IBFT, 30000, 5, &emptyBlockPeriodSeconds, 10, 50, common.Address{}, nil, "", nil, nil, nil, nil, 0, nil, 0, nil, nil, nil}}},
398+
stored: &ChainConfig{Transitions: []Transition{{nil, IBFT, 30000, 5, &emptyBlockPeriodSeconds, 10, 50, common.Address{}, nil, "", nil, nil, nil, nil, 0, nil, 0, nil, nil, nil, nil}}},
399399
wantErr: ErrBlockNumberMissing,
400400
},
401401
{

0 commit comments

Comments
 (0)