This commit is contained in:
Ethan Buchman 2017-05-04 21:59:53 -04:00
parent 6b059e0063
commit 9109b20852
5 changed files with 22 additions and 19 deletions

View File

@ -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())
}
}

View File

@ -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
},

View File

@ -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
}
}

View File

@ -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)

View File

@ -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)