Browse Source

node: ConfigFromViper

pull/484/head
Ethan Buchman 8 years ago
parent
commit
7db7bbe464
4 changed files with 19 additions and 18 deletions
  1. +2
    -2
      cmd/tendermint/commands/replay.go
  2. +1
    -5
      cmd/tendermint/commands/root.go
  3. +14
    -10
      node/node.go
  4. +2
    -1
      node/node_test.go

+ 2
- 2
cmd/tendermint/commands/replay.go View File

@ -11,7 +11,7 @@ var replayCmd = &cobra.Command{
Short: "Replay messages from WAL",
Run: func(cmd *cobra.Command, args []string) {
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",
Run: func(cmd *cobra.Command, args []string) {
config := getConfig()
consensus.RunReplayFile(config.Config, config.Consensus, true)
consensus.RunReplayFile(&config.Config, config.Consensus, true)
},
}


+ 1
- 5
cmd/tendermint/commands/root.go View File

@ -23,11 +23,7 @@ func init() {
// unmarshal viper into the Tendermint config
func getConfig() *node.Config {
config := new(node.Config)
if err := viperConfig.Unmarshal(config); err != nil {
panic(err)
}
return config
return node.ConfigFromViper(viperConfig)
}
//global flag


+ 14
- 10
node/node.go View File

@ -37,23 +37,31 @@ import (
type Config struct {
// Top level options use an anonymous struct
*cfg.Config `mapstructure:",squash"`
cfg.Config `mapstructure:",squash"`
// Options for services
P2P *p2p.NetworkConfig `mapstructure:"p2p"`
Mempool *mempl.Config `mapstructure:"mempool"`
Consensus *consensus.Config `mapstructure:"consensus"`
P2P *p2p.Config `mapstructure:"p2p"`
Mempool *mempl.Config `mapstructure:"mempool"`
Consensus *consensus.Config `mapstructure:"consensus"`
}
func NewDefaultConfig(rootDir string) *Config {
return &Config{
Config: cfg.NewDefaultConfig(rootDir),
Config: *cfg.NewDefaultConfig(rootDir),
P2P: p2p.NewDefaultConfig(rootDir),
Mempool: mempl.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 {
cmn.BaseService
@ -156,11 +164,7 @@ func NewNode(config *Config, privValidator *types.PrivValidator, clientCreator p
}
consensusReactor := consensus.NewConsensusReactor(consensusState, fastSync)
// Make p2p network switch
// TODO : p2pConfig := config.P2P
p2pConfig := viper.New()
sw := p2p.NewSwitch(p2pConfig)
sw := p2p.NewSwitch(config.P2P)
sw.AddReactor("MEMPOOL", mempoolReactor)
sw.AddReactor("BLOCKCHAIN", bcReactor)
sw.AddReactor("CONSENSUS", consensusReactor)


+ 2
- 1
node/node_test.go View File

@ -8,7 +8,8 @@ import (
)
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
n := NewNodeDefault(config)


Loading…
Cancel
Save