Browse Source

adding viper

int

int
pull/442/head
Rigel Rozanski 7 years ago
committed by Ethan Buchman
parent
commit
cefb2bede0
20 changed files with 223 additions and 167 deletions
  1. +6
    -4
      blockchain/reactor.go
  2. +2
    -1
      cmd/tendermint/commands/root.go
  3. +55
    -49
      config/tendermint/config.go
  4. +59
    -51
      config/tendermint_test/config.go
  5. +5
    -3
      consensus/byzantine_test.go
  6. +8
    -6
      consensus/common_test.go
  7. +6
    -4
      consensus/replay.go
  8. +6
    -4
      consensus/replay_file.go
  9. +8
    -7
      consensus/replay_test.go
  10. +5
    -4
      consensus/state.go
  11. +3
    -1
      glide.lock
  12. +11
    -0
      glide.yaml
  13. +7
    -5
      mempool/mempool.go
  14. +6
    -4
      mempool/reactor.go
  15. +15
    -9
      node/node.go
  16. +3
    -2
      proxy/client.go
  17. +5
    -4
      proxy/multi_app_conn.go
  18. +4
    -3
      rpc/tendermint/core/pipe.go
  19. +5
    -4
      rpc/tendermint/test/helpers.go
  20. +4
    -2
      state/state.go

+ 6
- 4
blockchain/reactor.go View File

