Browse Source

Commands compile (mostly) with new config reading

pull/484/head
Ethan Frey 8 years ago
committed by Ethan Buchman
parent
commit
92dee7ea3c
5 changed files with 25 additions and 49 deletions
  1. +2
    -2
      cmd/tendermint/commands/replay.go
  2. +8
    -20
      cmd/tendermint/commands/root.go
  3. +10
    -20
      cmd/tendermint/commands/run_node.go
  4. +3
    -5
      cmd/tendermint/main.go
  5. +2
    -2
      consensus/replay_file.go

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

@ -10,7 +10,7 @@ var replayCmd = &cobra.Command{
Use: "replay",
Short: "Replay messages from WAL",
Run: func(cmd *cobra.Command, args []string) {
consensus.RunReplayFile(&config.Config, config.Consensus, false)
consensus.RunReplayFile(config.BaseConfig, config.Consensus, false)
},
}
@ -18,7 +18,7 @@ var replayConsoleCmd = &cobra.Command{
Use: "replay_console",
Short: "Replay messages from WAL in a console",
Run: func(cmd *cobra.Command, args []string) {
consensus.RunReplayFile(&config.Config, config.Consensus, true)
consensus.RunReplayFile(config.BaseConfig, config.Consensus, true)
},
}


+ 8
- 20
cmd/tendermint/commands/root.go View File

@ -4,38 +4,26 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
cfg "github.com/tendermint/tendermint/config/tendermint"
"github.com/tendermint/tendermint/node"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tmlibs/logger"
)
var (
viperConfig *viper.Viper
config *node.Config
log = logger.New("module", "main")
config *cfg.Config
log = logger.New("module", "main")
)
func init() {
viperConfig = cfg.GetConfig("")
}
// unmarshal viper into the Tendermint config
func getConfig() *node.Config {
return node.ConfigFromViper(viperConfig)
config = cfg.DefaultConfig("REMOVE-ROOT")
RootCmd.PersistentFlags().String("log_level", config.LogLevel, "Log level")
}
var RootCmd = &cobra.Command{
Use: "tendermint",
Short: "Tendermint Core (BFT Consensus) in Go",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// set the log level
config = getConfig()
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
err := viper.Unmarshal(config)
logger.SetLogLevel(config.LogLevel)
return err
},
}
func init() {
//parse flag and set config
RootCmd.PersistentFlags().String("log_level", viperConfig.GetString("log_level"), "Log level")
viperConfig.BindPFlag("log_level", RootCmd.PersistentFlags().Lookup("log_level"))
}

+ 10
- 20
cmd/tendermint/commands/run_node.go View File

@ -18,38 +18,28 @@ var runNodeCmd = &cobra.Command{
RunE: runNode,
}
func registerRunNodeFlagString(flagName, desc string) {
runNodeCmd.Flags().String(flagName, viperConfig.GetString(flagName), desc)
viperConfig.BindPFlag(flagName, runNodeCmd.Flags().Lookup(flagName))
}
func registerRunNodeFlagBool(flagName, desc string) {
runNodeCmd.Flags().Bool(flagName, viperConfig.GetBool(flagName), desc)
viperConfig.BindPFlag(flagName, runNodeCmd.Flags().Lookup(flagName))
}
func init() {
// bind flags
runNodeCmd.Flags().String("moniker", config.Moniker, "Node Name")
// node flags
registerRunNodeFlagString("moniker", "Node Name")
registerRunNodeFlagBool("fast_sync", "Fast blockchain syncing")
runNodeCmd.Flags().Bool("fast_sync", config.FastSync, "Fast blockchain syncing")
// abci flags
registerRunNodeFlagString("proxy_app", "Proxy app address, or 'nilapp' or 'dummy' for local testing.")
registerRunNodeFlagString("abci", "Specify abci transport (socket | grpc)")
runNodeCmd.Flags().String("proxy_app", config.ProxyApp, "Proxy app address, or 'nilapp' or 'dummy' for local testing.")
runNodeCmd.Flags().String("abci", config.ABCI, "Specify abci transport (socket | grpc)")
// rpc flags
registerRunNodeFlagString("rpc_laddr", "RPC listen address. Port required")
registerRunNodeFlagString("grpc_laddr", "GRPC listen address (BroadcastTx only). Port required")
runNodeCmd.Flags().String("rpc_laddr", config.RPCListenAddress, "RPC listen address. Port required")
runNodeCmd.Flags().String("grpc_laddr", config.GRPCListenAddress, "GRPC listen address (BroadcastTx only). Port required")
// p2p flags
registerRunNodeFlagString("p2p.laddr", "Node listen address. (0.0.0.0:0 means any interface, any port)")
registerRunNodeFlagString("p2p.seeds", "Comma delimited host:port seed nodes")
registerRunNodeFlagBool("p2p.skip_upnp", "Skip UPNP configuration")
runNodeCmd.Flags().String("p2p.laddr", config.P2P.ListenAddress, "Node listen address. (0.0.0.0:0 means any interface, any port)")
runNodeCmd.Flags().String("p2p.seeds", config.P2P.Seeds, "Comma delimited host:port seed nodes")
runNodeCmd.Flags().Bool("p2p.skip_upnp", config.P2P.SkipUPNP, "Skip UPNP configuration")
// feature flags
registerRunNodeFlagBool("p2p.pex", "Enable Peer-Exchange (dev feature)")
runNodeCmd.Flags().Bool("p2p.pex", config.P2P.PexReactor, "Enable Peer-Exchange (dev feature)")
RootCmd.AddCommand(runNodeCmd)
}


+ 3
- 5
cmd/tendermint/main.go View File

@ -1,15 +1,13 @@
package main
import (
"fmt"
"os"
"github.com/tendermint/tendermint/cmd/tendermint/commands"
"github.com/tendermint/tmlibs/cli"
)
func main() {
if err := commands.RootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
cmd := cli.PrepareBaseCmd(commands.RootCmd, "TM", os.ExpandEnv("$HOME/.tendermint"))
cmd.Execute()
}

+ 2
- 2
consensus/replay_file.go View File

@ -20,7 +20,7 @@ import (
//--------------------------------------------------------
// replay messages interactively or all at once
func RunReplayFile(config *cfg.Config, csConfig *cfg.ConsensusConfig, console bool) {
func RunReplayFile(config *cfg.BaseConfig, csConfig *cfg.ConsensusConfig, console bool) {
consensusState := newConsensusStateForReplay(config, csConfig)
if err := consensusState.ReplayFile(csConfig.WalFile, console); err != nil {
@ -235,7 +235,7 @@ func (pb *playback) replayConsoleLoop() int {
//--------------------------------------------------------------------------------
// convenience for replay mode
func newConsensusStateForReplay(config *cfg.Config, csConfig *cfg.ConsensusConfig) *ConsensusState {
func newConsensusStateForReplay(config *cfg.BaseConfig, csConfig *cfg.ConsensusConfig) *ConsensusState {
// Get BlockStore
blockStoreDB := dbm.NewDB("blockstore", config.DBBackend, config.DBDir)
blockStore := bc.NewBlockStore(blockStoreDB)


Loading…
Cancel
Save