From 9109b20852ec7c414e8c8d44ea4a661c428072b3 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Thu, 4 May 2017 21:59:53 -0400 Subject: [PATCH] SetRoot --- cmd/tendermint/commands/init.go | 4 ++-- cmd/tendermint/commands/root.go | 2 ++ config/config.go | 29 +++++++++++++++-------------- config/toml.go | 2 +- consensus/replay_file.go | 4 ++-- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/cmd/tendermint/commands/init.go b/cmd/tendermint/commands/init.go index 5c3fbb52a..ba3b711b3 100644 --- a/cmd/tendermint/commands/init.go +++ b/cmd/tendermint/commands/init.go @@ -40,8 +40,8 @@ func initFiles(cmd *cobra.Command, args []string) { genDoc.SaveAs(genFile) } - log.Notice("Initialized tendermint", "genesis", config.GenesisFile, "priv_validator", config.PrivValidatorFile) + log.Notice("Initialized tendermint", "genesis", config.GenesisFile(), "priv_validator", config.PrivValidatorFile()) } else { - log.Notice("Already initialized", "priv_validator", config.PrivValidatorFile) + log.Notice("Already initialized", "priv_validator", config.PrivValidatorFile()) } } diff --git a/cmd/tendermint/commands/root.go b/cmd/tendermint/commands/root.go index 28527b7f1..5771a9b29 100644 --- a/cmd/tendermint/commands/root.go +++ b/cmd/tendermint/commands/root.go @@ -23,6 +23,8 @@ var RootCmd = &cobra.Command{ Short: "Tendermint Core (BFT Consensus) in Go", PersistentPreRunE: func(cmd *cobra.Command, args []string) error { err := viper.Unmarshal(config) + cfg.SetRoot(config, config.RootDir) + cfg.EnsureRoot(config.RootDir) logger.SetLogLevel(config.LogLevel) return err }, diff --git a/config/config.go b/config/config.go index 7490f8037..178f19dbc 100644 --- a/config/config.go +++ b/config/config.go @@ -9,7 +9,7 @@ import ( type Config struct { // Top level options use an anonymous struct - *BaseConfig `mapstructure:",squash"` + BaseConfig `mapstructure:",squash"` // Options for services P2P *P2PConfig `mapstructure:"p2p"` @@ -35,7 +35,7 @@ func TestConfig() *Config { } } -// TODO: set this from root or home.... or default.... +// Set the RootDir for all Config structs func SetRoot(cfg *Config, root string) { cfg.BaseConfig.RootDir = root cfg.P2P.RootDir = root @@ -45,7 +45,8 @@ func SetRoot(cfg *Config, root string) { // BaseConfig struct for a Tendermint node type BaseConfig struct { - // TODO: set this from root or home.... or default.... + // The root directory for all data. + // This should be set in viper so it can unmarshal into this struct RootDir string `mapstructure:"home"` // The ID of the chain to join (should be signed with every transaction and vote) @@ -99,8 +100,8 @@ type BaseConfig struct { GRPCListenAddress string `mapstructure:"grpc_laddr"` } -func DefaultBaseConfig() *BaseConfig { - return &BaseConfig{ +func DefaultBaseConfig() BaseConfig { + return BaseConfig{ Genesis: "genesis.json", PrivValidator: "priv_validator.json", Moniker: "anonymous", @@ -118,15 +119,15 @@ func DefaultBaseConfig() *BaseConfig { } } -func (b *BaseConfig) GenesisFile() string { +func (b BaseConfig) GenesisFile() string { return rootify(b.Genesis, b.RootDir) } -func (b *BaseConfig) PrivValidatorFile() string { +func (b BaseConfig) PrivValidatorFile() string { return rootify(b.PrivValidator, b.RootDir) } -func (b *BaseConfig) DBDir() string { +func (b BaseConfig) DBDir() string { return rootify(b.DBPath, b.RootDir) } @@ -156,10 +157,10 @@ func (p *P2PConfig) AddrBookFile() string { type MempoolConfig struct { RootDir string `mapstructure:"home"` - Recheck bool `mapstructure:"recheck"` // true - RecheckEmpty bool `mapstructure:"recheck_empty"` // true - Broadcast bool `mapstructure:"broadcast"` // true - WalPath string `mapstructure:"wal_dir"` // + Recheck bool `mapstructure:"recheck"` + RecheckEmpty bool `mapstructure:"recheck_empty"` + Broadcast bool `mapstructure:"broadcast"` + WalPath string `mapstructure:"wal_dir"` } func DefaultMempoolConfig() *MempoolConfig { @@ -236,8 +237,8 @@ func DefaultConsensusConfig() *ConsensusConfig { TimeoutCommit: 1000, SkipTimeoutCommit: false, MaxBlockSizeTxs: 10000, - MaxBlockSizeBytes: 1, // TODO - BlockPartSize: types.DefaultBlockPartSize, + MaxBlockSizeBytes: 1, // TODO + BlockPartSize: types.DefaultBlockPartSize, // TODO: we shouldnt be importing types } } diff --git a/config/toml.go b/config/toml.go index a9e6ba302..aff6bd1aa 100644 --- a/config/toml.go +++ b/config/toml.go @@ -10,7 +10,7 @@ import ( /****** these are for production settings ***********/ -func initRoot(rootDir string) { +func EnsureRoot(rootDir string) { cmn.EnsureDir(rootDir, 0700) cmn.EnsureDir(rootDir+"/data", 0700) diff --git a/consensus/replay_file.go b/consensus/replay_file.go index 3735f8942..a0af8b853 100644 --- a/consensus/replay_file.go +++ b/consensus/replay_file.go @@ -20,7 +20,7 @@ import ( //-------------------------------------------------------- // replay messages interactively or all at once -func RunReplayFile(config *cfg.BaseConfig, 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.BaseConfig, 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)