Browse Source

remove some more viper

pull/484/head
Ethan Buchman 8 years ago
parent
commit
95c74b2ccd
4 changed files with 18 additions and 24 deletions
  1. +12
    -15
      cmd/tendermint/commands/reset_priv_validator.go
  2. +4
    -7
      consensus/replay.go
  3. +1
    -1
      consensus/replay_file.go
  4. +1
    -1
      node/node.go

+ 12
- 15
cmd/tendermint/commands/reset_priv_validator.go View File

@ -4,7 +4,6 @@ import (
"os"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/log15"
"github.com/tendermint/tendermint/types"
@ -30,36 +29,34 @@ func init() {
// XXX: this is totally unsafe.
// it's only suitable for testnets.
func resetAll(cmd *cobra.Command, args []string) {
ResetAll(config, log)
ResetAll(config.GetString("db_dir"), config.GetString("priv_validator_file"), log)
}
// XXX: this is totally unsafe.
// it's only suitable for testnets.
func resetPrivValidator(cmd *cobra.Command, args []string) {
resetPrivValidatorLocal(config, log)
resetPrivValidatorLocal(config.GetString("priv_validator_file"), log)
}
// Exported so other CLI tools can use it
func ResetAll(c *viper.Viper, l log15.Logger) {
resetPrivValidatorLocal(c, l)
dataDir := c.GetString("db_dir")
os.RemoveAll(dataDir)
l.Notice("Removed all data", "dir", dataDir)
func ResetAll(dbDir, privValFile string, l log15.Logger) {
resetPrivValidatorLocal(privValFile, l)
os.RemoveAll(dbDir)
l.Notice("Removed all data", "dir", dbDir)
}
func resetPrivValidatorLocal(c *viper.Viper, l log15.Logger) {
func resetPrivValidatorLocal(privValFile string, l log15.Logger) {
// Get PrivValidator
var privValidator *types.PrivValidator
privValidatorFile := c.GetString("priv_validator_file")
if _, err := os.Stat(privValidatorFile); err == nil {
privValidator = types.LoadPrivValidator(privValidatorFile)
if _, err := os.Stat(privValFile); err == nil {
privValidator = types.LoadPrivValidator(privValFile)
privValidator.Reset()
l.Notice("Reset PrivValidator", "file", privValidatorFile)
l.Notice("Reset PrivValidator", "file", privValFile)
} else {
privValidator = types.GenPrivValidator()
privValidator.SetFile(privValidatorFile)
privValidator.SetFile(privValFile)
privValidator.Save()
l.Notice("Generated PrivValidator", "file", privValidatorFile)
l.Notice("Generated PrivValidator", "file", privValFile)
}
}

+ 4
- 7
consensus/replay.go View File

@ -10,8 +10,6 @@ import (
"strings"
"time"
"github.com/spf13/viper"
abci "github.com/tendermint/abci/types"
"github.com/tendermint/go-wire"
auto "github.com/tendermint/tmlibs/autofile"
@ -200,15 +198,14 @@ func makeHeightSearchFunc(height int) auto.SearchFunc {
// we were last and using the WAL to recover there
type Handshaker struct {
config *viper.Viper
state *sm.State
store types.BlockStore
state *sm.State
store types.BlockStore
nBlocks int // number of blocks applied to the state
}
func NewHandshaker(config *viper.Viper, state *sm.State, store types.BlockStore) *Handshaker {
return &Handshaker{config, state, store, 0}
func NewHandshaker(state *sm.State, store types.BlockStore) *Handshaker {
return &Handshaker{state, store, 0}
}
func (h *Handshaker) NBlocks() int {


+ 1
- 1
consensus/replay_file.go View File

@ -247,7 +247,7 @@ func newConsensusStateForReplay(config *viper.Viper) *ConsensusState {
// Create proxyAppConn connection (consensus, mempool, query)
clientCreator := proxy.DefaultClientCreator(config.GetString("proxy_app"), config.GetString("abci"), config.GetString("db_dir"))
proxyApp := proxy.NewAppConns(clientCreator, NewHandshaker(config, state, blockStore))
proxyApp := proxy.NewAppConns(clientCreator, NewHandshaker(state, blockStore))
_, err := proxyApp.Start()
if err != nil {
cmn.Exit(cmn.Fmt("Error starting proxy app conns: %v", err))


+ 1
- 1
node/node.go View File

@ -85,7 +85,7 @@ func NewNode(config *viper.Viper, privValidator *types.PrivValidator, clientCrea
// Create the proxyApp, which manages connections (consensus, mempool, query)
// and sync tendermint and the app by replaying any necessary blocks
proxyApp := proxy.NewAppConns(clientCreator, consensus.NewHandshaker(config, state, blockStore))
proxyApp := proxy.NewAppConns(clientCreator, consensus.NewHandshaker(state, blockStore))
if _, err := proxyApp.Start(); err != nil {
cmn.Exit(cmn.Fmt("Error starting proxy app connections: %v", err))
}


Loading…
Cancel
Save