mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-14 13:51:21 +00:00
node: ConfigFromViper
This commit is contained in:
@ -11,7 +11,7 @@ var replayCmd = &cobra.Command{
|
|||||||
Short: "Replay messages from WAL",
|
Short: "Replay messages from WAL",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
config := getConfig()
|
config := getConfig()
|
||||||
consensus.RunReplayFile(config.Config, config.Consensus, false)
|
consensus.RunReplayFile(&config.Config, config.Consensus, false)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ var replayConsoleCmd = &cobra.Command{
|
|||||||
Short: "Replay messages from WAL in a console",
|
Short: "Replay messages from WAL in a console",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
config := getConfig()
|
config := getConfig()
|
||||||
consensus.RunReplayFile(config.Config, config.Consensus, true)
|
consensus.RunReplayFile(&config.Config, config.Consensus, true)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,11 +23,7 @@ func init() {
|
|||||||
|
|
||||||
// unmarshal viper into the Tendermint config
|
// unmarshal viper into the Tendermint config
|
||||||
func getConfig() *node.Config {
|
func getConfig() *node.Config {
|
||||||
config := new(node.Config)
|
return node.ConfigFromViper(viperConfig)
|
||||||
if err := viperConfig.Unmarshal(config); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return config
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//global flag
|
//global flag
|
||||||
|
24
node/node.go
24
node/node.go
@ -37,23 +37,31 @@ import (
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
// Top level options use an anonymous struct
|
// Top level options use an anonymous struct
|
||||||
*cfg.Config `mapstructure:",squash"`
|
cfg.Config `mapstructure:",squash"`
|
||||||
|
|
||||||
// Options for services
|
// Options for services
|
||||||
P2P *p2p.NetworkConfig `mapstructure:"p2p"`
|
P2P *p2p.Config `mapstructure:"p2p"`
|
||||||
Mempool *mempl.Config `mapstructure:"mempool"`
|
Mempool *mempl.Config `mapstructure:"mempool"`
|
||||||
Consensus *consensus.Config `mapstructure:"consensus"`
|
Consensus *consensus.Config `mapstructure:"consensus"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDefaultConfig(rootDir string) *Config {
|
func NewDefaultConfig(rootDir string) *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
Config: cfg.NewDefaultConfig(rootDir),
|
Config: *cfg.NewDefaultConfig(rootDir),
|
||||||
P2P: p2p.NewDefaultConfig(rootDir),
|
P2P: p2p.NewDefaultConfig(rootDir),
|
||||||
Mempool: mempl.NewDefaultConfig(rootDir),
|
Mempool: mempl.NewDefaultConfig(rootDir),
|
||||||
Consensus: consensus.NewDefaultConfig(rootDir),
|
Consensus: consensus.NewDefaultConfig(rootDir),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ConfigFromViper(viperConfig *viper.Viper) *Config {
|
||||||
|
tmConfig := new(Config)
|
||||||
|
if err := viperConfig.Unmarshal(tmConfig); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return tmConfig
|
||||||
|
}
|
||||||
|
|
||||||
type Node struct {
|
type Node struct {
|
||||||
cmn.BaseService
|
cmn.BaseService
|
||||||
|
|
||||||
@ -156,11 +164,7 @@ func NewNode(config *Config, privValidator *types.PrivValidator, clientCreator p
|
|||||||
}
|
}
|
||||||
consensusReactor := consensus.NewConsensusReactor(consensusState, fastSync)
|
consensusReactor := consensus.NewConsensusReactor(consensusState, fastSync)
|
||||||
|
|
||||||
// Make p2p network switch
|
sw := p2p.NewSwitch(config.P2P)
|
||||||
// TODO : p2pConfig := config.P2P
|
|
||||||
p2pConfig := viper.New()
|
|
||||||
|
|
||||||
sw := p2p.NewSwitch(p2pConfig)
|
|
||||||
sw.AddReactor("MEMPOOL", mempoolReactor)
|
sw.AddReactor("MEMPOOL", mempoolReactor)
|
||||||
sw.AddReactor("BLOCKCHAIN", bcReactor)
|
sw.AddReactor("BLOCKCHAIN", bcReactor)
|
||||||
sw.AddReactor("CONSENSUS", consensusReactor)
|
sw.AddReactor("CONSENSUS", consensusReactor)
|
||||||
|
@ -8,7 +8,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestNodeStartStop(t *testing.T) {
|
func TestNodeStartStop(t *testing.T) {
|
||||||
config := tendermint_test.ResetConfig("node_node_test")
|
viperConfig := tendermint_test.ResetConfig("node_node_test")
|
||||||
|
config := ConfigFromViper(viperConfig)
|
||||||
|
|
||||||
// Create & start node
|
// Create & start node
|
||||||
n := NewNodeDefault(config)
|
n := NewNodeDefault(config)
|
||||||
|
Reference in New Issue
Block a user