forked from zeta-chain/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeout.go
More file actions
57 lines (45 loc) · 1.6 KB
/
timeout.go
File metadata and controls
57 lines (45 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package server
import (
"fmt"
"time"
"github.com/cosmos/cosmos-sdk/server"
"github.com/spf13/cobra"
)
// REF: https://github.com/zeta-chain/node/issues/4032
const (
// DefaultTimeoutProposeDelta How much timeout_propose increases with each round
DefaultTimeoutProposeDelta = 200 * time.Millisecond
// DefaultTimeoutPrevoteDelta How much the timeout_prevote increases with each round
DefaultTimeoutPrevoteDelta = 200 * time.Millisecond
// DefaultTimeoutPrecommitDelta How much the timeout_precommit increases with each round
DefaultTimeoutPrecommitDelta = 200 * time.Millisecond
FlagSkipConfigOverwrite = "skip-config-overwrite"
)
// timeoutConfig represents a consensus timeout configuration pair
type timeoutConfig struct {
currentValue *time.Duration
defaultValue time.Duration
}
// overWriteConfig overwrites the consensus timeout configurations to the default values.
func overWriteConfig(cmd *cobra.Command) error {
serverCtx := server.GetServerContextFromCmd(cmd)
timeoutConfigs := []timeoutConfig{
{&serverCtx.Config.Consensus.TimeoutProposeDelta, DefaultTimeoutProposeDelta},
{&serverCtx.Config.Consensus.TimeoutPrevoteDelta, DefaultTimeoutPrevoteDelta},
{&serverCtx.Config.Consensus.TimeoutPrecommitDelta, DefaultTimeoutPrecommitDelta},
}
needsUpdate := false
for _, config := range timeoutConfigs {
if *config.currentValue != config.defaultValue {
*config.currentValue = config.defaultValue
needsUpdate = true
}
}
if needsUpdate {
err := server.SetCmdServerContext(cmd, serverCtx)
if err != nil {
return fmt.Errorf("failed to set server context: %w", err)
}
}
return nil
}