forked from omni-network/omni
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcometconfig.go
93 lines (74 loc) · 2.86 KB
/
cometconfig.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package cmd
import (
"context"
"path/filepath"
"testing"
"time"
"github.com/omni-network/omni/lib/errors"
"github.com/omni-network/omni/lib/log"
cfg "github.com/cometbft/cometbft/config"
"github.com/spf13/viper"
)
//nolint:gochecknoglobals // Overrides cometbft default moniker for testing.
var testMoniker string
// setMonikerForT sets the test moniker for the duration of the test.
// This is required for deterministic default cometbft config.
func setMonikerForT(t *testing.T) {
t.Helper()
testMoniker = "testmoniker"
t.Cleanup(func() {
testMoniker = ""
})
}
// DefaultCometConfig returns the default cometBFT config.
func DefaultCometConfig(homeDir string) cfg.Config {
conf := cfg.DefaultConfig()
if testMoniker != "" {
conf.Moniker = testMoniker
}
conf.RootDir = homeDir
conf.SetRoot(conf.RootDir)
conf.LogLevel = "error" // Decrease default comet log level, it is super noisy.
conf.TxIndex = &cfg.TxIndexConfig{Indexer: "null"} // Disable tx indexing.
conf.StateSync.DiscoveryTime = time.Second * 10 // Increase discovery time
conf.StateSync.ChunkRequestTimeout = time.Minute // Increase timeout
conf.Mempool.Type = cfg.MempoolTypeNop // Disable cometBFT mempool
conf.ProxyApp = "" // Only support built-in ABCI app supported.
conf.ABCI = "" // Only support built-in ABCI app supported.
conf.Consensus.TimeoutPropose = time.Second // Mitigate slow blocks when proposer inactive (default=3s).
return *conf
}
// parseCometConfig parses the cometBFT config from disk and verifies it.
func parseCometConfig(ctx context.Context, homeDir string) (cfg.Config, error) {
const (
file = "config" // CometBFT config files are named config.toml
dir = "config" // CometBFT config files are stored in the config directory
)
v := viper.New()
v.SetConfigName(file)
v.AddConfigPath(filepath.Join(homeDir, dir))
// Attempt to read the cometBFT config file, gracefully ignoring errors
// caused by a config file not being found. Return an error
// if we cannot parse the config file.
if err := v.ReadInConfig(); err != nil {
// It's okay if there isn't a config file
var cfgError viper.ConfigFileNotFoundError
if ok := errors.As(err, &cfgError); !ok {
return cfg.Config{}, errors.Wrap(err, "read comet config")
}
log.Warn(ctx, "No comet config.toml file found, using default config", nil)
}
conf := DefaultCometConfig(homeDir)
if err := v.Unmarshal(&conf); err != nil {
return cfg.Config{}, errors.Wrap(err, "unmarshal comet config")
}
if err := conf.ValidateBasic(); err != nil {
return cfg.Config{}, errors.Wrap(err, "validate comet config")
}
if warnings := conf.CheckDeprecated(); len(warnings) > 0 {
for _, warning := range warnings {
log.Info(ctx, "Deprecated CometBFT config", "usage", warning)
}
}
return conf, nil
}