-
Notifications
You must be signed in to change notification settings - Fork 1
/
chain_consensus_config.go
52 lines (47 loc) · 1.62 KB
/
chain_consensus_config.go
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
package genesis
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/spf13/cobra"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/types"
"path/filepath"
"time"
)
// ConsensusConfigCmd sets the consensus configurations file for the node. Should be run before the chain starts
// up for the first time
func ConsensusConfigCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "consensus-config",
Short: "Set the consensus configurations for the chain. ie. shorten block times",
RunE: func(_ *cobra.Command, args []string) error {
setConsensusState(ctx)
err := setTendermintConsensus(ctx)
return err
},
}
return cmd
}
func setTendermintConsensus(ctx *server.Context) error {
genFile := ctx.Config.GenesisFile()
genDoc, err := types.GenesisDocFromFile(genFile)
if err != nil {
return err
}
genDoc.ConsensusParams.Block.TimeIotaMs = 1
err = genutil.ExportGenesisFile(genDoc, genFile)
return err
}
//setConsensusState sets the consensus configs to quicken block times
func setConsensusState(ctx *server.Context) {
con := ctx.Config.Consensus
con.TimeoutPropose = 200 * time.Millisecond
con.TimeoutProposeDelta = 200 * time.Millisecond
con.TimeoutPrevote = 200 * time.Millisecond
con.TimeoutPrevoteDelta = 200 * time.Millisecond
con.TimeoutPrecommit = 200 * time.Millisecond
con.TimeoutPrecommitDelta = 200 * time.Millisecond
con.TimeoutCommit = 800 * time.Millisecond
cfg.WriteConfigFile(filepath.Join(ctx.Config.RootDir, "config", "config.toml"), ctx.Config)
}