Browse Source

SetRoot

pull/484/head
Ethan Buchman 8 years ago
parent
commit
9109b20852
5 changed files with 22 additions and 19 deletions
  1. +2
    -2
      cmd/tendermint/commands/init.go
  2. +2
    -0
      cmd/tendermint/commands/root.go
  3. +15
    -14
      config/config.go
  4. +1
    -1
      config/toml.go
  5. +2
    -2
      consensus/replay_file.go

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

@ -40,8 +40,8 @@ func initFiles(cmd *cobra.Command, args []string) {
genDoc.SaveAs(genFile) 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 { } else {
log.Notice("Already initialized", "priv_validator", config.PrivValidatorFile)
log.Notice("Already initialized", "priv_validator", config.PrivValidatorFile())
} }
} }

+ 2
- 0
cmd/tendermint/commands/root.go View File

@ -23,6 +23,8 @@ var RootCmd = &cobra.Command{
Short: "Tendermint Core (BFT Consensus) in Go", Short: "Tendermint Core (BFT Consensus) in Go",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
err := viper.Unmarshal(config) err := viper.Unmarshal(config)
cfg.SetRoot(config, config.RootDir)
cfg.EnsureRoot(config.RootDir)
logger.SetLogLevel(config.LogLevel) logger.SetLogLevel(config.LogLevel)
return err return err
}, },


+ 15
- 14
config/config.go View File

@ -9,7 +9,7 @@ import (
type Config struct { type Config struct {
// Top level options use an anonymous struct // Top level options use an anonymous struct
*BaseConfig `mapstructure:",squash"`
BaseConfig `mapstructure:",squash"`
// Options for services // Options for services
P2P *P2PConfig `mapstructure:"p2p"` 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) { func SetRoot(cfg *Config, root string) {
cfg.BaseConfig.RootDir = root cfg.BaseConfig.RootDir = root
cfg.P2P.RootDir = root cfg.P2P.RootDir = root
@ -45,7 +45,8 @@ func SetRoot(cfg *Config, root string) {
// BaseConfig struct for a Tendermint node // BaseConfig struct for a Tendermint node
type BaseConfig struct { 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"` RootDir string `mapstructure:"home"`
// The ID of the chain to join (should be signed with every transaction and vote) // 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"` GRPCListenAddress string `mapstructure:"grpc_laddr"`
} }
func DefaultBaseConfig() *BaseConfig {
return &BaseConfig{
func DefaultBaseConfig() BaseConfig {
return BaseConfig{
Genesis: "genesis.json", Genesis: "genesis.json",
PrivValidator: "priv_validator.json", PrivValidator: "priv_validator.json",
Moniker: "anonymous", 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) return rootify(b.Genesis, b.RootDir)
} }
func (b *BaseConfig) PrivValidatorFile() string {
func (b BaseConfig) PrivValidatorFile() string {
return rootify(b.PrivValidator, b.RootDir) return rootify(b.PrivValidator, b.RootDir)
} }
func (b *BaseConfig) DBDir() string {
func (b BaseConfig) DBDir() string {
return rootify(b.DBPath, b.RootDir) return rootify(b.DBPath, b.RootDir)
} }
@ -156,10 +157,10 @@ func (p *P2PConfig) AddrBookFile() string {
type MempoolConfig struct { type MempoolConfig struct {
RootDir string `mapstructure:"home"` 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 { func DefaultMempoolConfig() *MempoolConfig {
@ -236,8 +237,8 @@ func DefaultConsensusConfig() *ConsensusConfig {
TimeoutCommit: 1000, TimeoutCommit: 1000,
SkipTimeoutCommit: false, SkipTimeoutCommit: false,
MaxBlockSizeTxs: 10000, MaxBlockSizeTxs: 10000,
MaxBlockSizeBytes: 1, // TODO
BlockPartSize: types.DefaultBlockPartSize,
MaxBlockSizeBytes: 1, // TODO
BlockPartSize: types.DefaultBlockPartSize, // TODO: we shouldnt be importing types
} }
} }


+ 1
- 1
config/toml.go View File

@ -10,7 +10,7 @@ import (
/****** these are for production settings ***********/ /****** these are for production settings ***********/
func initRoot(rootDir string) {
func EnsureRoot(rootDir string) {
cmn.EnsureDir(rootDir, 0700) cmn.EnsureDir(rootDir, 0700)
cmn.EnsureDir(rootDir+"/data", 0700) cmn.EnsureDir(rootDir+"/data", 0700)


+ 2
- 2
consensus/replay_file.go View File

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


Loading…
Cancel
Save