diff --git a/blockchain/reactor.go b/blockchain/reactor.go index a788c4aca..f45975e00 100644 --- a/blockchain/reactor.go +++ b/blockchain/reactor.go @@ -6,13 +6,15 @@ import ( "reflect" "time" - cmn "github.com/tendermint/tmlibs/common" + "github.com/spf13/viper" + cfg "github.com/tendermint/go-config" - "github.com/tendermint/tendermint/p2p" "github.com/tendermint/go-wire" + "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/proxy" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" + cmn "github.com/tendermint/tmlibs/common" ) const ( @@ -43,7 +45,7 @@ type consensusReactor interface { type BlockchainReactor struct { p2p.BaseReactor - config cfg.Config + config *viper.Viper state *sm.State proxyAppConn proxy.AppConnConsensus // same as consensus.proxyAppConn store *BlockStore @@ -57,7 +59,7 @@ type BlockchainReactor struct { } // NewBlockchainReactor returns new reactor instance. -func NewBlockchainReactor(config cfg.Config, state *sm.State, proxyAppConn proxy.AppConnConsensus, store *BlockStore, fastSync bool) *BlockchainReactor { +func NewBlockchainReactor(config *viper.Viper, state *sm.State, proxyAppConn proxy.AppConnConsensus, store *BlockStore, fastSync bool) *BlockchainReactor { if state.LastBlockHeight == store.Height()-1 { store.height-- // XXX HACK, make this better } diff --git a/cmd/tendermint/commands/root.go b/cmd/tendermint/commands/root.go index 120d53c04..78d197289 100644 --- a/cmd/tendermint/commands/root.go +++ b/cmd/tendermint/commands/root.go @@ -2,9 +2,10 @@ package commands import ( "github.com/spf13/cobra" + "github.com/spf13/viper" - "github.com/tendermint/tmlibs/logger" tmcfg "github.com/tendermint/tendermint/config/tendermint" + "github.com/tendermint/tmlibs/logger" ) var ( diff --git a/config/tendermint/config.go b/config/tendermint/config.go index 93650eaef..2e8cbb538 100644 --- a/config/tendermint/config.go +++ b/config/tendermint/config.go @@ -5,8 +5,10 @@ import ( "path" "strings" - . "github.com/tendermint/tmlibs/common" + "github.com/spf13/viper" + cfg "github.com/tendermint/go-config" + . "github.com/tendermint/tmlibs/common" ) func getTMRoot(rootDir string) string { @@ -38,72 +40,76 @@ func initTMRoot(rootDir string) { } } -func GetConfig(rootDir string) cfg.Config { +func GetConfig(rootDir string) *viper.Viper { rootDir = getTMRoot(rootDir) initTMRoot(rootDir) - configFilePath := path.Join(rootDir, "config.toml") - mapConfig, err := cfg.ReadMapConfigFromFile(configFilePath) + config := viper.New() + config.SetConfigName("config") + config.SetConfigType("toml") + config.AddConfigPath(rootDir) + err := viper.ReadInConfig() if err != nil { Exit(Fmt("Could not read config: %v", err)) } + config.WatchConfig() // Set defaults or panic - if mapConfig.IsSet("chain_id") { + if config.IsSet("chain_id") { Exit("Cannot set 'chain_id' via config.toml") } - if mapConfig.IsSet("revision_file") { + if config.IsSet("revision_file") { Exit("Cannot set 'revision_file' via config.toml. It must match what's in the Makefile") } - mapConfig.SetRequired("chain_id") // blows up if you try to use it before setting. - mapConfig.SetDefault("genesis_file", rootDir+"/genesis.json") - mapConfig.SetDefault("proxy_app", "tcp://127.0.0.1:46658") - mapConfig.SetDefault("abci", "socket") - mapConfig.SetDefault("moniker", "anonymous") - mapConfig.SetDefault("node_laddr", "tcp://0.0.0.0:46656") - mapConfig.SetDefault("seeds", "") - // mapConfig.SetDefault("seeds", "goldenalchemist.chaintest.net:46656") - mapConfig.SetDefault("fast_sync", true) - mapConfig.SetDefault("skip_upnp", false) - mapConfig.SetDefault("addrbook_file", rootDir+"/addrbook.json") - mapConfig.SetDefault("addrbook_strict", true) // disable to allow connections locally - mapConfig.SetDefault("pex_reactor", false) // enable for peer exchange - mapConfig.SetDefault("priv_validator_file", rootDir+"/priv_validator.json") - mapConfig.SetDefault("db_backend", "leveldb") - mapConfig.SetDefault("db_dir", rootDir+"/data") - mapConfig.SetDefault("log_level", "info") - mapConfig.SetDefault("rpc_laddr", "tcp://0.0.0.0:46657") - mapConfig.SetDefault("grpc_laddr", "") - mapConfig.SetDefault("prof_laddr", "") - mapConfig.SetDefault("revision_file", rootDir+"/revision") - mapConfig.SetDefault("cs_wal_file", rootDir+"/data/cs.wal/wal") - mapConfig.SetDefault("cs_wal_light", false) - mapConfig.SetDefault("filter_peers", false) - - mapConfig.SetDefault("block_size", 10000) // max number of txs - mapConfig.SetDefault("block_part_size", 65536) // part size 64K - mapConfig.SetDefault("disable_data_hash", false) + //mapConfig.SetRequired("chain_id") // blows up if you try to use it before setting. + config.SetDefault("genesis_file", rootDir+"/genesis.json") + config.SetDefault("proxy_app", "tcp://127.0.0.1:46658") + config.SetDefault("abci", "socket") + config.SetDefault("moniker", "anonymous") + config.SetDefault("node_laddr", "tcp://0.0.0.0:46656") + config.SetDefault("seeds", "") + // config.SetDefault("seeds", "goldenalchemist.chaintest.net:46656") + config.SetDefault("fast_sync", true) + config.SetDefault("skip_upnp", false) + config.SetDefault("addrbook_file", rootDir+"/addrbook.json") + config.SetDefault("addrbook_strict", true) // disable to allow connections locally + config.SetDefault("pex_reactor", false) // enable for peer exchange + config.SetDefault("priv_validator_file", rootDir+"/priv_validator.json") + config.SetDefault("db_backend", "leveldb") + config.SetDefault("db_dir", rootDir+"/data") + config.SetDefault("log_level", "info") + config.SetDefault("rpc_laddr", "tcp://0.0.0.0:46657") + config.SetDefault("grpc_laddr", "") + config.SetDefault("prof_laddr", "") + config.SetDefault("revision_file", rootDir+"/revision") + config.SetDefault("cs_wal_file", rootDir+"/data/cs.wal/wal") + config.SetDefault("cs_wal_light", false) + config.SetDefault("filter_peers", false) + + config.SetDefault("block_size", 10000) // max number of txs + config.SetDefault("block_part_size", 65536) // part size 64K + config.SetDefault("disable_data_hash", false) // all timeouts are in ms - mapConfig.SetDefault("timeout_handshake", 10000) - mapConfig.SetDefault("timeout_propose", 3000) - mapConfig.SetDefault("timeout_propose_delta", 500) - mapConfig.SetDefault("timeout_prevote", 1000) - mapConfig.SetDefault("timeout_prevote_delta", 500) - mapConfig.SetDefault("timeout_precommit", 1000) - mapConfig.SetDefault("timeout_precommit_delta", 500) - mapConfig.SetDefault("timeout_commit", 1000) + config.SetDefault("timeout_handshake", 10000) + config.SetDefault("timeout_propose", 3000) + config.SetDefault("timeout_propose_delta", 500) + config.SetDefault("timeout_prevote", 1000) + config.SetDefault("timeout_prevote_delta", 500) + config.SetDefault("timeout_precommit", 1000) + config.SetDefault("timeout_precommit_delta", 500) + config.SetDefault("timeout_commit", 1000) // make progress asap (no `timeout_commit`) on full precommit votes - mapConfig.SetDefault("skip_timeout_commit", false) - mapConfig.SetDefault("mempool_recheck", true) - mapConfig.SetDefault("mempool_recheck_empty", true) - mapConfig.SetDefault("mempool_broadcast", true) - mapConfig.SetDefault("mempool_wal_dir", rootDir+"/data/mempool.wal") + config.SetDefault("skip_timeout_commit", false) + config.SetDefault("mempool_recheck", true) + config.SetDefault("mempool_recheck_empty", true) + config.SetDefault("mempool_broadcast", true) + config.SetDefault("mempool_wal_dir", rootDir+"/data/mempool.wal") - mapConfig.SetDefault("tx_index", "kv") + config.SetDefault("tx_index", "kv") - return mapConfig + return config } var defaultConfigTmpl = `# This is a TOML config file. diff --git a/config/tendermint_test/config.go b/config/tendermint_test/config.go index fcdc572b9..846d28c64 100644 --- a/config/tendermint_test/config.go +++ b/config/tendermint_test/config.go @@ -3,12 +3,15 @@ package tendermint_test import ( + "fmt" "os" "path" "strings" - . "github.com/tendermint/tmlibs/common" + "github.com/spf13/viper" + cfg "github.com/tendermint/go-config" + . "github.com/tendermint/tmlibs/common" "github.com/tendermint/tmlibs/logger" ) @@ -53,65 +56,70 @@ func initTMRoot(rootDir string) { MustWriteFile(privFilePath, []byte(defaultPrivValidator), 0644) } -func ResetConfig(localPath string) cfg.Config { +func ResetConfig(localPath string) *viper.Viper { rootDir := os.Getenv("HOME") + "/.tendermint_test/" + localPath initTMRoot(rootDir) - configFilePath := path.Join(rootDir, "config.toml") - mapConfig, err := cfg.ReadMapConfigFromFile(configFilePath) + config := viper.New() + config.SetConfigName("config") + config.SetConfigType("toml") + config.AddConfigPath(rootDir) + err := config.ReadInConfig() if err != nil { Exit(Fmt("Could not read config: %v", err)) } + config.WatchConfig() // Set defaults or panic - if mapConfig.IsSet("chain_id") { - Exit("Cannot set 'chain_id' via config.toml") + if config.IsSet("chain_id") { + Exit(fmt.Sprintf("Cannot set 'chain_id' via config.toml:\n %v\n %v\n ", config.Get("chain_id"), rootDir)) } - mapConfig.SetDefault("chain_id", "tendermint_test") - mapConfig.SetDefault("genesis_file", rootDir+"/genesis.json") - mapConfig.SetDefault("proxy_app", "dummy") - mapConfig.SetDefault("abci", "socket") - mapConfig.SetDefault("moniker", "anonymous") - mapConfig.SetDefault("node_laddr", "tcp://0.0.0.0:36656") - mapConfig.SetDefault("fast_sync", false) - mapConfig.SetDefault("skip_upnp", true) - mapConfig.SetDefault("addrbook_file", rootDir+"/addrbook.json") - mapConfig.SetDefault("addrbook_strict", true) // disable to allow connections locally - mapConfig.SetDefault("pex_reactor", false) // enable for peer exchange - mapConfig.SetDefault("priv_validator_file", rootDir+"/priv_validator.json") - mapConfig.SetDefault("db_backend", "memdb") - mapConfig.SetDefault("db_dir", rootDir+"/data") - mapConfig.SetDefault("log_level", "info") - mapConfig.SetDefault("rpc_laddr", "tcp://0.0.0.0:36657") - mapConfig.SetDefault("grpc_laddr", "tcp://0.0.0.0:36658") - mapConfig.SetDefault("prof_laddr", "") - mapConfig.SetDefault("revision_file", rootDir+"/revision") - mapConfig.SetDefault("cs_wal_file", rootDir+"/data/cs.wal/wal") - mapConfig.SetDefault("cs_wal_light", false) - mapConfig.SetDefault("filter_peers", false) - - mapConfig.SetDefault("block_size", 10000) - mapConfig.SetDefault("block_part_size", 65536) // part size 64K - mapConfig.SetDefault("disable_data_hash", false) - mapConfig.SetDefault("timeout_handshake", 10000) - mapConfig.SetDefault("timeout_propose", 2000) - mapConfig.SetDefault("timeout_propose_delta", 1) - mapConfig.SetDefault("timeout_prevote", 10) - mapConfig.SetDefault("timeout_prevote_delta", 1) - mapConfig.SetDefault("timeout_precommit", 10) - mapConfig.SetDefault("timeout_precommit_delta", 1) - mapConfig.SetDefault("timeout_commit", 10) - mapConfig.SetDefault("skip_timeout_commit", true) - mapConfig.SetDefault("mempool_recheck", true) - mapConfig.SetDefault("mempool_recheck_empty", true) - mapConfig.SetDefault("mempool_broadcast", true) - mapConfig.SetDefault("mempool_wal_dir", "") - - mapConfig.SetDefault("tx_index", "kv") - - logger.SetLogLevel(mapConfig.GetString("log_level")) - - return mapConfig + + config.SetDefault("chain_id", "tendermint_test") + config.SetDefault("genesis_file", rootDir+"/genesis.json") + config.SetDefault("proxy_app", "dummy") + config.SetDefault("abci", "socket") + config.SetDefault("moniker", "anonymous") + config.SetDefault("node_laddr", "tcp://0.0.0.0:36656") + config.SetDefault("fast_sync", false) + config.SetDefault("skip_upnp", true) + config.SetDefault("addrbook_file", rootDir+"/addrbook.json") + config.SetDefault("addrbook_strict", true) // disable to allow connections locally + config.SetDefault("pex_reactor", false) // enable for peer exchange + config.SetDefault("priv_validator_file", rootDir+"/priv_validator.json") + config.SetDefault("db_backend", "memdb") + config.SetDefault("db_dir", rootDir+"/data") + config.SetDefault("log_level", "info") + config.SetDefault("rpc_laddr", "tcp://0.0.0.0:36657") + config.SetDefault("grpc_laddr", "tcp://0.0.0.0:36658") + config.SetDefault("prof_laddr", "") + config.SetDefault("revision_file", rootDir+"/revision") + config.SetDefault("cs_wal_file", rootDir+"/data/cs.wal/wal") + config.SetDefault("cs_wal_light", false) + config.SetDefault("filter_peers", false) + + config.SetDefault("block_size", 10000) + config.SetDefault("block_part_size", 65536) // part size 64K + config.SetDefault("disable_data_hash", false) + config.SetDefault("timeout_handshake", 10000) + config.SetDefault("timeout_propose", 2000) + config.SetDefault("timeout_propose_delta", 1) + config.SetDefault("timeout_prevote", 10) + config.SetDefault("timeout_prevote_delta", 1) + config.SetDefault("timeout_precommit", 10) + config.SetDefault("timeout_precommit_delta", 1) + config.SetDefault("timeout_commit", 10) + config.SetDefault("skip_timeout_commit", true) + config.SetDefault("mempool_recheck", true) + config.SetDefault("mempool_recheck_empty", true) + config.SetDefault("mempool_broadcast", true) + config.SetDefault("mempool_wal_dir", "") + + config.SetDefault("tx_index", "kv") + + logger.SetLogLevel(config.GetString("log_level")) + + return config } var defaultConfigTmpl = `# This is a TOML config file. diff --git a/consensus/byzantine_test.go b/consensus/byzantine_test.go index acd9e90e2..d4cda4046 100644 --- a/consensus/byzantine_test.go +++ b/consensus/byzantine_test.go @@ -5,13 +5,15 @@ import ( "testing" "time" + "github.com/spf13/viper" + "github.com/tendermint/tendermint/config/tendermint_test" - . "github.com/tendermint/tmlibs/common" cfg "github.com/tendermint/go-config" - "github.com/tendermint/tmlibs/events" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/types" + . "github.com/tendermint/tmlibs/common" + "github.com/tendermint/tmlibs/events" ) func init() { @@ -36,7 +38,7 @@ func TestByzantine(t *testing.T) { switches := make([]*p2p.Switch, N) for i := 0; i < N; i++ { - switches[i] = p2p.NewSwitch(cfg.NewMapConfig(nil)) + switches[i] = p2p.NewSwitch(viper.New()) } reactors := make([]p2p.Reactor, N) diff --git a/consensus/common_test.go b/consensus/common_test.go index 77cc8172a..7acb54ad7 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -11,23 +11,25 @@ import ( "testing" "time" + "github.com/spf13/viper" + abcicli "github.com/tendermint/abci/client" abci "github.com/tendermint/abci/types" - . "github.com/tendermint/tmlibs/common" cfg "github.com/tendermint/go-config" - dbm "github.com/tendermint/tmlibs/db" - "github.com/tendermint/tendermint/p2p" bc "github.com/tendermint/tendermint/blockchain" "github.com/tendermint/tendermint/config/tendermint_test" mempl "github.com/tendermint/tendermint/mempool" + "github.com/tendermint/tendermint/p2p" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" + . "github.com/tendermint/tmlibs/common" + dbm "github.com/tendermint/tmlibs/db" "github.com/tendermint/abci/example/counter" "github.com/tendermint/abci/example/dummy" ) -var config cfg.Config // NOTE: must be reset for each _test.go file +var config *viper.Viper // NOTE: must be reset for each _test.go file var ensureTimeout = time.Duration(2) func ensureDir(dir string, mode os.FileMode) { @@ -233,7 +235,7 @@ func newConsensusState(state *sm.State, pv *types.PrivValidator, app abci.Applic return newConsensusStateWithConfig(config, state, pv, app) } -func newConsensusStateWithConfig(thisConfig cfg.Config, state *sm.State, pv *types.PrivValidator, app abci.Application) *ConsensusState { +func newConsensusStateWithConfig(thisConfig *viper.Viper, state *sm.State, pv *types.PrivValidator, app abci.Application) *ConsensusState { // Get BlockStore blockDB := dbm.NewMemDB() blockStore := bc.NewBlockStore(blockDB) @@ -256,7 +258,7 @@ func newConsensusStateWithConfig(thisConfig cfg.Config, state *sm.State, pv *typ return cs } -func loadPrivValidator(conf cfg.Config) *types.PrivValidator { +func loadPrivValidator(conf *viper.Viper) *types.PrivValidator { privValidatorFile := conf.GetString("priv_validator_file") ensureDir(path.Dir(privValidatorFile), 0700) privValidator := types.LoadOrGenPrivValidator(privValidatorFile) diff --git a/consensus/replay.go b/consensus/replay.go index 931e8893d..acbe44098 100644 --- a/consensus/replay.go +++ b/consensus/replay.go @@ -10,11 +10,13 @@ import ( "strings" "time" + "github.com/spf13/viper" + abci "github.com/tendermint/abci/types" - auto "github.com/tendermint/tmlibs/autofile" - . "github.com/tendermint/tmlibs/common" cfg "github.com/tendermint/go-config" "github.com/tendermint/go-wire" + auto "github.com/tendermint/tmlibs/autofile" + . "github.com/tendermint/tmlibs/common" "github.com/tendermint/tendermint/proxy" sm "github.com/tendermint/tendermint/state" @@ -199,14 +201,14 @@ func makeHeightSearchFunc(height int) auto.SearchFunc { // we were last and using the WAL to recover there type Handshaker struct { - config cfg.Config + config *viper.Viper state *sm.State store types.BlockStore nBlocks int // number of blocks applied to the state } -func NewHandshaker(config cfg.Config, state *sm.State, store types.BlockStore) *Handshaker { +func NewHandshaker(config *viper.Viper, state *sm.State, store types.BlockStore) *Handshaker { return &Handshaker{config, state, store, 0} } diff --git a/consensus/replay_file.go b/consensus/replay_file.go index 3de0e3d10..e5056ef0d 100644 --- a/consensus/replay_file.go +++ b/consensus/replay_file.go @@ -8,20 +8,22 @@ import ( "strconv" "strings" - . "github.com/tendermint/tmlibs/common" + "github.com/spf13/viper" + cfg "github.com/tendermint/go-config" - dbm "github.com/tendermint/tmlibs/db" bc "github.com/tendermint/tendermint/blockchain" mempl "github.com/tendermint/tendermint/mempool" "github.com/tendermint/tendermint/proxy" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" + . "github.com/tendermint/tmlibs/common" + dbm "github.com/tendermint/tmlibs/db" ) //-------------------------------------------------------- // replay messages interactively or all at once -func RunReplayFile(config cfg.Config, walFile string, console bool) { +func RunReplayFile(config *viper.Viper, walFile string, console bool) { consensusState := newConsensusStateForReplay(config) if err := consensusState.ReplayFile(walFile, console); err != nil { @@ -236,7 +238,7 @@ func (pb *playback) replayConsoleLoop() int { //-------------------------------------------------------------------------------- // convenience for replay mode -func newConsensusStateForReplay(config cfg.Config) *ConsensusState { +func newConsensusStateForReplay(config *viper.Viper) *ConsensusState { // Get BlockStore blockStoreDB := dbm.NewDB("blockstore", config.GetString("db_backend"), config.GetString("db_dir")) blockStore := bc.NewBlockStore(blockStoreDB) diff --git a/consensus/replay_test.go b/consensus/replay_test.go index 32415d6e3..b78d5915f 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -12,17 +12,18 @@ import ( "testing" "time" - "github.com/tendermint/tendermint/config/tendermint_test" + "github.com/spf13/viper" "github.com/tendermint/abci/example/dummy" - cmn "github.com/tendermint/tmlibs/common" cfg "github.com/tendermint/go-config" "github.com/tendermint/go-crypto" - dbm "github.com/tendermint/tmlibs/db" "github.com/tendermint/go-wire" + "github.com/tendermint/tendermint/config/tendermint_test" "github.com/tendermint/tendermint/proxy" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" + cmn "github.com/tendermint/tmlibs/common" + dbm "github.com/tendermint/tmlibs/db" ) func init() { @@ -408,7 +409,7 @@ func buildAppStateFromChain(proxyApp proxy.AppConns, } -func buildTMStateFromChain(config cfg.Config, state *sm.State, chain []*types.Block, mode uint) []byte { +func buildTMStateFromChain(config *viper.Viper, state *sm.State, chain []*types.Block, mode uint) []byte { // run the whole chain against this client to build up the tendermint state clientCreator := proxy.NewLocalClientCreator(dummy.NewPersistentDummyApplication(path.Join(config.GetString("db_dir"), "1"))) proxyApp := proxy.NewAppConns(config, clientCreator, nil) // sm.NewHandshaker(config, state, store, ReplayLastBlock)) @@ -602,7 +603,7 @@ func makeBlockchain(t *testing.T, chainID string, nBlocks int, privVal *types.Pr } // fresh state and mock store -func stateAndStore(config cfg.Config, pubKey crypto.PubKey) (*sm.State, *mockBlockStore) { +func stateAndStore(config *viper.Viper, pubKey crypto.PubKey) (*sm.State, *mockBlockStore) { stateDB := dbm.NewMemDB() return sm.MakeGenesisState(stateDB, &types.GenesisDoc{ ChainID: config.GetString("chain_id"), @@ -617,13 +618,13 @@ func stateAndStore(config cfg.Config, pubKey crypto.PubKey) (*sm.State, *mockBlo // mock block store type mockBlockStore struct { - config cfg.Config + config *viper.Viper chain []*types.Block commits []*types.Commit } // TODO: NewBlockStore(db.NewMemDB) ... -func NewMockBlockStore(config cfg.Config) *mockBlockStore { +func NewMockBlockStore(config *viper.Viper) *mockBlockStore { return &mockBlockStore{config, nil, nil} } diff --git a/consensus/state.go b/consensus/state.go index 8077dcec1..06c20db2a 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -10,13 +10,14 @@ import ( "time" "github.com/ebuchman/fail-test" + "github.com/spf13/viper" - . "github.com/tendermint/tmlibs/common" cfg "github.com/tendermint/go-config" "github.com/tendermint/go-wire" "github.com/tendermint/tendermint/proxy" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" + . "github.com/tendermint/tmlibs/common" ) //----------------------------------------------------------------------------- @@ -56,7 +57,7 @@ func (tp *TimeoutParams) Commit(t time.Time) time.Time { } // InitTimeoutParamsFromConfig initializes parameters from config -func InitTimeoutParamsFromConfig(config cfg.Config) *TimeoutParams { +func InitTimeoutParamsFromConfig(config *viper.Viper) *TimeoutParams { return &TimeoutParams{ Propose0: config.GetInt("timeout_propose"), ProposeDelta: config.GetInt("timeout_propose_delta"), @@ -224,7 +225,7 @@ type PrivValidator interface { type ConsensusState struct { BaseService - config cfg.Config + config *viper.Viper proxyAppConn proxy.AppConnConsensus blockStore types.BlockStore mempool types.Mempool @@ -255,7 +256,7 @@ type ConsensusState struct { done chan struct{} } -func NewConsensusState(config cfg.Config, state *sm.State, proxyAppConn proxy.AppConnConsensus, blockStore types.BlockStore, mempool types.Mempool) *ConsensusState { +func NewConsensusState(config *viper.Viper, state *sm.State, proxyAppConn proxy.AppConnConsensus, blockStore types.BlockStore, mempool types.Mempool) *ConsensusState { cs := &ConsensusState{ config: config, proxyAppConn: proxyAppConn, diff --git a/glide.lock b/glide.lock index 954064e5c..7b8eb278b 100644 --- a/glide.lock +++ b/glide.lock @@ -41,8 +41,10 @@ imports: version: d8ed2627bdf02c080bf22230dbb337003b7aba2d subpackages: - difflib +- name: github.com/spf13/viper + version: 84f94806c67f59dd7ae87bc5351f7a9c94a4558d - name: github.com/spf13/cobra - version: fcd0c5a1df88f5d6784cb4feead962c3f3d0b66c + version: 5deb57bbca49eb370538fc295ba4b2988f9f5e09 - name: github.com/spf13/pflag version: 9ff6c6923cfffbcd502984b8e0c80539a94968b7 - name: github.com/stretchr/testify diff --git a/glide.yaml b/glide.yaml index a5570d038..e4c2e4138 100644 --- a/glide.yaml +++ b/glide.yaml @@ -39,6 +39,17 @@ import: - flowrate - logger - merkle +- package: github.com/gogo/protobuf + version: ^0.3 + subpackages: + - proto +- package: github.com/gorilla/websocket + version: ^1.1.0 +- package: github.com/spf13/cobra +- package: github.com/spf13/viper +- package: github.com/spf13/pflag +- package: github.com/pkg/errors + version: ^0.8.0 - package: golang.org/x/crypto subpackages: - nacl/box diff --git a/mempool/mempool.go b/mempool/mempool.go index eedf6fb9c..086a99e32 100644 --- a/mempool/mempool.go +++ b/mempool/mempool.go @@ -7,13 +7,15 @@ import ( "sync/atomic" "time" + "github.com/spf13/viper" + abci "github.com/tendermint/abci/types" - auto "github.com/tendermint/tmlibs/autofile" - "github.com/tendermint/tmlibs/clist" - . "github.com/tendermint/tmlibs/common" cfg "github.com/tendermint/go-config" "github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/types" + auto "github.com/tendermint/tmlibs/autofile" + "github.com/tendermint/tmlibs/clist" + . "github.com/tendermint/tmlibs/common" ) /* @@ -47,7 +49,7 @@ TODO: Better handle abci client errors. (make it automatically handle connection const cacheSize = 100000 type Mempool struct { - config cfg.Config + config *viper.Viper proxyMtx sync.Mutex proxyAppConn proxy.AppConnMempool @@ -66,7 +68,7 @@ type Mempool struct { wal *auto.AutoFile } -func NewMempool(config cfg.Config, proxyAppConn proxy.AppConnMempool) *Mempool { +func NewMempool(config *viper.Viper, proxyAppConn proxy.AppConnMempool) *Mempool { mempool := &Mempool{ config: config, proxyAppConn: proxyAppConn, diff --git a/mempool/reactor.go b/mempool/reactor.go index 4d1638888..d30fd1151 100644 --- a/mempool/reactor.go +++ b/mempool/reactor.go @@ -6,12 +6,14 @@ import ( "reflect" "time" + "github.com/spf13/viper" + abci "github.com/tendermint/abci/types" - "github.com/tendermint/tmlibs/clist" cfg "github.com/tendermint/go-config" - "github.com/tendermint/tendermint/p2p" "github.com/tendermint/go-wire" + "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/types" + "github.com/tendermint/tmlibs/clist" ) const ( @@ -24,12 +26,12 @@ const ( // MempoolReactor handles mempool tx broadcasting amongst peers. type MempoolReactor struct { p2p.BaseReactor - config cfg.Config + config *viper.Viper Mempool *Mempool evsw types.EventSwitch } -func NewMempoolReactor(config cfg.Config, mempool *Mempool) *MempoolReactor { +func NewMempoolReactor(config *viper.Viper, mempool *Mempool) *MempoolReactor { memR := &MempoolReactor{ config: config, Mempool: mempool, diff --git a/node/node.go b/node/node.go index f24c1c4f2..17fb98bad 100644 --- a/node/node.go +++ b/node/node.go @@ -7,19 +7,19 @@ import ( "net/http" "strings" + "github.com/spf13/viper" + abci "github.com/tendermint/abci/types" - cmn "github.com/tendermint/tmlibs/common" cfg "github.com/tendermint/go-config" crypto "github.com/tendermint/go-crypto" - dbm "github.com/tendermint/tmlibs/db" - p2p "github.com/tendermint/tendermint/p2p" - rpc "github.com/tendermint/tendermint/rpc" - rpcserver "github.com/tendermint/tendermint/rpc/server" wire "github.com/tendermint/go-wire" bc "github.com/tendermint/tendermint/blockchain" "github.com/tendermint/tendermint/consensus" mempl "github.com/tendermint/tendermint/mempool" + p2p "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/proxy" + rpc "github.com/tendermint/tendermint/rpc" + rpcserver "github.com/tendermint/tendermint/rpc/server" rpccore "github.com/tendermint/tendermint/rpc/tendermint/core" grpccore "github.com/tendermint/tendermint/rpc/tendermint/grpc" sm "github.com/tendermint/tendermint/state" @@ -28,6 +28,8 @@ import ( "github.com/tendermint/tendermint/state/txindex/null" "github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/version" + cmn "github.com/tendermint/tmlibs/common" + dbm "github.com/tendermint/tmlibs/db" _ "net/http/pprof" ) @@ -36,7 +38,7 @@ type Node struct { cmn.BaseService // config - config cfg.Config // user config + config *viper.Viper // user config genesisDoc *types.GenesisDoc // initial validator set privValidator *types.PrivValidator // local node's validator key @@ -57,14 +59,14 @@ type Node struct { txIndexer txindex.TxIndexer } -func NewNodeDefault(config cfg.Config) *Node { +func NewNodeDefault(config *viper.Viper) *Node { // Get PrivValidator privValidatorFile := config.GetString("priv_validator_file") privValidator := types.LoadOrGenPrivValidator(privValidatorFile) return NewNode(config, privValidator, proxy.DefaultClientCreator(config)) } -func NewNode(config cfg.Config, privValidator *types.PrivValidator, clientCreator proxy.ClientCreator) *Node { +func NewNode(config *viper.Viper, privValidator *types.PrivValidator, clientCreator proxy.ClientCreator) *Node { // Get BlockStore blockStoreDB := dbm.NewDB("blockstore", config.GetString("db_backend"), config.GetString("db_dir")) @@ -134,7 +136,11 @@ func NewNode(config cfg.Config, privValidator *types.PrivValidator, clientCreato consensusReactor := consensus.NewConsensusReactor(consensusState, fastSync) // Make p2p network switch - sw := p2p.NewSwitch(config.GetConfig("p2p")) + p2pConfig := viper.New() + if config.IsSet("p2p") { //TODO verify this necessary, where is this ever set? + p2pConfig = config.Get("p2p").(*viper.Viper) + } + sw := p2p.NewSwitch(p2pConfig) sw.AddReactor("MEMPOOL", mempoolReactor) sw.AddReactor("BLOCKCHAIN", bcReactor) sw.AddReactor("CONSENSUS", consensusReactor) diff --git a/proxy/client.go b/proxy/client.go index ea9051989..4c50f38b3 100644 --- a/proxy/client.go +++ b/proxy/client.go @@ -4,10 +4,11 @@ import ( "fmt" "sync" + "github.com/spf13/viper" + abcicli "github.com/tendermint/abci/client" "github.com/tendermint/abci/example/dummy" "github.com/tendermint/abci/types" - cfg "github.com/tendermint/go-config" ) // NewABCIClient returns newly connected client @@ -63,7 +64,7 @@ func (r *remoteClientCreator) NewABCIClient() (abcicli.Client, error) { //----------------------------------------------------------------- // default -func DefaultClientCreator(config cfg.Config) ClientCreator { +func DefaultClientCreator(config *viper.Viper) ClientCreator { addr := config.GetString("proxy_app") transport := config.GetString("abci") diff --git a/proxy/multi_app_conn.go b/proxy/multi_app_conn.go index b70a0baf0..bb846c7fa 100644 --- a/proxy/multi_app_conn.go +++ b/proxy/multi_app_conn.go @@ -1,8 +1,9 @@ package proxy import ( - cmn "github.com/tendermint/tmlibs/common" + "github.com/spf13/viper" cfg "github.com/tendermint/go-config" + cmn "github.com/tendermint/tmlibs/common" ) //----------------------------- @@ -16,7 +17,7 @@ type AppConns interface { Query() AppConnQuery } -func NewAppConns(config cfg.Config, clientCreator ClientCreator, handshaker Handshaker) AppConns { +func NewAppConns(config *viper.Viper, clientCreator ClientCreator, handshaker Handshaker) AppConns { return NewMultiAppConn(config, clientCreator, handshaker) } @@ -34,7 +35,7 @@ type Handshaker interface { type multiAppConn struct { cmn.BaseService - config cfg.Config + config *viper.Viper handshaker Handshaker @@ -46,7 +47,7 @@ type multiAppConn struct { } // Make all necessary abci connections to the application -func NewMultiAppConn(config cfg.Config, clientCreator ClientCreator, handshaker Handshaker) *multiAppConn { +func NewMultiAppConn(config *viper.Viper, clientCreator ClientCreator, handshaker Handshaker) *multiAppConn { multiAppConn := &multiAppConn{ config: config, handshaker: handshaker, diff --git a/rpc/tendermint/core/pipe.go b/rpc/tendermint/core/pipe.go index d4a1d127e..6f4740902 100644 --- a/rpc/tendermint/core/pipe.go +++ b/rpc/tendermint/core/pipe.go @@ -1,11 +1,12 @@ package core import ( + "github.com/spf13/viper" cfg "github.com/tendermint/go-config" crypto "github.com/tendermint/go-crypto" - p2p "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/consensus" + p2p "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/state/txindex" "github.com/tendermint/tendermint/types" @@ -34,7 +35,7 @@ var ( // external, thread safe interfaces eventSwitch types.EventSwitch proxyAppQuery proxy.AppConnQuery - config cfg.Config + config *viper.Viper // interfaces defined in types and above blockStore types.BlockStore @@ -49,7 +50,7 @@ var ( txIndexer txindex.TxIndexer ) -func SetConfig(c cfg.Config) { +func SetConfig(c *viper.Viper) { config = c } diff --git a/rpc/tendermint/test/helpers.go b/rpc/tendermint/test/helpers.go index e5a2fb4e2..8477ef570 100644 --- a/rpc/tendermint/test/helpers.go +++ b/rpc/tendermint/test/helpers.go @@ -9,23 +9,24 @@ import ( "testing" "time" + "github.com/spf13/viper" "github.com/stretchr/testify/require" - logger "github.com/tendermint/tmlibs/logger" wire "github.com/tendermint/go-wire" + logger "github.com/tendermint/tmlibs/logger" abci "github.com/tendermint/abci/types" cfg "github.com/tendermint/go-config" - client "github.com/tendermint/tendermint/rpc/client" "github.com/tendermint/tendermint/config/tendermint_test" nm "github.com/tendermint/tendermint/node" "github.com/tendermint/tendermint/proxy" + client "github.com/tendermint/tendermint/rpc/client" ctypes "github.com/tendermint/tendermint/rpc/tendermint/core/types" core_grpc "github.com/tendermint/tendermint/rpc/tendermint/grpc" "github.com/tendermint/tendermint/types" ) var ( - config cfg.Config + config *viper.Viper ) const tmLogLevel = "error" @@ -56,7 +57,7 @@ func makeAddrs() (string, string, string) { } // GetConfig returns a config for the test cases as a singleton -func GetConfig() cfg.Config { +func GetConfig() *viper.Viper { if config == nil { pathname := makePathname() config = tendermint_test.ResetConfig(pathname) diff --git a/state/state.go b/state/state.go index ccdf508ac..3055fb7b7 100644 --- a/state/state.go +++ b/state/state.go @@ -6,10 +6,12 @@ import ( "sync" "time" + "github.com/spf13/viper" abci "github.com/tendermint/abci/types" - . "github.com/tendermint/tmlibs/common" cfg "github.com/tendermint/go-config" + . "github.com/tendermint/tmlibs/common" dbm "github.com/tendermint/tmlibs/db" + "github.com/tendermint/go-wire" "github.com/tendermint/tendermint/state/txindex" "github.com/tendermint/tendermint/state/txindex/null" @@ -168,7 +170,7 @@ func (s *State) GetValidators() (*types.ValidatorSet, *types.ValidatorSet) { // Load the most recent state from "state" db, // or create a new one (and save) from genesis. -func GetState(config cfg.Config, stateDB dbm.DB) *State { +func GetState(config *viper.Viper, stateDB dbm.DB) *State { state := LoadState(stateDB) if state == nil { state = MakeGenesisStateFromFile(stateDB, config.GetString("genesis_file"))