@ -6,13 +6,15 @@ import (
"reflect" "reflect"
"time" "time"
cmn "github.com/tendermint/tmlibs/common"
"github.com/spf13/viper"
cfg "github.com/tendermint/go-config" cfg "github.com/tendermint/go-config"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/go-wire" "github.com/tendermint/go-wire"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common"
) )
const ( const (
@ -43,7 +45,7 @@ type consensusReactor interface {
type BlockchainReactor struct { type BlockchainReactor struct {
p2p.BaseReactor p2p.BaseReactor
config cfg.Config
config *viper.Viper
state *sm.State state *sm.State
proxyAppConn proxy.AppConnConsensus // same as consensus.proxyAppConn proxyAppConn proxy.AppConnConsensus // same as consensus.proxyAppConn
store *BlockStore store *BlockStore
@ -57,7 +59,7 @@ type BlockchainReactor struct {
} }
// NewBlockchainReactor returns new reactor instance. // 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 { if state.LastBlockHeight == store.Height()-1 {
store.height-- // XXX HACK, make this better store.height-- // XXX HACK, make this better
} }


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

@ -2,9 +2,10 @@ package commands
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/tmlibs/logger"
tmcfg "github.com/tendermint/tendermint/config/tendermint" tmcfg "github.com/tendermint/tendermint/config/tendermint"
"github.com/tendermint/tmlibs/logger"
) )
var ( var (


+ 55
- 49
config/tendermint/config.go View File

@ -5,8 +5,10 @@ import (
"path" "path"
"strings" "strings"
. "github.com/tendermint/tmlibs/common"
"github.com/spf13/viper"
cfg "github.com/tendermint/go-config" cfg "github.com/tendermint/go-config"
. "github.com/tendermint/tmlibs/common"
) )
func getTMRoot(rootDir string) string { 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) rootDir = getTMRoot(rootDir)
initTMRoot(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 { if err != nil {
Exit(Fmt("Could not read config: %v", err)) Exit(Fmt("Could not read config: %v", err))
} }
config.WatchConfig()
// Set defaults or panic // Set defaults or panic
if mapConfig.IsSet("chain_id") {
if config.IsSet("chain_id") {
Exit("Cannot set 'chain_id' via config.toml") 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") 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 // 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 // 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. var defaultConfigTmpl = `# This is a TOML config file.


+ 59
- 51
config/tendermint_test/config.go View File

@ -3,12 +3,15 @@
package tendermint_test package tendermint_test
import ( import (
"fmt"
"os" "os"
"path" "path"
"strings" "strings"
. "github.com/tendermint/tmlibs/common"
"github.com/spf13/viper"
cfg "github.com/tendermint/go-config" cfg "github.com/tendermint/go-config"
. "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/logger" "github.com/tendermint/tmlibs/logger"
) )
@ -53,65 +56,70 @@ func initTMRoot(rootDir string) {
MustWriteFile(privFilePath, []byte(defaultPrivValidator), 0644) MustWriteFile(privFilePath, []byte(defaultPrivValidator), 0644)
} }
func ResetConfig(localPath string) cfg.Config {
func ResetConfig(localPath string) *viper.Viper {
rootDir := os.Getenv("HOME") + "/.tendermint_test/" + localPath rootDir := os.Getenv("HOME") + "/.tendermint_test/" + localPath
initTMRoot(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 := config.ReadInConfig()
if err != nil { if err != nil {
Exit(Fmt("Could not read config: %v", err)) Exit(Fmt("Could not read config: %v", err))
} }
config.WatchConfig()
// Set defaults or panic // 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. var defaultConfigTmpl = `# This is a TOML config file.


+ 5
- 3
consensus/byzantine_test.go View File

@ -5,13 +5,15 @@ import (
"testing" "testing"
"time" "time"
"github.com/spf13/viper"
"github.com/tendermint/tendermint/config/tendermint_test" "github.com/tendermint/tendermint/config/tendermint_test"
. "github.com/tendermint/tmlibs/common"
cfg "github.com/tendermint/go-config" cfg "github.com/tendermint/go-config"
"github.com/tendermint/tmlibs/events"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
. "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/events"
) )
func init() { func init() {
@ -36,7 +38,7 @@ func TestByzantine(t *testing.T) {
switches := make([]*p2p.Switch, N) switches := make([]*p2p.Switch, N)
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
switches[i] = p2p.NewSwitch(cfg.NewMapConfig(nil))
switches[i] = p2p.NewSwitch(viper.New())
} }
reactors := make([]p2p.Reactor, N) reactors := make([]p2p.Reactor, N)


+ 8
- 6
consensus/common_test.go View File

@ -11,23 +11,25 @@ import (
"testing" "testing"
"time" "time"
"github.com/spf13/viper"
abcicli "github.com/tendermint/abci/client" abcicli "github.com/tendermint/abci/client"
abci "github.com/tendermint/abci/types" abci "github.com/tendermint/abci/types"
. "github.com/tendermint/tmlibs/common"
cfg "github.com/tendermint/go-config" cfg "github.com/tendermint/go-config"
dbm "github.com/tendermint/tmlibs/db"
"github.com/tendermint/tendermint/p2p"
bc "github.com/tendermint/tendermint/blockchain" bc "github.com/tendermint/tendermint/blockchain"
"github.com/tendermint/tendermint/config/tendermint_test" "github.com/tendermint/tendermint/config/tendermint_test"
mempl "github.com/tendermint/tendermint/mempool" mempl "github.com/tendermint/tendermint/mempool"
"github.com/tendermint/tendermint/p2p"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types" "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/counter"
"github.com/tendermint/abci/example/dummy" "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) var ensureTimeout = time.Duration(2)
func ensureDir(dir string, mode os.FileMode) { 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) 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 // Get BlockStore
blockDB := dbm.NewMemDB() blockDB := dbm.NewMemDB()
blockStore := bc.NewBlockStore(blockDB) blockStore := bc.NewBlockStore(blockDB)
@ -256,7 +258,7 @@ func newConsensusStateWithConfig(thisConfig cfg.Config, state *sm.State, pv *typ
return cs return cs
} }
func loadPrivValidator(conf cfg.Config) *types.PrivValidator {
func loadPrivValidator(conf *viper.Viper) *types.PrivValidator {
privValidatorFile := conf.GetString("priv_validator_file") privValidatorFile := conf.GetString("priv_validator_file")
ensureDir(path.Dir(privValidatorFile), 0700) ensureDir(path.Dir(privValidatorFile), 0700)
privValidator := types.LoadOrGenPrivValidator(privValidatorFile) privValidator := types.LoadOrGenPrivValidator(privValidatorFile)


+ 6
- 4
consensus/replay.go View File

@ -10,11 +10,13 @@ import (
"strings" "strings"
"time" "time"
"github.com/spf13/viper"
abci "github.com/tendermint/abci/types" abci "github.com/tendermint/abci/types"
auto "github.com/tendermint/tmlibs/autofile"
. "github.com/tendermint/tmlibs/common"
cfg "github.com/tendermint/go-config" cfg "github.com/tendermint/go-config"
"github.com/tendermint/go-wire" "github.com/tendermint/go-wire"
auto "github.com/tendermint/tmlibs/autofile"
. "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
sm "github.com/tendermint/tendermint/state" 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 // we were last and using the WAL to recover there
type Handshaker struct { type Handshaker struct {
config cfg.Config
config *viper.Viper
state *sm.State state *sm.State
store types.BlockStore store types.BlockStore
nBlocks int // number of blocks applied to the state 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} return &Handshaker{config, state, store, 0}
} }


+ 6
- 4
consensus/replay_file.go View File

@ -8,20 +8,22 @@ import (
"strconv" "strconv"
"strings" "strings"
. "github.com/tendermint/tmlibs/common"
"github.com/spf13/viper"
cfg "github.com/tendermint/go-config" cfg "github.com/tendermint/go-config"
dbm "github.com/tendermint/tmlibs/db"
bc "github.com/tendermint/tendermint/blockchain" bc "github.com/tendermint/tendermint/blockchain"
mempl "github.com/tendermint/tendermint/mempool" mempl "github.com/tendermint/tendermint/mempool"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
. "github.com/tendermint/tmlibs/common"
dbm "github.com/tendermint/tmlibs/db"
) )
//-------------------------------------------------------- //--------------------------------------------------------
// replay messages interactively or all at once // 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) consensusState := newConsensusStateForReplay(config)
if err := consensusState.ReplayFile(walFile, console); err != nil { if err := consensusState.ReplayFile(walFile, console); err != nil {
@ -236,7 +238,7 @@ func (pb *playback) replayConsoleLoop() int {
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// convenience for replay mode // convenience for replay mode
func newConsensusStateForReplay(config cfg.Config) *ConsensusState {
func newConsensusStateForReplay(config *viper.Viper) *ConsensusState {
// Get BlockStore // Get BlockStore
blockStoreDB := dbm.NewDB("blockstore", config.GetString("db_backend"), config.GetString("db_dir")) blockStoreDB := dbm.NewDB("blockstore", config.GetString("db_backend"), config.GetString("db_dir"))
blockStore := bc.NewBlockStore(blockStoreDB) blockStore := bc.NewBlockStore(blockStoreDB)


+ 8
- 7
consensus/replay_test.go View File

@ -12,17 +12,18 @@ import (
"testing" "testing"
"time" "time"
"github.com/tendermint/tendermint/config/tendermint_test"
"github.com/spf13/viper"
"github.com/tendermint/abci/example/dummy" "github.com/tendermint/abci/example/dummy"
cmn "github.com/tendermint/tmlibs/common"
cfg "github.com/tendermint/go-config" cfg "github.com/tendermint/go-config"
"github.com/tendermint/go-crypto" "github.com/tendermint/go-crypto"
dbm "github.com/tendermint/tmlibs/db"
"github.com/tendermint/go-wire" "github.com/tendermint/go-wire"
"github.com/tendermint/tendermint/config/tendermint_test"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common"
dbm "github.com/tendermint/tmlibs/db"
) )
func init() { 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 // 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"))) clientCreator := proxy.NewLocalClientCreator(dummy.NewPersistentDummyApplication(path.Join(config.GetString("db_dir"), "1")))
proxyApp := proxy.NewAppConns(config, clientCreator, nil) // sm.NewHandshaker(config, state, store, ReplayLastBlock)) 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 // 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() stateDB := dbm.NewMemDB()
return sm.MakeGenesisState(stateDB, &types.GenesisDoc{ return sm.MakeGenesisState(stateDB, &types.GenesisDoc{
ChainID: config.GetString("chain_id"), ChainID: config.GetString("chain_id"),
@ -617,13 +618,13 @@ func stateAndStore(config cfg.Config, pubKey crypto.PubKey) (*sm.State, *mockBlo
// mock block store // mock block store
type mockBlockStore struct { type mockBlockStore struct {
config cfg.Config
config *viper.Viper
chain []*types.Block chain []*types.Block
commits []*types.Commit commits []*types.Commit
} }
// TODO: NewBlockStore(db.NewMemDB) ... // TODO: NewBlockStore(db.NewMemDB) ...
func NewMockBlockStore(config cfg.Config) *mockBlockStore {
func NewMockBlockStore(config *viper.Viper) *mockBlockStore {
return &mockBlockStore{config, nil, nil} return &mockBlockStore{config, nil, nil}
} }


+ 5
- 4
consensus/state.go View File

@ -10,13 +10,14 @@ import (
"time" "time"
"github.com/ebuchman/fail-test" "github.com/ebuchman/fail-test"
"github.com/spf13/viper"
. "github.com/tendermint/tmlibs/common"
cfg "github.com/tendermint/go-config" cfg "github.com/tendermint/go-config"
"github.com/tendermint/go-wire" "github.com/tendermint/go-wire"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types" "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 // InitTimeoutParamsFromConfig initializes parameters from config
func InitTimeoutParamsFromConfig(config cfg.Config) *TimeoutParams {
func InitTimeoutParamsFromConfig(config *viper.Viper) *TimeoutParams {
return &TimeoutParams{ return &TimeoutParams{
Propose0: config.GetInt("timeout_propose"), Propose0: config.GetInt("timeout_propose"),
ProposeDelta: config.GetInt("timeout_propose_delta"), ProposeDelta: config.GetInt("timeout_propose_delta"),
@ -224,7 +225,7 @@ type PrivValidator interface {
type ConsensusState struct { type ConsensusState struct {
BaseService BaseService
config cfg.Config
config *viper.Viper
proxyAppConn proxy.AppConnConsensus proxyAppConn proxy.AppConnConsensus
blockStore types.BlockStore blockStore types.BlockStore
mempool types.Mempool mempool types.Mempool
@ -255,7 +256,7 @@ type ConsensusState struct {
done chan 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{ cs := &ConsensusState{
config: config, config: config,
proxyAppConn: proxyAppConn, proxyAppConn: proxyAppConn,


+ 3
- 1
glide.lock View File

@ -41,8 +41,10 @@ imports:
version: d8ed2627bdf02c080bf22230dbb337003b7aba2d version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
subpackages: subpackages:
- difflib - difflib
- name: github.com/spf13/viper
version: 84f94806c67f59dd7ae87bc5351f7a9c94a4558d
- name: github.com/spf13/cobra - name: github.com/spf13/cobra
version: fcd0c5a1df88f5d6784cb4feead962c3f3d0b66c
version: 5deb57bbca49eb370538fc295ba4b2988f9f5e09
- name: github.com/spf13/pflag - name: github.com/spf13/pflag
version: 9ff6c6923cfffbcd502984b8e0c80539a94968b7 version: 9ff6c6923cfffbcd502984b8e0c80539a94968b7
- name: github.com/stretchr/testify - name: github.com/stretchr/testify


+ 11
- 0
glide.yaml View File

@ -39,6 +39,17 @@ import:
- flowrate - flowrate
- logger - logger
- merkle - 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 - package: golang.org/x/crypto
subpackages: subpackages:
- nacl/box - nacl/box


+ 7
- 5
mempool/mempool.go View File

@ -7,13 +7,15 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/spf13/viper"
abci "github.com/tendermint/abci/types" 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" cfg "github.com/tendermint/go-config"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
"github.com/tendermint/tendermint/types" "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 const cacheSize = 100000
type Mempool struct { type Mempool struct {
config cfg.Config
config *viper.Viper
proxyMtx sync.Mutex proxyMtx sync.Mutex
proxyAppConn proxy.AppConnMempool proxyAppConn proxy.AppConnMempool
@ -66,7 +68,7 @@ type Mempool struct {
wal *auto.AutoFile wal *auto.AutoFile
} }
func NewMempool(config cfg.Config, proxyAppConn proxy.AppConnMempool) *Mempool {
func NewMempool(config *viper.Viper, proxyAppConn proxy.AppConnMempool) *Mempool {
mempool := &Mempool{ mempool := &Mempool{
config: config, config: config,
proxyAppConn: proxyAppConn, proxyAppConn: proxyAppConn,


+ 6
- 4
mempool/reactor.go View File

@ -6,12 +6,14 @@ import (
"reflect" "reflect"
"time" "time"
"github.com/spf13/viper"
abci "github.com/tendermint/abci/types" abci "github.com/tendermint/abci/types"
"github.com/tendermint/tmlibs/clist"
cfg "github.com/tendermint/go-config" cfg "github.com/tendermint/go-config"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/go-wire" "github.com/tendermint/go-wire"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
"github.com/tendermint/tmlibs/clist"
) )
const ( const (
@ -24,12 +26,12 @@ const (
// MempoolReactor handles mempool tx broadcasting amongst peers. // MempoolReactor handles mempool tx broadcasting amongst peers.
type MempoolReactor struct { type MempoolReactor struct {
p2p.BaseReactor p2p.BaseReactor
config cfg.Config
config *viper.Viper
Mempool *Mempool Mempool *Mempool
evsw types.EventSwitch evsw types.EventSwitch
} }
func NewMempoolReactor(config cfg.Config, mempool *Mempool) *MempoolReactor {
func NewMempoolReactor(config *viper.Viper, mempool *Mempool) *MempoolReactor {
memR := &MempoolReactor{ memR := &MempoolReactor{
config: config, config: config,
Mempool: mempool, Mempool: mempool,


+ 15
- 9
node/node.go View File

@ -7,19 +7,19 @@ import (
"net/http" "net/http"
"strings" "strings"
"github.com/spf13/viper"
abci "github.com/tendermint/abci/types" abci "github.com/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common"
cfg "github.com/tendermint/go-config" cfg "github.com/tendermint/go-config"
crypto "github.com/tendermint/go-crypto" 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" wire "github.com/tendermint/go-wire"
bc "github.com/tendermint/tendermint/blockchain" bc "github.com/tendermint/tendermint/blockchain"
"github.com/tendermint/tendermint/consensus" "github.com/tendermint/tendermint/consensus"
mempl "github.com/tendermint/tendermint/mempool" mempl "github.com/tendermint/tendermint/mempool"
p2p "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/proxy" "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" rpccore "github.com/tendermint/tendermint/rpc/tendermint/core"
grpccore "github.com/tendermint/tendermint/rpc/tendermint/grpc" grpccore "github.com/tendermint/tendermint/rpc/tendermint/grpc"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
@ -28,6 +28,8 @@ import (
"github.com/tendermint/tendermint/state/txindex/null" "github.com/tendermint/tendermint/state/txindex/null"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
"github.com/tendermint/tendermint/version" "github.com/tendermint/tendermint/version"
cmn "github.com/tendermint/tmlibs/common"
dbm "github.com/tendermint/tmlibs/db"
_ "net/http/pprof" _ "net/http/pprof"
) )
@ -36,7 +38,7 @@ type Node struct {
cmn.BaseService cmn.BaseService
// config // config
config cfg.Config // user config
config *viper.Viper // user config
genesisDoc *types.GenesisDoc // initial validator set genesisDoc *types.GenesisDoc // initial validator set
privValidator *types.PrivValidator // local node's validator key privValidator *types.PrivValidator // local node's validator key
@ -57,14 +59,14 @@ type Node struct {
txIndexer txindex.TxIndexer txIndexer txindex.TxIndexer
} }
func NewNodeDefault(config cfg.Config) *Node {
func NewNodeDefault(config *viper.Viper) *Node {
// Get PrivValidator // Get PrivValidator
privValidatorFile := config.GetString("priv_validator_file") privValidatorFile := config.GetString("priv_validator_file")
privValidator := types.LoadOrGenPrivValidator(privValidatorFile) privValidator := types.LoadOrGenPrivValidator(privValidatorFile)
return NewNode(config, privValidator, proxy.DefaultClientCreator(config)) 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 // Get BlockStore
blockStoreDB := dbm.NewDB("blockstore", config.GetString("db_backend"), config.GetString("db_dir")) 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) consensusReactor := consensus.NewConsensusReactor(consensusState, fastSync)
// Make p2p network switch // 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("MEMPOOL", mempoolReactor)
sw.AddReactor("BLOCKCHAIN", bcReactor) sw.AddReactor("BLOCKCHAIN", bcReactor)
sw.AddReactor("CONSENSUS", consensusReactor) sw.AddReactor("CONSENSUS", consensusReactor)


+ 3
- 2
proxy/client.go View File

@ -4,10 +4,11 @@ import (
"fmt" "fmt"
"sync" "sync"
"github.com/spf13/viper"
abcicli "github.com/tendermint/abci/client" abcicli "github.com/tendermint/abci/client"
"github.com/tendermint/abci/example/dummy" "github.com/tendermint/abci/example/dummy"
"github.com/tendermint/abci/types" "github.com/tendermint/abci/types"
cfg "github.com/tendermint/go-config"
) )
// NewABCIClient returns newly connected client // NewABCIClient returns newly connected client
@ -63,7 +64,7 @@ func (r *remoteClientCreator) NewABCIClient() (abcicli.Client, error) {
//----------------------------------------------------------------- //-----------------------------------------------------------------
// default // default
func DefaultClientCreator(config cfg.Config) ClientCreator {
func DefaultClientCreator(config *viper.Viper) ClientCreator {
addr := config.GetString("proxy_app") addr := config.GetString("proxy_app")
transport := config.GetString("abci") transport := config.GetString("abci")


+ 5
- 4
proxy/multi_app_conn.go View File

@ -1,8 +1,9 @@
package proxy package proxy
import ( import (
cmn "github.com/tendermint/tmlibs/common"
"github.com/spf13/viper"
cfg "github.com/tendermint/go-config" cfg "github.com/tendermint/go-config"
cmn "github.com/tendermint/tmlibs/common"
) )
//----------------------------- //-----------------------------
@ -16,7 +17,7 @@ type AppConns interface {
Query() AppConnQuery 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) return NewMultiAppConn(config, clientCreator, handshaker)
} }
@ -34,7 +35,7 @@ type Handshaker interface {
type multiAppConn struct { type multiAppConn struct {
cmn.BaseService cmn.BaseService
config cfg.Config
config *viper.Viper
handshaker Handshaker handshaker Handshaker
@ -46,7 +47,7 @@ type multiAppConn struct {
} }
// Make all necessary abci connections to the application // 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{ multiAppConn := &multiAppConn{
config: config, config: config,
handshaker: handshaker, handshaker: handshaker,


+ 4
- 3
rpc/tendermint/core/pipe.go View File

@ -1,11 +1,12 @@
package core package core
import ( import (
"github.com/spf13/viper"
cfg "github.com/tendermint/go-config" cfg "github.com/tendermint/go-config"
crypto "github.com/tendermint/go-crypto" crypto "github.com/tendermint/go-crypto"
p2p "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/consensus" "github.com/tendermint/tendermint/consensus"
p2p "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
"github.com/tendermint/tendermint/state/txindex" "github.com/tendermint/tendermint/state/txindex"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
@ -34,7 +35,7 @@ var (
// external, thread safe interfaces // external, thread safe interfaces
eventSwitch types.EventSwitch eventSwitch types.EventSwitch
proxyAppQuery proxy.AppConnQuery proxyAppQuery proxy.AppConnQuery
config cfg.Config
config *viper.Viper
// interfaces defined in types and above // interfaces defined in types and above
blockStore types.BlockStore blockStore types.BlockStore
@ -49,7 +50,7 @@ var (
txIndexer txindex.TxIndexer txIndexer txindex.TxIndexer
) )
func SetConfig(c cfg.Config) {
func SetConfig(c *viper.Viper) {
config = c config = c
} }


+ 5
- 4
rpc/tendermint/test/helpers.go View File

@ -9,23 +9,24 @@ import (
"testing" "testing"
"time" "time"
"github.com/spf13/viper"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
logger "github.com/tendermint/tmlibs/logger"
wire "github.com/tendermint/go-wire" wire "github.com/tendermint/go-wire"
logger "github.com/tendermint/tmlibs/logger"
abci "github.com/tendermint/abci/types" abci "github.com/tendermint/abci/types"
cfg "github.com/tendermint/go-config" cfg "github.com/tendermint/go-config"
client "github.com/tendermint/tendermint/rpc/client"
"github.com/tendermint/tendermint/config/tendermint_test" "github.com/tendermint/tendermint/config/tendermint_test"
nm "github.com/tendermint/tendermint/node" nm "github.com/tendermint/tendermint/node"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
client "github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/tendermint/core/types" ctypes "github.com/tendermint/tendermint/rpc/tendermint/core/types"
core_grpc "github.com/tendermint/tendermint/rpc/tendermint/grpc" core_grpc "github.com/tendermint/tendermint/rpc/tendermint/grpc"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )
var ( var (
config cfg.Config
config *viper.Viper
) )
const tmLogLevel = "error" const tmLogLevel = "error"
@ -56,7 +57,7 @@ func makeAddrs() (string, string, string) {
} }
// GetConfig returns a config for the test cases as a singleton // GetConfig returns a config for the test cases as a singleton
func GetConfig() cfg.Config {
func GetConfig() *viper.Viper {
if config == nil { if config == nil {
pathname := makePathname() pathname := makePathname()
config = tendermint_test.ResetConfig(pathname) config = tendermint_test.ResetConfig(pathname)


+ 4
- 2
state/state.go View File

@ -6,10 +6,12 @@ import (
"sync" "sync"
"time" "time"
"github.com/spf13/viper"
abci "github.com/tendermint/abci/types" abci "github.com/tendermint/abci/types"
. "github.com/tendermint/tmlibs/common"
cfg "github.com/tendermint/go-config" cfg "github.com/tendermint/go-config"
. "github.com/tendermint/tmlibs/common"
dbm "github.com/tendermint/tmlibs/db" dbm "github.com/tendermint/tmlibs/db"
"github.com/tendermint/go-wire" "github.com/tendermint/go-wire"
"github.com/tendermint/tendermint/state/txindex" "github.com/tendermint/tendermint/state/txindex"
"github.com/tendermint/tendermint/state/txindex/null" "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, // Load the most recent state from "state" db,
// or create a new one (and save) from genesis. // 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) state := LoadState(stateDB)
if state == nil { if state == nil {
state = MakeGenesisStateFromFile(stateDB, config.GetString("genesis_file")) state = MakeGenesisStateFromFile(stateDB, config.GetString("genesis_file"))


Loading…
Cancel
Save