From 47852122d0db9841216554e1869d952e39292f38 Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Tue, 28 Mar 2017 02:00:42 -0400 Subject: [PATCH 01/10] changed reset commands --- cmd/tendermint/commands/reset_priv_validator.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/tendermint/commands/reset_priv_validator.go b/cmd/tendermint/commands/reset_priv_validator.go index b1fb334bc..49d277411 100644 --- a/cmd/tendermint/commands/reset_priv_validator.go +++ b/cmd/tendermint/commands/reset_priv_validator.go @@ -43,20 +43,21 @@ func resetPrivValidator(cmd *cobra.Command, args []string) { func ResetAll(c cfg.Config, l log15.Logger) { ResetPrivValidator(c, l) os.RemoveAll(c.GetString("db_dir")) + l.Notice("Removed all data", "dir", dataDir) } func ResetPrivValidator(c cfg.Config, l log15.Logger) { // Get PrivValidator var privValidator *types.PrivValidator - privValidatorFile := config.GetString("priv_validator_file") + privValidatorFile := c.GetString("priv_validator_file") if _, err := os.Stat(privValidatorFile); err == nil { privValidator = types.LoadPrivValidator(privValidatorFile) privValidator.Reset() - log.Notice("Reset PrivValidator", "file", privValidatorFile) + l.Notice("Reset PrivValidator", "file", privValidatorFile) } else { privValidator = types.GenPrivValidator() privValidator.SetFile(privValidatorFile) privValidator.Save() - log.Notice("Generated PrivValidator", "file", privValidatorFile) + l.Notice("Generated PrivValidator", "file", privValidatorFile) } } From cefb2bede0907cdb492eda165c1eed10c475d1ea Mon Sep 17 00:00:00 2001 From: Rigel Rozanski Date: Sat, 8 Apr 2017 22:04:06 -0400 Subject: [PATCH 02/10] adding viper int int --- blockchain/reactor.go | 10 +-- cmd/tendermint/commands/root.go | 3 +- config/tendermint/config.go | 104 +++++++++++++++-------------- config/tendermint_test/config.go | 110 +++++++++++++++++-------------- consensus/byzantine_test.go | 8 ++- consensus/common_test.go | 14 ++-- consensus/replay.go | 10 +-- consensus/replay_file.go | 10 +-- consensus/replay_test.go | 15 +++-- consensus/state.go | 9 +-- glide.lock | 4 +- glide.yaml | 11 ++++ mempool/mempool.go | 12 ++-- mempool/reactor.go | 10 +-- node/node.go | 24 ++++--- proxy/client.go | 5 +- proxy/multi_app_conn.go | 9 +-- rpc/tendermint/core/pipe.go | 7 +- rpc/tendermint/test/helpers.go | 9 +-- state/state.go | 6 +- 20 files changed, 223 insertions(+), 167 deletions(-) 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")) From 270b68a893474cd22c820cc6eb3fa3f26b2b2c20 Mon Sep 17 00:00:00 2001 From: Rigel Rozanski Date: Sun, 9 Apr 2017 23:07:15 -0400 Subject: [PATCH 03/10] glide lock updates --- .../commands/reset_priv_validator.go | 7 +-- glide.lock | 43 ++++++++++++++++--- rpc/tendermint/test/client_test.go | 1 + 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/cmd/tendermint/commands/reset_priv_validator.go b/cmd/tendermint/commands/reset_priv_validator.go index 49d277411..c880e8313 100644 --- a/cmd/tendermint/commands/reset_priv_validator.go +++ b/cmd/tendermint/commands/reset_priv_validator.go @@ -4,8 +4,8 @@ import ( "os" "github.com/spf13/cobra" + "github.com/spf13/viper" - cfg "github.com/tendermint/go-config" "github.com/tendermint/log15" "github.com/tendermint/tendermint/types" ) @@ -40,13 +40,14 @@ func resetPrivValidator(cmd *cobra.Command, args []string) { } // Exported so other CLI tools can use it -func ResetAll(c cfg.Config, l log15.Logger) { +func ResetAll(c *viper.Viper, l log15.Logger) { ResetPrivValidator(c, l) os.RemoveAll(c.GetString("db_dir")) l.Notice("Removed all data", "dir", dataDir) } -func ResetPrivValidator(c cfg.Config, l log15.Logger) { +func ResetPrivValidator(c *viper.Viper, l log15.Logger) { + // Get PrivValidator var privValidator *types.PrivValidator privValidatorFile := c.GetString("priv_validator_file") diff --git a/glide.lock b/glide.lock index 7b8eb278b..bc4778927 100644 --- a/glide.lock +++ b/glide.lock @@ -13,6 +13,8 @@ imports: - spew - name: github.com/ebuchman/fail-test version: 95f809107225be108efcf10a3509e4ea6ceef3c4 +- name: github.com/fsnotify/fsnotify + version: 4da3e2cfbabc9f751898f250b49f2439785783a1 - name: github.com/go-stack/stack version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82 - name: github.com/gogo/protobuf @@ -27,26 +29,53 @@ imports: version: d9eb7a3d35ec988b8585d4a0068e462c27d28380 - name: github.com/gorilla/websocket version: 3ab3a8b8831546bd18fd182c20687ca853b2bb13 +- name: github.com/hashicorp/hcl + version: 630949a3c5fa3c613328e1b8256052cbc2327c9b + subpackages: + - hcl/ast + - hcl/parser + - hcl/scanner + - hcl/strconv + - hcl/token + - json/parser + - json/scanner + - json/token - name: github.com/inconshreveable/mousetrap version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 - name: github.com/jmhodges/levigo version: c42d9e0ca023e2198120196f842701bb4c55d7b9 +- name: github.com/magiconair/properties + version: 51463bfca2576e06c62a8504b5c0f06d61312647 - name: github.com/mattn/go-colorable version: d228849504861217f796da67fae4f6e347643f15 - name: github.com/mattn/go-isatty version: 30a891c33c7cde7b02a981314b4228ec99380cca +- name: github.com/mitchellh/mapstructure + version: 53818660ed4955e899c0bcafa97299a388bd7c8e +- name: github.com/pelletier/go-buffruneio + version: c37440a7cf42ac63b919c752ca73a85067e05992 +- name: github.com/pelletier/go-toml + version: fe206efb84b2bc8e8cfafe6b4c1826622be969e3 - name: github.com/pkg/errors version: 645ef00459ed84a119197bfb8d8205042c6df63d - name: github.com/pmezard/go-difflib version: d8ed2627bdf02c080bf22230dbb337003b7aba2d subpackages: - difflib -- name: github.com/spf13/viper - version: 84f94806c67f59dd7ae87bc5351f7a9c94a4558d +- name: github.com/spf13/afero + version: 9be650865eab0c12963d8753212f4f9c66cdcf12 + subpackages: + - mem +- name: github.com/spf13/cast + version: ce135a4ebeee6cfe9a26c93ee0d37825f26113c7 - name: github.com/spf13/cobra - version: 5deb57bbca49eb370538fc295ba4b2988f9f5e09 + version: fcd0c5a1df88f5d6784cb4feead962c3f3d0b66c +- name: github.com/spf13/jwalterweatherman + version: fa7ca7e836cf3a8bb4ebf799f472c12d7e903d66 - name: github.com/spf13/pflag version: 9ff6c6923cfffbcd502984b8e0c80539a94968b7 +- name: github.com/spf13/viper + version: 84f94806c67f59dd7ae87bc5351f7a9c94a4558d - name: github.com/stretchr/testify version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 subpackages: @@ -81,9 +110,9 @@ imports: - edwards25519 - extra25519 - name: github.com/tendermint/go-common - version: f9e3db037330c8a8d61d3966de8473eaf01154fa -- name: github.com/tendermint/go-config - version: 620dcbbd7d587cf3599dedbf329b64311b0c307a + version: 6af2364fa91ef2f3afc8ba0db33b66d9d3ae006c + subpackages: + - test - name: github.com/tendermint/go-crypto version: 9b95da8fa4187f6799558d89b271dc8ab6485615 - name: github.com/tendermint/go-wire @@ -151,4 +180,6 @@ imports: - stats - tap - transport +- name: gopkg.in/yaml.v2 + version: cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b testImports: [] diff --git a/rpc/tendermint/test/client_test.go b/rpc/tendermint/test/client_test.go index 1164bdd79..2fc8a2d9b 100644 --- a/rpc/tendermint/test/client_test.go +++ b/rpc/tendermint/test/client_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + abci "github.com/tendermint/abci/types" rpc "github.com/tendermint/tendermint/rpc/client" "github.com/tendermint/tendermint/rpc/tendermint/core" From 6e662337ffadd85cb635139b95e5cf20b822cf74 Mon Sep 17 00:00:00 2001 From: Rigel Rozanski Date: Mon, 10 Apr 2017 12:59:43 -0400 Subject: [PATCH 04/10] dont export resetPrivValidator --- cmd/tendermint/commands/reset_priv_validator.go | 9 +++++---- glide.lock | 5 +++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/tendermint/commands/reset_priv_validator.go b/cmd/tendermint/commands/reset_priv_validator.go index c880e8313..a611935bb 100644 --- a/cmd/tendermint/commands/reset_priv_validator.go +++ b/cmd/tendermint/commands/reset_priv_validator.go @@ -36,17 +36,18 @@ func resetAll(cmd *cobra.Command, args []string) { // XXX: this is totally unsafe. // it's only suitable for testnets. func resetPrivValidator(cmd *cobra.Command, args []string) { - ResetPrivValidator(config, log) + resetPrivValidatorLocal(config, log) } // Exported so other CLI tools can use it func ResetAll(c *viper.Viper, l log15.Logger) { - ResetPrivValidator(c, l) - os.RemoveAll(c.GetString("db_dir")) + resetPrivValidatorLocal(c, l) + dataDir := c.GetString("db_dir") + os.RemoveAll(dataDir) l.Notice("Removed all data", "dir", dataDir) } -func ResetPrivValidator(c *viper.Viper, l log15.Logger) { +func resetPrivValidatorLocal(c *viper.Viper, l log15.Logger) { // Get PrivValidator var privValidator *types.PrivValidator diff --git a/glide.lock b/glide.lock index bc4778927..70da9fac1 100644 --- a/glide.lock +++ b/glide.lock @@ -167,6 +167,11 @@ imports: version: d75a52659825e75fff6158388dddc6a5b04f9ba5 subpackages: - unix +- name: golang.org/x/text + version: f4b4367115ec2de254587813edaa901bc1c723a8 + subpackages: + - transform + - unicode/norm - name: google.golang.org/grpc version: cbcceb2942a489498cf22b2f918536e819d33f0a subpackages: From 7448753257e394d02e2886bc45b34a9c281b0e4a Mon Sep 17 00:00:00 2001 From: Rigel Rozanski Date: Wed, 12 Apr 2017 21:23:58 -0400 Subject: [PATCH 05/10] fixing tests --- config/tendermint/config.go | 2 +- config/tendermint_test/config.go | 2 +- rpc/tendermint/test/client_test.go | 102 +++++++++++++++-------------- rpc/tendermint/test/helpers.go | 4 +- 4 files changed, 55 insertions(+), 55 deletions(-) diff --git a/config/tendermint/config.go b/config/tendermint/config.go index 2e8cbb538..bb2846f7f 100644 --- a/config/tendermint/config.go +++ b/config/tendermint/config.go @@ -52,7 +52,7 @@ func GetConfig(rootDir string) *viper.Viper { if err != nil { Exit(Fmt("Could not read config: %v", err)) } - config.WatchConfig() + //config.WatchConfig() // Set defaults or panic if config.IsSet("chain_id") { diff --git a/config/tendermint_test/config.go b/config/tendermint_test/config.go index 846d28c64..5ff8e78f6 100644 --- a/config/tendermint_test/config.go +++ b/config/tendermint_test/config.go @@ -68,7 +68,7 @@ func ResetConfig(localPath string) *viper.Viper { if err != nil { Exit(Fmt("Could not read config: %v", err)) } - config.WatchConfig() + //config.WatchConfig() // Set defaults or panic if config.IsSet("chain_id") { diff --git a/rpc/tendermint/test/client_test.go b/rpc/tendermint/test/client_test.go index 2fc8a2d9b..d6d616f0c 100644 --- a/rpc/tendermint/test/client_test.go +++ b/rpc/tendermint/test/client_test.go @@ -67,8 +67,10 @@ func TestJSONBroadcastTxSync(t *testing.T) { } func testBroadcastTxSync(t *testing.T, client rpc.HTTPClient) { - config.Set("block_size", 0) - defer config.Set("block_size", -1) + // config.Set("block_size", 0) + // defer config.Set("block_size", -1) + mem := node.MempoolReactor().Mempool + initMemSize := mem.Size() tmResult := new(ctypes.TMResult) tx := randBytes(t) _, err := client.Call("broadcast_tx_sync", map[string]interface{}{"tx": tx}, tmResult) @@ -76,8 +78,7 @@ func testBroadcastTxSync(t *testing.T, client rpc.HTTPClient) { res := (*tmResult).(*ctypes.ResultBroadcastTx) require.Equal(t, abci.CodeType_OK, res.Code) - mem := node.MempoolReactor().Mempool - require.Equal(t, 1, mem.Size()) + require.Equal(t, initMemSize+1, mem.Size()) txs := mem.Reap(1) require.EqualValues(t, tx, txs[0]) mem.Flush() @@ -358,51 +359,52 @@ func TestWSDoubleFire(t *testing.T) { }*/ //-------------------------------------------------------------------------------- +//TODO needs to be refactored so we don't use a mutable config but rather update specific values we're interested in // unsafe_set_config -var stringVal = "my string" -var intVal = 987654321 -var boolVal = true - -// don't change these -var testCasesUnsafeSetConfig = [][]string{ - []string{"string", "key1", stringVal}, - []string{"int", "key2", fmt.Sprintf("%v", intVal)}, - []string{"bool", "key3", fmt.Sprintf("%v", boolVal)}, -} - -func TestURIUnsafeSetConfig(t *testing.T) { - for _, testCase := range testCasesUnsafeSetConfig { - tmResult := new(ctypes.TMResult) - _, err := GetURIClient().Call("unsafe_set_config", map[string]interface{}{ - "type": testCase[0], - "key": testCase[1], - "value": testCase[2], - }, tmResult) - require.Nil(t, err) - } - testUnsafeSetConfig(t) -} - -func TestJSONUnsafeSetConfig(t *testing.T) { - for _, testCase := range testCasesUnsafeSetConfig { - tmResult := new(ctypes.TMResult) - _, err := GetJSONClient().Call("unsafe_set_config", - map[string]interface{}{"type": testCase[0], "key": testCase[1], "value": testCase[2]}, - tmResult) - require.Nil(t, err) - } - testUnsafeSetConfig(t) -} - -func testUnsafeSetConfig(t *testing.T) { - require := require.New(t) - s := config.GetString("key1") - require.Equal(stringVal, s) - - i := config.GetInt("key2") - require.Equal(intVal, i) - - b := config.GetBool("key3") - require.Equal(boolVal, b) -} +//var stringVal = "my string" +//var intVal = 987654321 +//var boolVal = true +// +//// don't change these +//var testCasesUnsafeSetConfig = [][]string{ +// []string{"string", "key1", stringVal}, +// []string{"int", "key2", fmt.Sprintf("%v", intVal)}, +// []string{"bool", "key3", fmt.Sprintf("%v", boolVal)}, +//} +// +//func TestURIUnsafeSetConfig(t *testing.T) { +// for _, testCase := range testCasesUnsafeSetConfig { +// tmResult := new(ctypes.TMResult) +// _, err := GetURIClient().Call("unsafe_set_config", map[string]interface{}{ +// "type": testCase[0], +// "key": testCase[1], +// "value": testCase[2], +// }, tmResult) +// require.Nil(t, err) +// } +// testUnsafeSetConfig(t) +//} +// +//func TestJSONUnsafeSetConfig(t *testing.T) { +// for _, testCase := range testCasesUnsafeSetConfig { +// tmResult := new(ctypes.TMResult) +// _, err := GetJSONClient().Call("unsafe_set_config", +// map[string]interface{}{"type": testCase[0], "key": testCase[1], "value": testCase[2]}, +// tmResult) +// require.Nil(t, err) +// } +// testUnsafeSetConfig(t) +//} +// +//func testUnsafeSetConfig(t *testing.T) { +// require := require.New(t) +// s := config.GetString("key1") +// require.Equal(stringVal, s) +// +// i := config.GetInt("key2") +// require.Equal(intVal, i) +// +// b := config.GetBool("key3") +// require.Equal(boolVal, b) +//} diff --git a/rpc/tendermint/test/helpers.go b/rpc/tendermint/test/helpers.go index 8477ef570..f89287670 100644 --- a/rpc/tendermint/test/helpers.go +++ b/rpc/tendermint/test/helpers.go @@ -25,9 +25,7 @@ import ( "github.com/tendermint/tendermint/types" ) -var ( - config *viper.Viper -) +var config *viper.Viper const tmLogLevel = "error" From 7bb638e3b8e1e4e8ac3442dd78dffdc88428cdc1 Mon Sep 17 00:00:00 2001 From: Rigel Rozanski Date: Thu, 13 Apr 2017 16:31:29 -0400 Subject: [PATCH 06/10] fix test_integrations error --- config/tendermint/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/tendermint/config.go b/config/tendermint/config.go index bb2846f7f..c3424d9a4 100644 --- a/config/tendermint/config.go +++ b/config/tendermint/config.go @@ -48,9 +48,9 @@ func GetConfig(rootDir string) *viper.Viper { config.SetConfigName("config") config.SetConfigType("toml") config.AddConfigPath(rootDir) - err := viper.ReadInConfig() + err := config.ReadInConfig() if err != nil { - Exit(Fmt("Could not read config: %v", err)) + Exit(Fmt("Could not read config from directory %v: %v", rootDir, err)) } //config.WatchConfig() From 5d0c2a1414c976ed29163e50569cfdbcefc4b0db Mon Sep 17 00:00:00 2001 From: Rigel Rozanski Date: Sat, 15 Apr 2017 16:40:52 -0400 Subject: [PATCH 07/10] commands: Run -> RunE --- cmd/tendermint/commands/probe_upnp.go | 8 ++++---- cmd/tendermint/commands/run_node.go | 17 ++++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/cmd/tendermint/commands/probe_upnp.go b/cmd/tendermint/commands/probe_upnp.go index eb55d6690..330dcf17d 100644 --- a/cmd/tendermint/commands/probe_upnp.go +++ b/cmd/tendermint/commands/probe_upnp.go @@ -12,14 +12,14 @@ import ( var probeUpnpCmd = &cobra.Command{ Use: "probe_upnp", Short: "Test UPnP functionality", - Run: probeUpnp, + RunE: probeUpnp, } func init() { RootCmd.AddCommand(probeUpnpCmd) } -func probeUpnp(cmd *cobra.Command, args []string) { +func probeUpnp(cmd *cobra.Command, args []string) error { capabilities, err := upnp.Probe() if err != nil { @@ -28,9 +28,9 @@ func probeUpnp(cmd *cobra.Command, args []string) { fmt.Println("Probe success!") jsonBytes, err := json.Marshal(capabilities) if err != nil { - panic(err) + return err } fmt.Println(string(jsonBytes)) } - + return nil } diff --git a/cmd/tendermint/commands/run_node.go b/cmd/tendermint/commands/run_node.go index 5e0fef32c..972ed5215 100644 --- a/cmd/tendermint/commands/run_node.go +++ b/cmd/tendermint/commands/run_node.go @@ -1,6 +1,7 @@ package commands import ( + "fmt" "io/ioutil" "time" @@ -13,9 +14,9 @@ import ( var runNodeCmd = &cobra.Command{ Use: "node", - Short: "Run the tendermint node", + Short: "RunE the tendermint node", PreRun: setConfigFlags, - Run: runNode, + RunE: runNode, } //flags @@ -82,7 +83,7 @@ func setConfigFlags(cmd *cobra.Command, args []string) { // should import github.com/tendermint/tendermint/node and implement // their own run_node to call node.NewNode (instead of node.NewNodeDefault) // with their custom priv validator and/or custom proxy.ClientCreator -func runNode(cmd *cobra.Command, args []string) { +func runNode(cmd *cobra.Command, args []string) error { // Wait until the genesis doc becomes available // This is for Mintnet compatibility. @@ -98,14 +99,14 @@ func runNode(cmd *cobra.Command, args []string) { } jsonBlob, err := ioutil.ReadFile(genDocFile) if err != nil { - Exit(Fmt("Couldn't read GenesisDoc file: %v", err)) + return fmt.Errorf("Couldn't read GenesisDoc file: %v", err) } genDoc, err := types.GenesisDocFromJSON(jsonBlob) if err != nil { - Exit(Fmt("Error reading GenesisDoc: %v", err)) + return fmt.Errorf("Error reading GenesisDoc: %v", err) } if genDoc.ChainID == "" { - Exit(Fmt("Genesis doc %v must include non-empty chain_id", genDocFile)) + return fmt.Errorf("Genesis doc %v must include non-empty chain_id", genDocFile) } config.Set("chain_id", genDoc.ChainID) } @@ -114,11 +115,13 @@ func runNode(cmd *cobra.Command, args []string) { // Create & start node n := node.NewNodeDefault(config) if _, err := n.Start(); err != nil { - Exit(Fmt("Failed to start node: %v", err)) + return fmt.Errorf("Failed to start node: %v", err) } else { log.Notice("Started node", "nodeInfo", n.Switch().NodeInfo()) } // Trap signal, run forever. n.RunForever() + + return nil } From 72c4be35e8bf2172dffb7eedd871903ffd1a8f89 Mon Sep 17 00:00:00 2001 From: rigel rozanski Date: Tue, 18 Apr 2017 03:19:15 -0400 Subject: [PATCH 08/10] tiny fix --- cmd/tendermint/commands/run_node.go | 2 +- rpc/tendermint/test/client_test.go | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/cmd/tendermint/commands/run_node.go b/cmd/tendermint/commands/run_node.go index 972ed5215..a4e4e69dd 100644 --- a/cmd/tendermint/commands/run_node.go +++ b/cmd/tendermint/commands/run_node.go @@ -14,7 +14,7 @@ import ( var runNodeCmd = &cobra.Command{ Use: "node", - Short: "RunE the tendermint node", + Short: "Run the tendermint node", PreRun: setConfigFlags, RunE: runNode, } diff --git a/rpc/tendermint/test/client_test.go b/rpc/tendermint/test/client_test.go index d6d616f0c..11ee61a56 100644 --- a/rpc/tendermint/test/client_test.go +++ b/rpc/tendermint/test/client_test.go @@ -67,8 +67,6 @@ func TestJSONBroadcastTxSync(t *testing.T) { } func testBroadcastTxSync(t *testing.T, client rpc.HTTPClient) { - // config.Set("block_size", 0) - // defer config.Set("block_size", -1) mem := node.MempoolReactor().Mempool initMemSize := mem.Size() tmResult := new(ctypes.TMResult) From fcf78a5da7cfce36d34156c464031f69f6af3f2c Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Tue, 25 Apr 2017 14:50:20 -0400 Subject: [PATCH 09/10] cleanup go-config/viper and some unnamed imports --- blockchain/reactor.go | 1 - cmd/tendermint/commands/root.go | 1 - cmd/tendermint/commands/run_node.go | 8 +-- config/tendermint/config.go | 18 +++---- config/tendermint_test/config.go | 2 - consensus/byzantine_test.go | 2 - consensus/common_test.go | 1 - consensus/replay.go | 19 ++++--- consensus/replay_file.go | 15 +++--- consensus/replay_test.go | 1 - consensus/state.go | 83 ++++++++++++++--------------- glide.lock | 18 +++---- glide.yaml | 14 +---- mempool/mempool.go | 1 - mempool/reactor.go | 1 - node/node.go | 1 - p2p/config.go | 4 +- p2p/switch.go | 11 ++-- p2p/switch_test.go | 9 ++-- proxy/app_conn_test.go | 22 ++++---- proxy/multi_app_conn.go | 1 - rpc/tendermint/core/pipe.go | 1 - rpc/tendermint/test/helpers.go | 1 - state/errors.go | 12 ++--- state/execution.go | 16 +++--- state/state.go | 17 +++--- test/test_libs.sh | 4 +- 27 files changed, 124 insertions(+), 160 deletions(-) diff --git a/blockchain/reactor.go b/blockchain/reactor.go index f45975e00..1ea5650ed 100644 --- a/blockchain/reactor.go +++ b/blockchain/reactor.go @@ -8,7 +8,6 @@ import ( "github.com/spf13/viper" - cfg "github.com/tendermint/go-config" "github.com/tendermint/go-wire" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/proxy" diff --git a/cmd/tendermint/commands/root.go b/cmd/tendermint/commands/root.go index 78d197289..de5b71bd1 100644 --- a/cmd/tendermint/commands/root.go +++ b/cmd/tendermint/commands/root.go @@ -2,7 +2,6 @@ package commands import ( "github.com/spf13/cobra" - "github.com/spf13/viper" tmcfg "github.com/tendermint/tendermint/config/tendermint" "github.com/tendermint/tmlibs/logger" diff --git a/cmd/tendermint/commands/run_node.go b/cmd/tendermint/commands/run_node.go index a4e4e69dd..b2b23af5c 100644 --- a/cmd/tendermint/commands/run_node.go +++ b/cmd/tendermint/commands/run_node.go @@ -7,9 +7,9 @@ import ( "github.com/spf13/cobra" - . "github.com/tendermint/tmlibs/common" "github.com/tendermint/tendermint/node" "github.com/tendermint/tendermint/types" + cmn "github.com/tendermint/tmlibs/common" ) var runNodeCmd = &cobra.Command{ @@ -90,11 +90,11 @@ func runNode(cmd *cobra.Command, args []string) error { // TODO: If Mintnet gets deprecated or genesis_file is // always available, remove. genDocFile := config.GetString("genesis_file") - if !FileExists(genDocFile) { - log.Notice(Fmt("Waiting for genesis file %v...", genDocFile)) + if !cmn.FileExists(genDocFile) { + log.Notice(cmn.Fmt("Waiting for genesis file %v...", genDocFile)) for { time.Sleep(time.Second) - if !FileExists(genDocFile) { + if !cmn.FileExists(genDocFile) { continue } jsonBlob, err := ioutil.ReadFile(genDocFile) diff --git a/config/tendermint/config.go b/config/tendermint/config.go index c3424d9a4..9011e0154 100644 --- a/config/tendermint/config.go +++ b/config/tendermint/config.go @@ -6,9 +6,7 @@ import ( "strings" "github.com/spf13/viper" - - cfg "github.com/tendermint/go-config" - . "github.com/tendermint/tmlibs/common" + cmn "github.com/tendermint/tmlibs/common" ) func getTMRoot(rootDir string) string { @@ -27,16 +25,16 @@ func getTMRoot(rootDir string) string { func initTMRoot(rootDir string) { rootDir = getTMRoot(rootDir) - EnsureDir(rootDir, 0700) - EnsureDir(rootDir+"/data", 0700) + cmn.EnsureDir(rootDir, 0700) + cmn.EnsureDir(rootDir+"/data", 0700) configFilePath := path.Join(rootDir, "config.toml") // Write default config file if missing. - if !FileExists(configFilePath) { + if !cmn.FileExists(configFilePath) { // Ask user for moniker // moniker := cfg.Prompt("Type hostname: ", "anonymous") - MustWriteFile(configFilePath, []byte(defaultConfig("anonymous")), 0644) + cmn.MustWriteFile(configFilePath, []byte(defaultConfig("anonymous")), 0644) } } @@ -50,16 +48,16 @@ func GetConfig(rootDir string) *viper.Viper { config.AddConfigPath(rootDir) err := config.ReadInConfig() if err != nil { - Exit(Fmt("Could not read config from directory %v: %v", rootDir, err)) + cmn.Exit(cmn.Fmt("Could not read config from directory %v: %v", rootDir, err)) } //config.WatchConfig() // Set defaults or panic if config.IsSet("chain_id") { - Exit("Cannot set 'chain_id' via config.toml") + cmn.Exit("Cannot set 'chain_id' via config.toml") } if config.IsSet("revision_file") { - Exit("Cannot set 'revision_file' via config.toml. It must match what's in the Makefile") + cmn.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. config.SetDefault("genesis_file", rootDir+"/genesis.json") diff --git a/config/tendermint_test/config.go b/config/tendermint_test/config.go index 5ff8e78f6..1a87d5261 100644 --- a/config/tendermint_test/config.go +++ b/config/tendermint_test/config.go @@ -10,7 +10,6 @@ import ( "github.com/spf13/viper" - cfg "github.com/tendermint/go-config" . "github.com/tendermint/tmlibs/common" "github.com/tendermint/tmlibs/logger" ) @@ -46,7 +45,6 @@ func initTMRoot(rootDir string) { // Write default config file if missing. if !FileExists(configFilePath) { // Ask user for moniker - // moniker := cfg.Prompt("Type hostname: ", "anonymous") MustWriteFile(configFilePath, []byte(defaultConfig("anonymous")), 0644) } if !FileExists(genesisFilePath) { diff --git a/consensus/byzantine_test.go b/consensus/byzantine_test.go index d4cda4046..b9edf4635 100644 --- a/consensus/byzantine_test.go +++ b/consensus/byzantine_test.go @@ -8,8 +8,6 @@ import ( "github.com/spf13/viper" "github.com/tendermint/tendermint/config/tendermint_test" - - cfg "github.com/tendermint/go-config" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/types" . "github.com/tendermint/tmlibs/common" diff --git a/consensus/common_test.go b/consensus/common_test.go index 7acb54ad7..469fc9c6b 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -15,7 +15,6 @@ import ( abcicli "github.com/tendermint/abci/client" abci "github.com/tendermint/abci/types" - cfg "github.com/tendermint/go-config" bc "github.com/tendermint/tendermint/blockchain" "github.com/tendermint/tendermint/config/tendermint_test" mempl "github.com/tendermint/tendermint/mempool" diff --git a/consensus/replay.go b/consensus/replay.go index acbe44098..5bc0c2611 100644 --- a/consensus/replay.go +++ b/consensus/replay.go @@ -13,10 +13,9 @@ import ( "github.com/spf13/viper" abci "github.com/tendermint/abci/types" - cfg "github.com/tendermint/go-config" "github.com/tendermint/go-wire" auto "github.com/tendermint/tmlibs/autofile" - . "github.com/tendermint/tmlibs/common" + cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/tendermint/proxy" sm "github.com/tendermint/tendermint/state" @@ -110,7 +109,7 @@ func (cs *ConsensusState) catchupReplay(csHeight int) error { gr.Close() } if found { - return errors.New(Fmt("WAL should not contain #ENDHEIGHT %d.", csHeight)) + return errors.New(cmn.Fmt("WAL should not contain #ENDHEIGHT %d.", csHeight)) } // Search for last height marker @@ -145,7 +144,7 @@ func (cs *ConsensusState) catchupReplay(csHeight int) error { } // TODO (0.10.0): uncomment - // return errors.New(Fmt("Cannot replay height %d. WAL does not contain #ENDHEIGHT for %d.", csHeight, csHeight-1)) + // return errors.New(cmn.Fmt("Cannot replay height %d. WAL does not contain #ENDHEIGHT for %d.", csHeight, csHeight-1)) } log.Notice("Catchup by replaying consensus messages", "height", csHeight) @@ -223,7 +222,7 @@ func (h *Handshaker) Handshake(proxyApp proxy.AppConns) error { // handshake is done via info request on the query conn res, err := proxyApp.Query().InfoSync() if err != nil { - return errors.New(Fmt("Error calling Info: %v", err)) + return errors.New(cmn.Fmt("Error calling Info: %v", err)) } blockHeight := int(res.LastBlockHeight) // XXX: beware overflow @@ -240,7 +239,7 @@ func (h *Handshaker) Handshake(proxyApp proxy.AppConns) error { return nil } else if err != nil { - return errors.New(Fmt("Error on replay: %v", err)) + return errors.New(cmn.Fmt("Error on replay: %v", err)) } log.Notice("Completed ABCI Handshake - Tendermint and App are synced", "appHeight", blockHeight, "appHash", appHash) @@ -268,11 +267,11 @@ func (h *Handshaker) ReplayBlocks(appHash []byte, appBlockHeight int, proxyApp p } else if storeBlockHeight < stateBlockHeight { // the state should never be ahead of the store (this is under tendermint's control) - PanicSanity(Fmt("StateBlockHeight (%d) > StoreBlockHeight (%d)", stateBlockHeight, storeBlockHeight)) + cmn.PanicSanity(cmn.Fmt("StateBlockHeight (%d) > StoreBlockHeight (%d)", stateBlockHeight, storeBlockHeight)) } else if storeBlockHeight > stateBlockHeight+1 { // store should be at most one ahead of the state (this is under tendermint's control) - PanicSanity(Fmt("StoreBlockHeight (%d) > StateBlockHeight + 1 (%d)", storeBlockHeight, stateBlockHeight+1)) + cmn.PanicSanity(cmn.Fmt("StoreBlockHeight (%d) > StateBlockHeight + 1 (%d)", storeBlockHeight, stateBlockHeight+1)) } // Now either store is equal to state, or one ahead. @@ -315,7 +314,7 @@ func (h *Handshaker) ReplayBlocks(appHash []byte, appBlockHeight int, proxyApp p } - PanicSanity("Should never happen") + cmn.PanicSanity("Should never happen") return nil, nil } @@ -370,7 +369,7 @@ func (h *Handshaker) replayBlock(height int, proxyApp proxy.AppConnConsensus) ([ func (h *Handshaker) checkAppHash(appHash []byte) error { if !bytes.Equal(h.state.AppHash, appHash) { - panic(errors.New(Fmt("Tendermint state.AppHash does not match AppHash after replay. Got %X, expected %X", appHash, h.state.AppHash)).Error()) + panic(errors.New(cmn.Fmt("Tendermint state.AppHash does not match AppHash after replay. Got %X, expected %X", appHash, h.state.AppHash)).Error()) return nil } return nil diff --git a/consensus/replay_file.go b/consensus/replay_file.go index e5056ef0d..1d2a91f31 100644 --- a/consensus/replay_file.go +++ b/consensus/replay_file.go @@ -10,13 +10,12 @@ import ( "github.com/spf13/viper" - cfg "github.com/tendermint/go-config" 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" + cmn "github.com/tendermint/tmlibs/common" dbm "github.com/tendermint/tmlibs/db" ) @@ -27,7 +26,7 @@ func RunReplayFile(config *viper.Viper, walFile string, console bool) { consensusState := newConsensusStateForReplay(config) if err := consensusState.ReplayFile(walFile, console); err != nil { - Exit(Fmt("Error during consensus replay: %v", err)) + cmn.Exit(cmn.Fmt("Error during consensus replay: %v", err)) } } @@ -116,7 +115,7 @@ func (pb *playback) replayReset(count int, newStepCh chan interface{}) error { pb.fp = fp pb.scanner = bufio.NewScanner(fp) count = pb.count - count - log.Notice(Fmt("Reseting from %d to %d", pb.count, count)) + log.Notice(cmn.Fmt("Reseting from %d to %d", pb.count, count)) pb.count = 0 pb.cs = newCS for i := 0; pb.scanner.Scan() && i < count; i++ { @@ -151,9 +150,9 @@ func (pb *playback) replayConsoleLoop() int { bufReader := bufio.NewReader(os.Stdin) line, more, err := bufReader.ReadLine() if more { - Exit("input is too long") + cmn.Exit("input is too long") } else if err != nil { - Exit(err.Error()) + cmn.Exit(err.Error()) } tokens := strings.Split(string(line), " ") @@ -251,7 +250,7 @@ func newConsensusStateForReplay(config *viper.Viper) *ConsensusState { proxyApp := proxy.NewAppConns(config, proxy.DefaultClientCreator(config), NewHandshaker(config, state, blockStore)) _, err := proxyApp.Start() if err != nil { - Exit(Fmt("Error starting proxy app conns: %v", err)) + cmn.Exit(cmn.Fmt("Error starting proxy app conns: %v", err)) } // add the chainid to the global config @@ -260,7 +259,7 @@ func newConsensusStateForReplay(config *viper.Viper) *ConsensusState { // Make event switch eventSwitch := types.NewEventSwitch() if _, err := eventSwitch.Start(); err != nil { - Exit(Fmt("Failed to start event switch: %v", err)) + cmn.Exit(cmn.Fmt("Failed to start event switch: %v", err)) } mempool := mempl.NewMempool(config, proxyApp.Mempool()) diff --git a/consensus/replay_test.go b/consensus/replay_test.go index b78d5915f..e486af83e 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -15,7 +15,6 @@ import ( "github.com/spf13/viper" "github.com/tendermint/abci/example/dummy" - cfg "github.com/tendermint/go-config" "github.com/tendermint/go-crypto" "github.com/tendermint/go-wire" "github.com/tendermint/tendermint/config/tendermint_test" diff --git a/consensus/state.go b/consensus/state.go index 06c20db2a..28836a079 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -12,12 +12,11 @@ import ( "github.com/ebuchman/fail-test" "github.com/spf13/viper" - 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" + cmn "github.com/tendermint/tmlibs/common" ) //----------------------------------------------------------------------------- @@ -223,7 +222,7 @@ type PrivValidator interface { // Tracks consensus state across block heights and rounds. type ConsensusState struct { - BaseService + cmn.BaseService config *viper.Viper proxyAppConn proxy.AppConnConsensus @@ -277,7 +276,7 @@ func NewConsensusState(config *viper.Viper, state *sm.State, proxyAppConn proxy. // Don't call scheduleRound0 yet. // We do that upon Start(). cs.reconstructLastCommit(state) - cs.BaseService = *NewBaseService(log, "ConsensusState", cs) + cs.BaseService = *cmn.NewBaseService(log, "ConsensusState", cs) return cs } @@ -291,7 +290,7 @@ func (cs *ConsensusState) SetEventSwitch(evsw types.EventSwitch) { func (cs *ConsensusState) String() string { // better not to access shared variables - return Fmt("ConsensusState") //(H:%v R:%v S:%v", cs.Height, cs.Round, cs.Step) + return cmn.Fmt("ConsensusState") //(H:%v R:%v S:%v", cs.Height, cs.Round, cs.Step) } func (cs *ConsensusState) GetState() *sm.State { @@ -399,7 +398,7 @@ func (cs *ConsensusState) Wait() { // Open file to log all consensus messages and timeouts for deterministic accountability func (cs *ConsensusState) OpenWAL(walFile string) (err error) { - err = EnsureDir(path.Dir(walFile), 0700) + err = cmn.EnsureDir(path.Dir(walFile), 0700) if err != nil { log.Error("Error ensuring ConsensusState wal dir", "error", err.Error()) return err @@ -520,11 +519,11 @@ func (cs *ConsensusState) reconstructLastCommit(state *sm.State) { } added, err := lastPrecommits.AddVote(precommit) if !added || err != nil { - PanicCrisis(Fmt("Failed to reconstruct LastCommit: %v", err)) + cmn.PanicCrisis(cmn.Fmt("Failed to reconstruct LastCommit: %v", err)) } } if !lastPrecommits.HasTwoThirdsMajority() { - PanicSanity("Failed to reconstruct LastCommit: Does not have +2/3 maj") + cmn.PanicSanity("Failed to reconstruct LastCommit: Does not have +2/3 maj") } cs.LastCommit = lastPrecommits } @@ -533,13 +532,13 @@ func (cs *ConsensusState) reconstructLastCommit(state *sm.State) { // The round becomes 0 and cs.Step becomes RoundStepNewHeight. func (cs *ConsensusState) updateToState(state *sm.State) { if cs.CommitRound > -1 && 0 < cs.Height && cs.Height != state.LastBlockHeight { - PanicSanity(Fmt("updateToState() expected state height of %v but found %v", + cmn.PanicSanity(cmn.Fmt("updateToState() expected state height of %v but found %v", cs.Height, state.LastBlockHeight)) } if cs.state != nil && cs.state.LastBlockHeight+1 != cs.Height { // This might happen when someone else is mutating cs.state. // Someone forgot to pass in state.Copy() somewhere?! - PanicSanity(Fmt("Inconsistent cs.state.LastBlockHeight+1 %v vs cs.Height %v", + cmn.PanicSanity(cmn.Fmt("Inconsistent cs.state.LastBlockHeight+1 %v vs cs.Height %v", cs.state.LastBlockHeight+1, cs.Height)) } @@ -556,7 +555,7 @@ func (cs *ConsensusState) updateToState(state *sm.State) { lastPrecommits := (*types.VoteSet)(nil) if cs.CommitRound > -1 && cs.Votes != nil { if !cs.Votes.Precommits(cs.CommitRound).HasTwoThirdsMajority() { - PanicSanity("updateToState(state) called but last Precommit round didn't have +2/3") + cmn.PanicSanity("updateToState(state) called but last Precommit round didn't have +2/3") } lastPrecommits = cs.Votes.Precommits(cs.CommitRound) } @@ -724,7 +723,7 @@ func (cs *ConsensusState) handleTimeout(ti timeoutInfo, rs RoundState) { types.FireEventTimeoutWait(cs.evsw, cs.RoundStateEvent()) cs.enterNewRound(ti.Height, ti.Round+1) default: - panic(Fmt("Invalid timeout step: %v", ti.Step)) + panic(cmn.Fmt("Invalid timeout step: %v", ti.Step)) } } @@ -739,7 +738,7 @@ func (cs *ConsensusState) handleTimeout(ti timeoutInfo, rs RoundState) { // NOTE: cs.StartTime was already set for height. func (cs *ConsensusState) enterNewRound(height int, round int) { if cs.Height != height || round < cs.Round || (cs.Round == round && cs.Step != RoundStepNewHeight) { - log.Debug(Fmt("enterNewRound(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) + log.Debug(cmn.Fmt("enterNewRound(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) return } @@ -747,7 +746,7 @@ func (cs *ConsensusState) enterNewRound(height int, round int) { log.Warn("Need to set a buffer and log.Warn() here for sanity.", "startTime", cs.StartTime, "now", now) } - log.Notice(Fmt("enterNewRound(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) + log.Notice(cmn.Fmt("enterNewRound(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) // Increment validators if necessary validators := cs.Validators @@ -781,10 +780,10 @@ func (cs *ConsensusState) enterNewRound(height int, round int) { // Enter: from NewRound(height,round). func (cs *ConsensusState) enterPropose(height int, round int) { if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPropose <= cs.Step) { - log.Debug(Fmt("enterPropose(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) + log.Debug(cmn.Fmt("enterPropose(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) return } - log.Info(Fmt("enterPropose(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) + log.Info(cmn.Fmt("enterPropose(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) defer func() { // Done enterPropose: @@ -851,7 +850,7 @@ func (cs *ConsensusState) defaultDecideProposal(height, round int) { cs.sendInternalMessage(msgInfo{&BlockPartMessage{cs.Height, cs.Round, part}, ""}) } log.Info("Signed proposal", "height", height, "round", round, "proposal", proposal) - log.Debug(Fmt("Signed proposal block: %v", block)) + log.Debug(cmn.Fmt("Signed proposal block: %v", block)) } else { if !cs.replayMode { log.Warn("enterPropose: Error signing proposal", "height", height, "round", round, "error", err) @@ -907,7 +906,7 @@ func (cs *ConsensusState) createProposalBlock() (block *types.Block, blockParts // Otherwise vote nil. func (cs *ConsensusState) enterPrevote(height int, round int) { if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPrevote <= cs.Step) { - log.Debug(Fmt("enterPrevote(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) + log.Debug(cmn.Fmt("enterPrevote(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) return } @@ -925,7 +924,7 @@ func (cs *ConsensusState) enterPrevote(height int, round int) { // TODO: catchup event? } - log.Info(Fmt("enterPrevote(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) + log.Info(cmn.Fmt("enterPrevote(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) // Sign and broadcast vote as necessary cs.doPrevote(height, round) @@ -968,13 +967,13 @@ func (cs *ConsensusState) defaultDoPrevote(height int, round int) { // Enter: any +2/3 prevotes at next round. func (cs *ConsensusState) enterPrevoteWait(height int, round int) { if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPrevoteWait <= cs.Step) { - log.Debug(Fmt("enterPrevoteWait(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) + log.Debug(cmn.Fmt("enterPrevoteWait(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) return } if !cs.Votes.Prevotes(round).HasTwoThirdsAny() { - PanicSanity(Fmt("enterPrevoteWait(%v/%v), but Prevotes does not have any +2/3 votes", height, round)) + cmn.PanicSanity(cmn.Fmt("enterPrevoteWait(%v/%v), but Prevotes does not have any +2/3 votes", height, round)) } - log.Info(Fmt("enterPrevoteWait(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) + log.Info(cmn.Fmt("enterPrevoteWait(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) defer func() { // Done enterPrevoteWait: @@ -994,11 +993,11 @@ func (cs *ConsensusState) enterPrevoteWait(height int, round int) { // else, precommit nil otherwise. func (cs *ConsensusState) enterPrecommit(height int, round int) { if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPrecommit <= cs.Step) { - log.Debug(Fmt("enterPrecommit(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) + log.Debug(cmn.Fmt("enterPrecommit(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) return } - log.Info(Fmt("enterPrecommit(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) + log.Info(cmn.Fmt("enterPrecommit(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) defer func() { // Done enterPrecommit: @@ -1025,7 +1024,7 @@ func (cs *ConsensusState) enterPrecommit(height int, round int) { // the latest POLRound should be this round polRound, _ := cs.Votes.POLInfo() if polRound < round { - PanicSanity(Fmt("This POLRound should be %v but got %", round, polRound)) + cmn.PanicSanity(cmn.Fmt("This POLRound should be %v but got %", round, polRound)) } // +2/3 prevoted nil. Unlock and precommit nil. @@ -1059,7 +1058,7 @@ func (cs *ConsensusState) enterPrecommit(height int, round int) { log.Notice("enterPrecommit: +2/3 prevoted proposal block. Locking", "hash", blockID.Hash) // Validate the block. if err := cs.state.ValidateBlock(cs.ProposalBlock); err != nil { - PanicConsensus(Fmt("enterPrecommit: +2/3 prevoted for an invalid block: %v", err)) + cmn.PanicConsensus(cmn.Fmt("enterPrecommit: +2/3 prevoted for an invalid block: %v", err)) } cs.LockedRound = round cs.LockedBlock = cs.ProposalBlock @@ -1088,13 +1087,13 @@ func (cs *ConsensusState) enterPrecommit(height int, round int) { // Enter: any +2/3 precommits for next round. func (cs *ConsensusState) enterPrecommitWait(height int, round int) { if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPrecommitWait <= cs.Step) { - log.Debug(Fmt("enterPrecommitWait(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) + log.Debug(cmn.Fmt("enterPrecommitWait(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) return } if !cs.Votes.Precommits(round).HasTwoThirdsAny() { - PanicSanity(Fmt("enterPrecommitWait(%v/%v), but Precommits does not have any +2/3 votes", height, round)) + cmn.PanicSanity(cmn.Fmt("enterPrecommitWait(%v/%v), but Precommits does not have any +2/3 votes", height, round)) } - log.Info(Fmt("enterPrecommitWait(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) + log.Info(cmn.Fmt("enterPrecommitWait(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) defer func() { // Done enterPrecommitWait: @@ -1110,10 +1109,10 @@ func (cs *ConsensusState) enterPrecommitWait(height int, round int) { // Enter: +2/3 precommits for block func (cs *ConsensusState) enterCommit(height int, commitRound int) { if cs.Height != height || RoundStepCommit <= cs.Step { - log.Debug(Fmt("enterCommit(%v/%v): Invalid args. Current step: %v/%v/%v", height, commitRound, cs.Height, cs.Round, cs.Step)) + log.Debug(cmn.Fmt("enterCommit(%v/%v): Invalid args. Current step: %v/%v/%v", height, commitRound, cs.Height, cs.Round, cs.Step)) return } - log.Info(Fmt("enterCommit(%v/%v). Current: %v/%v/%v", height, commitRound, cs.Height, cs.Round, cs.Step)) + log.Info(cmn.Fmt("enterCommit(%v/%v). Current: %v/%v/%v", height, commitRound, cs.Height, cs.Round, cs.Step)) defer func() { // Done enterCommit: @@ -1129,7 +1128,7 @@ func (cs *ConsensusState) enterCommit(height int, commitRound int) { blockID, ok := cs.Votes.Precommits(commitRound).TwoThirdsMajority() if !ok { - PanicSanity("RunActionCommit() expects +2/3 precommits") + cmn.PanicSanity("RunActionCommit() expects +2/3 precommits") } // The Locked* fields no longer matter. @@ -1156,7 +1155,7 @@ func (cs *ConsensusState) enterCommit(height int, commitRound int) { // If we have the block AND +2/3 commits for it, finalize. func (cs *ConsensusState) tryFinalizeCommit(height int) { if cs.Height != height { - PanicSanity(Fmt("tryFinalizeCommit() cs.Height: %v vs height: %v", cs.Height, height)) + cmn.PanicSanity(cmn.Fmt("tryFinalizeCommit() cs.Height: %v vs height: %v", cs.Height, height)) } blockID, ok := cs.Votes.Precommits(cs.CommitRound).TwoThirdsMajority() @@ -1177,7 +1176,7 @@ func (cs *ConsensusState) tryFinalizeCommit(height int) { // Increment height and goto RoundStepNewHeight func (cs *ConsensusState) finalizeCommit(height int) { if cs.Height != height || cs.Step != RoundStepCommit { - log.Debug(Fmt("finalizeCommit(%v): Invalid args. Current step: %v/%v/%v", height, cs.Height, cs.Round, cs.Step)) + log.Debug(cmn.Fmt("finalizeCommit(%v): Invalid args. Current step: %v/%v/%v", height, cs.Height, cs.Round, cs.Step)) return } @@ -1185,21 +1184,21 @@ func (cs *ConsensusState) finalizeCommit(height int) { block, blockParts := cs.ProposalBlock, cs.ProposalBlockParts if !ok { - PanicSanity(Fmt("Cannot finalizeCommit, commit does not have two thirds majority")) + cmn.PanicSanity(cmn.Fmt("Cannot finalizeCommit, commit does not have two thirds majority")) } if !blockParts.HasHeader(blockID.PartsHeader) { - PanicSanity(Fmt("Expected ProposalBlockParts header to be commit header")) + cmn.PanicSanity(cmn.Fmt("Expected ProposalBlockParts header to be commit header")) } if !block.HashesTo(blockID.Hash) { - PanicSanity(Fmt("Cannot finalizeCommit, ProposalBlock does not hash to commit hash")) + cmn.PanicSanity(cmn.Fmt("Cannot finalizeCommit, ProposalBlock does not hash to commit hash")) } if err := cs.state.ValidateBlock(block); err != nil { - PanicConsensus(Fmt("+2/3 committed an invalid block: %v", err)) + cmn.PanicConsensus(cmn.Fmt("+2/3 committed an invalid block: %v", err)) } - log.Notice(Fmt("Finalizing commit of block with %d txs", block.NumTxs), + log.Notice(cmn.Fmt("Finalizing commit of block with %d txs", block.NumTxs), "height", block.Height, "hash", block.Hash(), "root", block.AppHash) - log.Info(Fmt("%v", block)) + log.Info(cmn.Fmt("%v", block)) fail.Fail() // XXX @@ -1394,7 +1393,7 @@ func (cs *ConsensusState) addVote(vote *types.Vote, peerKey string) (added bool, } added, err = cs.LastCommit.AddVote(vote) if added { - log.Info(Fmt("Added to lastPrecommits: %v", cs.LastCommit.StringShort())) + log.Info(cmn.Fmt("Added to lastPrecommits: %v", cs.LastCommit.StringShort())) types.FireEventVote(cs.evsw, types.EventDataVote{vote}) // if we can skip timeoutCommit and have all the votes now, @@ -1475,7 +1474,7 @@ func (cs *ConsensusState) addVote(vote *types.Vote, peerKey string) (added bool, cs.enterPrecommitWait(height, vote.Round) } default: - PanicSanity(Fmt("Unexpected vote type %X", vote.Type)) // Should not happen. + cmn.PanicSanity(cmn.Fmt("Unexpected vote type %X", vote.Type)) // Should not happen. } } // Either duplicate, or error upon cs.Votes.AddByIndex() diff --git a/glide.lock b/glide.lock index 70da9fac1..7720c946b 100644 --- a/glide.lock +++ b/glide.lock @@ -1,12 +1,10 @@ -hash: 9096fc4e29eff8fac3708ed30deacac67b7a181f0192b177006105dccdb16686 -updated: 2017-04-21T18:39:37.154946943-04:00 +hash: 6f8962f6ca0e25b8e43bc6e496bd46c9ff3a79dcf789578efeeaee2fffc39c6e +updated: 2017-04-25T14:48:36.999444976-04:00 imports: - name: github.com/btcsuite/btcd version: 583684b21bfbde9b5fc4403916fd7c807feb0289 subpackages: - btcec -- name: github.com/BurntSushi/toml - version: 99064174e013895bbd9b025c31100bd1d9b590ca - name: github.com/davecgh/go-spew version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 subpackages: @@ -55,7 +53,7 @@ imports: - name: github.com/pelletier/go-buffruneio version: c37440a7cf42ac63b919c752ca73a85067e05992 - name: github.com/pelletier/go-toml - version: fe206efb84b2bc8e8cfafe6b4c1826622be969e3 + version: 13d49d4606eb801b8f01ae542b4afc4c6ee3d84a - name: github.com/pkg/errors version: 645ef00459ed84a119197bfb8d8205042c6df63d - name: github.com/pmezard/go-difflib @@ -67,7 +65,7 @@ imports: subpackages: - mem - name: github.com/spf13/cast - version: ce135a4ebeee6cfe9a26c93ee0d37825f26113c7 + version: acbeb36b902d72a7a4c18e8f3241075e7ab763e4 - name: github.com/spf13/cobra version: fcd0c5a1df88f5d6784cb4feead962c3f3d0b66c - name: github.com/spf13/jwalterweatherman @@ -75,7 +73,7 @@ imports: - name: github.com/spf13/pflag version: 9ff6c6923cfffbcd502984b8e0c80539a94968b7 - name: github.com/spf13/viper - version: 84f94806c67f59dd7ae87bc5351f7a9c94a4558d + version: 5d46e70da8c0b6f812e0b170b7a985753b5c63cb - name: github.com/stretchr/testify version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 subpackages: @@ -97,7 +95,7 @@ imports: - leveldb/table - leveldb/util - name: github.com/tendermint/abci - version: be61e273cebeb64866a83c578f92b22cf2169cdd + version: c709d3cc857929a8dd36a90da3640122d7e75770 subpackages: - client - example/counter @@ -109,10 +107,6 @@ imports: subpackages: - edwards25519 - extra25519 -- name: github.com/tendermint/go-common - version: 6af2364fa91ef2f3afc8ba0db33b66d9d3ae006c - subpackages: - - test - name: github.com/tendermint/go-crypto version: 9b95da8fa4187f6799558d89b271dc8ab6485615 - name: github.com/tendermint/go-wire diff --git a/glide.yaml b/glide.yaml index e4c2e4138..f06a16b3b 100644 --- a/glide.yaml +++ b/glide.yaml @@ -10,6 +10,7 @@ import: - package: github.com/gorilla/websocket - package: github.com/pkg/errors - package: github.com/spf13/cobra +- package: github.com/spf13/viper - package: github.com/stretchr/testify subpackages: - require @@ -19,8 +20,6 @@ import: - client - example/dummy - types -- package: github.com/tendermint/go-config - version: develop - package: github.com/tendermint/go-crypto version: develop - package: github.com/tendermint/go-wire @@ -39,17 +38,6 @@ 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 086a99e32..621f0931e 100644 --- a/mempool/mempool.go +++ b/mempool/mempool.go @@ -10,7 +10,6 @@ import ( "github.com/spf13/viper" abci "github.com/tendermint/abci/types" - cfg "github.com/tendermint/go-config" "github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/types" auto "github.com/tendermint/tmlibs/autofile" diff --git a/mempool/reactor.go b/mempool/reactor.go index d30fd1151..6bea53b0c 100644 --- a/mempool/reactor.go +++ b/mempool/reactor.go @@ -9,7 +9,6 @@ import ( "github.com/spf13/viper" abci "github.com/tendermint/abci/types" - cfg "github.com/tendermint/go-config" "github.com/tendermint/go-wire" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/types" diff --git a/node/node.go b/node/node.go index 17fb98bad..1c66c00e0 100644 --- a/node/node.go +++ b/node/node.go @@ -10,7 +10,6 @@ import ( "github.com/spf13/viper" abci "github.com/tendermint/abci/types" - cfg "github.com/tendermint/go-config" crypto "github.com/tendermint/go-crypto" wire "github.com/tendermint/go-wire" bc "github.com/tendermint/tendermint/blockchain" diff --git a/p2p/config.go b/p2p/config.go index a8b7e343b..2e70d16df 100644 --- a/p2p/config.go +++ b/p2p/config.go @@ -1,7 +1,7 @@ package p2p import ( - cfg "github.com/tendermint/go-config" + "github.com/spf13/viper" ) const ( @@ -24,7 +24,7 @@ const ( configFuzzProbSleep = "fuzz_prob_sleep" ) -func setConfigDefaults(config cfg.Config) { +func setConfigDefaults(config *viper.Viper) { // Switch default config config.SetDefault(configKeyDialTimeoutSeconds, 3) config.SetDefault(configKeyHandshakeTimeoutSeconds, 20) diff --git a/p2p/switch.go b/p2p/switch.go index 8c771df1c..7e9c0a9c6 100644 --- a/p2p/switch.go +++ b/p2p/switch.go @@ -7,7 +7,8 @@ import ( "net" "time" - cfg "github.com/tendermint/go-config" + "github.com/spf13/viper" + crypto "github.com/tendermint/go-crypto" "github.com/tendermint/log15" . "github.com/tendermint/tmlibs/common" @@ -61,7 +62,7 @@ incoming messages are received on the reactor. type Switch struct { BaseService - config cfg.Config + config *viper.Viper listeners []Listener reactors map[string]Reactor chDescs []*ChannelDescriptor @@ -80,7 +81,7 @@ var ( ErrSwitchMaxPeersPerIPRange = errors.New("IP range has too many peers") ) -func NewSwitch(config cfg.Config) *Switch { +func NewSwitch(config *viper.Viper) *Switch { setConfigDefaults(config) sw := &Switch{ @@ -529,7 +530,7 @@ func makeSwitch(i int, network, version string, initSwitch func(int, *Switch) *S privKey := crypto.GenPrivKeyEd25519() // new switch, add reactors // TODO: let the config be passed in? - s := initSwitch(i, NewSwitch(cfg.NewMapConfig(nil))) + s := initSwitch(i, NewSwitch(viper.New())) s.SetNodeInfo(&NodeInfo{ PubKey: privKey.PubKey().Unwrap().(crypto.PubKeyEd25519), Moniker: Fmt("switch%d", i), @@ -572,7 +573,7 @@ func (sw *Switch) addPeerWithConnectionAndConfig(conn net.Conn, config *PeerConf return nil } -func peerConfigFromGoConfig(config cfg.Config) *PeerConfig { +func peerConfigFromGoConfig(config *viper.Viper) *PeerConfig { return &PeerConfig{ AuthEnc: config.GetBool(configKeyAuthEnc), Fuzz: config.GetBool(configFuzzEnable), diff --git a/p2p/switch_test.go b/p2p/switch_test.go index 1f1fe69f0..38529d754 100644 --- a/p2p/switch_test.go +++ b/p2p/switch_test.go @@ -8,20 +8,21 @@ import ( "testing" "time" + "github.com/spf13/viper" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - . "github.com/tendermint/tmlibs/common" - cfg "github.com/tendermint/go-config" crypto "github.com/tendermint/go-crypto" wire "github.com/tendermint/go-wire" + . "github.com/tendermint/tmlibs/common" ) var ( - config cfg.Config + config *viper.Viper ) func init() { - config = cfg.NewMapConfig(nil) + config = viper.New() setConfigDefaults(config) } diff --git a/proxy/app_conn_test.go b/proxy/app_conn_test.go index 7c072625a..f9c6afc98 100644 --- a/proxy/app_conn_test.go +++ b/proxy/app_conn_test.go @@ -4,11 +4,11 @@ import ( "strings" "testing" - . "github.com/tendermint/tmlibs/common" abcicli "github.com/tendermint/abci/client" "github.com/tendermint/abci/example/dummy" "github.com/tendermint/abci/server" "github.com/tendermint/abci/types" + cmn "github.com/tendermint/tmlibs/common" ) //---------------------------------------- @@ -44,43 +44,43 @@ func (app *appConnTest) InfoSync() (types.ResponseInfo, error) { var SOCKET = "socket" func TestEcho(t *testing.T) { - sockPath := Fmt("unix:///tmp/echo_%v.sock", RandStr(6)) + sockPath := cmn.Fmt("unix:///tmp/echo_%v.sock", cmn.RandStr(6)) clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true) // Start server s, err := server.NewSocketServer(sockPath, dummy.NewDummyApplication()) if err != nil { - Exit(err.Error()) + cmn.Exit(err.Error()) } defer s.Stop() // Start client cli, err := clientCreator.NewABCIClient() if err != nil { - Exit(err.Error()) + cmn.Exit(err.Error()) } proxy := NewAppConnTest(cli) t.Log("Connected") for i := 0; i < 1000; i++ { - proxy.EchoAsync(Fmt("echo-%v", i)) + proxy.EchoAsync(cmn.Fmt("echo-%v", i)) } proxy.FlushSync() } func BenchmarkEcho(b *testing.B) { b.StopTimer() // Initialize - sockPath := Fmt("unix:///tmp/echo_%v.sock", RandStr(6)) + sockPath := cmn.Fmt("unix:///tmp/echo_%v.sock", cmn.RandStr(6)) clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true) // Start server s, err := server.NewSocketServer(sockPath, dummy.NewDummyApplication()) if err != nil { - Exit(err.Error()) + cmn.Exit(err.Error()) } defer s.Stop() // Start client cli, err := clientCreator.NewABCIClient() if err != nil { - Exit(err.Error()) + cmn.Exit(err.Error()) } proxy := NewAppConnTest(cli) b.Log("Connected") @@ -98,18 +98,18 @@ func BenchmarkEcho(b *testing.B) { } func TestInfo(t *testing.T) { - sockPath := Fmt("unix:///tmp/echo_%v.sock", RandStr(6)) + sockPath := cmn.Fmt("unix:///tmp/echo_%v.sock", cmn.RandStr(6)) clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true) // Start server s, err := server.NewSocketServer(sockPath, dummy.NewDummyApplication()) if err != nil { - Exit(err.Error()) + cmn.Exit(err.Error()) } defer s.Stop() // Start client cli, err := clientCreator.NewABCIClient() if err != nil { - Exit(err.Error()) + cmn.Exit(err.Error()) } proxy := NewAppConnTest(cli) t.Log("Connected") diff --git a/proxy/multi_app_conn.go b/proxy/multi_app_conn.go index bb846c7fa..9f70713eb 100644 --- a/proxy/multi_app_conn.go +++ b/proxy/multi_app_conn.go @@ -2,7 +2,6 @@ package proxy import ( "github.com/spf13/viper" - cfg "github.com/tendermint/go-config" cmn "github.com/tendermint/tmlibs/common" ) diff --git a/rpc/tendermint/core/pipe.go b/rpc/tendermint/core/pipe.go index 6f4740902..b10ff4737 100644 --- a/rpc/tendermint/core/pipe.go +++ b/rpc/tendermint/core/pipe.go @@ -2,7 +2,6 @@ package core import ( "github.com/spf13/viper" - cfg "github.com/tendermint/go-config" crypto "github.com/tendermint/go-crypto" "github.com/tendermint/tendermint/consensus" diff --git a/rpc/tendermint/test/helpers.go b/rpc/tendermint/test/helpers.go index f89287670..4e281f8c3 100644 --- a/rpc/tendermint/test/helpers.go +++ b/rpc/tendermint/test/helpers.go @@ -15,7 +15,6 @@ import ( logger "github.com/tendermint/tmlibs/logger" abci "github.com/tendermint/abci/types" - cfg "github.com/tendermint/go-config" "github.com/tendermint/tendermint/config/tendermint_test" nm "github.com/tendermint/tendermint/node" "github.com/tendermint/tendermint/proxy" diff --git a/state/errors.go b/state/errors.go index 1ea7ed3d9..50c5a2c04 100644 --- a/state/errors.go +++ b/state/errors.go @@ -1,7 +1,7 @@ package state import ( - . "github.com/tendermint/tmlibs/common" + cmn "github.com/tendermint/tmlibs/common" ) type ( @@ -36,20 +36,20 @@ type ( ) func (e ErrUnknownBlock) Error() string { - return Fmt("Could not find block #%d", e.Height) + return cmn.Fmt("Could not find block #%d", e.Height) } func (e ErrBlockHashMismatch) Error() string { - return Fmt("App block hash (%X) does not match core block hash (%X) for height %d", e.AppHash, e.CoreHash, e.Height) + return cmn.Fmt("App block hash (%X) does not match core block hash (%X) for height %d", e.AppHash, e.CoreHash, e.Height) } func (e ErrAppBlockHeightTooHigh) Error() string { - return Fmt("App block height (%d) is higher than core (%d)", e.AppHeight, e.CoreHeight) + return cmn.Fmt("App block height (%d) is higher than core (%d)", e.AppHeight, e.CoreHeight) } func (e ErrLastStateMismatch) Error() string { - return Fmt("Latest tendermint block (%d) LastAppHash (%X) does not match app's AppHash (%X)", e.Height, e.Core, e.App) + return cmn.Fmt("Latest tendermint block (%d) LastAppHash (%X) does not match app's AppHash (%X)", e.Height, e.Core, e.App) } func (e ErrStateMismatch) Error() string { - return Fmt("State after replay does not match saved state. Got ----\n%v\nExpected ----\n%v\n", e.Got, e.Expected) + return cmn.Fmt("State after replay does not match saved state. Got ----\n%v\nExpected ----\n%v\n", e.Got, e.Expected) } diff --git a/state/execution.go b/state/execution.go index 643dd4d05..b06974cd8 100644 --- a/state/execution.go +++ b/state/execution.go @@ -6,11 +6,11 @@ import ( fail "github.com/ebuchman/fail-test" abci "github.com/tendermint/abci/types" - . "github.com/tendermint/tmlibs/common" crypto "github.com/tendermint/go-crypto" "github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/state/txindex" "github.com/tendermint/tendermint/types" + cmn "github.com/tendermint/tmlibs/common" ) //-------------------------------------------------- @@ -126,7 +126,7 @@ func updateValidators(validators *types.ValidatorSet, changedValidators []*abci. power := int64(v.Power) // mind the overflow from uint64 if power < 0 { - return errors.New(Fmt("Power (%d) overflows int64", v.Power)) + return errors.New(cmn.Fmt("Power (%d) overflows int64", v.Power)) } _, val := validators.GetByAddress(address) @@ -134,20 +134,20 @@ func updateValidators(validators *types.ValidatorSet, changedValidators []*abci. // add val added := validators.Add(types.NewValidator(pubkey, power)) if !added { - return errors.New(Fmt("Failed to add new validator %X with voting power %d", address, power)) + return errors.New(cmn.Fmt("Failed to add new validator %X with voting power %d", address, power)) } } else if v.Power == 0 { // remove val _, removed := validators.Remove(address) if !removed { - return errors.New(Fmt("Failed to remove validator %X)")) + return errors.New(cmn.Fmt("Failed to remove validator %X)")) } } else { // update val val.VotingPower = power updated := validators.Update(val) if !updated { - return errors.New(Fmt("Failed to update validator %X with voting power %d", address, power)) + return errors.New(cmn.Fmt("Failed to update validator %X with voting power %d", address, power)) } } } @@ -156,8 +156,8 @@ func updateValidators(validators *types.ValidatorSet, changedValidators []*abci. // return a bit array of validators that signed the last commit // NOTE: assumes commits have already been authenticated -func commitBitArrayFromBlock(block *types.Block) *BitArray { - signed := NewBitArray(len(block.LastCommit.Precommits)) +func commitBitArrayFromBlock(block *types.Block) *cmn.BitArray { + signed := cmn.NewBitArray(len(block.LastCommit.Precommits)) for i, precommit := range block.LastCommit.Precommits { if precommit != nil { signed.SetIndex(i, true) // val_.LastCommitHeight = block.Height - 1 @@ -187,7 +187,7 @@ func (s *State) validateBlock(block *types.Block) error { } } else { if len(block.LastCommit.Precommits) != s.LastValidators.Size() { - return errors.New(Fmt("Invalid block commit size. Expected %v, got %v", + return errors.New(cmn.Fmt("Invalid block commit size. Expected %v, got %v", s.LastValidators.Size(), len(block.LastCommit.Precommits))) } err := s.LastValidators.VerifyCommit( diff --git a/state/state.go b/state/state.go index 3055fb7b7..2625cbc71 100644 --- a/state/state.go +++ b/state/state.go @@ -8,8 +8,7 @@ import ( "github.com/spf13/viper" abci "github.com/tendermint/abci/types" - cfg "github.com/tendermint/go-config" - . "github.com/tendermint/tmlibs/common" + cmn "github.com/tendermint/tmlibs/common" dbm "github.com/tendermint/tmlibs/db" "github.com/tendermint/go-wire" @@ -66,7 +65,7 @@ func loadState(db dbm.DB, key []byte) *State { wire.ReadBinaryPtr(&s, r, 0, n, err) if *err != nil { // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED - Exit(Fmt("LoadState: Data has been corrupted or its spec has changed: %v\n", *err)) + cmn.Exit(cmn.Fmt("LoadState: Data has been corrupted or its spec has changed: %v\n", *err)) } // TODO: ensure that buf is completely read. } @@ -110,7 +109,7 @@ func (s *State) LoadABCIResponses() *ABCIResponses { wire.ReadBinaryPtr(abciResponses, r, 0, n, err) if *err != nil { // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED - Exit(Fmt("LoadABCIResponses: Data has been corrupted or its spec has changed: %v\n", *err)) + cmn.Exit(cmn.Fmt("LoadABCIResponses: Data has been corrupted or its spec has changed: %v\n", *err)) } // TODO: ensure that buf is completely read. } @@ -125,7 +124,7 @@ func (s *State) Bytes() []byte { buf, n, err := new(bytes.Buffer), new(int), new(error) wire.WriteBinary(s, buf, n, err) if *err != nil { - PanicCrisis(*err) + cmn.PanicCrisis(*err) } return buf.Bytes() } @@ -205,7 +204,7 @@ func (a *ABCIResponses) Bytes() []byte { buf, n, err := new(bytes.Buffer), new(int), new(error) wire.WriteBinary(*a, buf, n, err) if *err != nil { - PanicCrisis(*err) + cmn.PanicCrisis(*err) } return buf.Bytes() } @@ -219,11 +218,11 @@ func (a *ABCIResponses) Bytes() []byte { func MakeGenesisStateFromFile(db dbm.DB, genDocFile string) *State { genDocJSON, err := ioutil.ReadFile(genDocFile) if err != nil { - Exit(Fmt("Couldn't read GenesisDoc file: %v", err)) + cmn.Exit(cmn.Fmt("Couldn't read GenesisDoc file: %v", err)) } genDoc, err := types.GenesisDocFromJSON(genDocJSON) if err != nil { - Exit(Fmt("Error reading GenesisDoc: %v", err)) + cmn.Exit(cmn.Fmt("Error reading GenesisDoc: %v", err)) } return MakeGenesisState(db, genDoc) } @@ -233,7 +232,7 @@ func MakeGenesisStateFromFile(db dbm.DB, genDocFile string) *State { // Used in tests. func MakeGenesisState(db dbm.DB, genDoc *types.GenesisDoc) *State { if len(genDoc.Validators) == 0 { - Exit(Fmt("The genesis file has no validators")) + cmn.Exit(cmn.Fmt("The genesis file has no validators")) } if genDoc.GenesisTime.IsZero() { diff --git a/test/test_libs.sh b/test/test_libs.sh index 1d57ae049..3f4315cd9 100644 --- a/test/test_libs.sh +++ b/test/test_libs.sh @@ -14,8 +14,8 @@ fi # some libs are tested with go, others with make # TODO: should be all make (post repo merge) -LIBS_GO_TEST=(tmlibs/clist tmlibs/common go-config go-crypto tmlibs/db tmlibs/events go-merkle tendermint/p2p) -LIBS_MAKE_TEST=(tendermint/rpc go-wire abci) +LIBS_GO_TEST=(tmlibs go-crypto) +LIBS_MAKE_TEST=(go-wire abci) for lib in "${LIBS_GO_TEST[@]}"; do From 2fcb2b9232ccd295c770111812e998c65903a2a9 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Tue, 25 Apr 2017 17:58:26 -0400 Subject: [PATCH 10/10] remove unsafe_set_config --- rpc/tendermint/core/routes.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rpc/tendermint/core/routes.go b/rpc/tendermint/core/routes.go index 1ed874f28..7ed18ef7f 100644 --- a/rpc/tendermint/core/routes.go +++ b/rpc/tendermint/core/routes.go @@ -3,8 +3,8 @@ package core import ( data "github.com/tendermint/go-wire/data" rpc "github.com/tendermint/tendermint/rpc/server" - "github.com/tendermint/tendermint/rpc/types" ctypes "github.com/tendermint/tendermint/rpc/tendermint/core/types" + "github.com/tendermint/tendermint/rpc/types" "github.com/tendermint/tendermint/types" ) @@ -39,7 +39,9 @@ var Routes = map[string]*rpc.RPCFunc{ // control API "dial_seeds": rpc.NewRPCFunc(UnsafeDialSeedsResult, "seeds"), "unsafe_flush_mempool": rpc.NewRPCFunc(UnsafeFlushMempool, ""), - "unsafe_set_config": rpc.NewRPCFunc(UnsafeSetConfigResult, "type,key,value"), + + // config is not in general thread safe. expose specifics if you need em + // "unsafe_set_config": rpc.NewRPCFunc(UnsafeSetConfigResult, "type,key,value"), // profiler API "unsafe_start_cpu_profiler": rpc.NewRPCFunc(UnsafeStartCPUProfilerResult, "filename"),