mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-29 06:01:21 +00:00
Merge pull request #442 from tendermint/viper
go-config -> viper, commands: Run -> RunE
This commit is contained in:
commit
0e5cd6dc2f
@ -6,13 +6,14 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"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/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 +44,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 +58,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
|
||||||
}
|
}
|
||||||
|
@ -12,14 +12,14 @@ import (
|
|||||||
var probeUpnpCmd = &cobra.Command{
|
var probeUpnpCmd = &cobra.Command{
|
||||||
Use: "probe_upnp",
|
Use: "probe_upnp",
|
||||||
Short: "Test UPnP functionality",
|
Short: "Test UPnP functionality",
|
||||||
Run: probeUpnp,
|
RunE: probeUpnp,
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RootCmd.AddCommand(probeUpnpCmd)
|
RootCmd.AddCommand(probeUpnpCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func probeUpnp(cmd *cobra.Command, args []string) {
|
func probeUpnp(cmd *cobra.Command, args []string) error {
|
||||||
|
|
||||||
capabilities, err := upnp.Probe()
|
capabilities, err := upnp.Probe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -28,9 +28,9 @@ func probeUpnp(cmd *cobra.Command, args []string) {
|
|||||||
fmt.Println("Probe success!")
|
fmt.Println("Probe success!")
|
||||||
jsonBytes, err := json.Marshal(capabilities)
|
jsonBytes, err := json.Marshal(capabilities)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println(string(jsonBytes))
|
fmt.Println(string(jsonBytes))
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
"github.com/tendermint/log15"
|
"github.com/tendermint/log15"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
@ -36,27 +36,30 @@ func resetAll(cmd *cobra.Command, args []string) {
|
|||||||
// XXX: this is totally unsafe.
|
// XXX: this is totally unsafe.
|
||||||
// it's only suitable for testnets.
|
// it's only suitable for testnets.
|
||||||
func resetPrivValidator(cmd *cobra.Command, args []string) {
|
func resetPrivValidator(cmd *cobra.Command, args []string) {
|
||||||
ResetPrivValidator(config, log)
|
resetPrivValidatorLocal(config, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exported so other CLI tools can use it
|
// 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)
|
resetPrivValidatorLocal(c, l)
|
||||||
os.RemoveAll(c.GetString("db_dir"))
|
dataDir := c.GetString("db_dir")
|
||||||
|
os.RemoveAll(dataDir)
|
||||||
|
l.Notice("Removed all data", "dir", dataDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResetPrivValidator(c cfg.Config, l log15.Logger) {
|
func resetPrivValidatorLocal(c *viper.Viper, l log15.Logger) {
|
||||||
|
|
||||||
// Get PrivValidator
|
// Get PrivValidator
|
||||||
var privValidator *types.PrivValidator
|
var privValidator *types.PrivValidator
|
||||||
privValidatorFile := config.GetString("priv_validator_file")
|
privValidatorFile := c.GetString("priv_validator_file")
|
||||||
if _, err := os.Stat(privValidatorFile); err == nil {
|
if _, err := os.Stat(privValidatorFile); err == nil {
|
||||||
privValidator = types.LoadPrivValidator(privValidatorFile)
|
privValidator = types.LoadPrivValidator(privValidatorFile)
|
||||||
privValidator.Reset()
|
privValidator.Reset()
|
||||||
log.Notice("Reset PrivValidator", "file", privValidatorFile)
|
l.Notice("Reset PrivValidator", "file", privValidatorFile)
|
||||||
} else {
|
} else {
|
||||||
privValidator = types.GenPrivValidator()
|
privValidator = types.GenPrivValidator()
|
||||||
privValidator.SetFile(privValidatorFile)
|
privValidator.SetFile(privValidatorFile)
|
||||||
privValidator.Save()
|
privValidator.Save()
|
||||||
log.Notice("Generated PrivValidator", "file", privValidatorFile)
|
l.Notice("Generated PrivValidator", "file", privValidatorFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@ package commands
|
|||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"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 (
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
. "github.com/tendermint/tmlibs/common"
|
|
||||||
"github.com/tendermint/tendermint/node"
|
"github.com/tendermint/tendermint/node"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
var runNodeCmd = &cobra.Command{
|
var runNodeCmd = &cobra.Command{
|
||||||
Use: "node",
|
Use: "node",
|
||||||
Short: "Run the tendermint node",
|
Short: "Run the tendermint node",
|
||||||
PreRun: setConfigFlags,
|
PreRun: setConfigFlags,
|
||||||
Run: runNode,
|
RunE: runNode,
|
||||||
}
|
}
|
||||||
|
|
||||||
//flags
|
//flags
|
||||||
@ -82,30 +83,30 @@ func setConfigFlags(cmd *cobra.Command, args []string) {
|
|||||||
// should import github.com/tendermint/tendermint/node and implement
|
// should import github.com/tendermint/tendermint/node and implement
|
||||||
// their own run_node to call node.NewNode (instead of node.NewNodeDefault)
|
// their own run_node to call node.NewNode (instead of node.NewNodeDefault)
|
||||||
// with their custom priv validator and/or custom proxy.ClientCreator
|
// 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
|
// Wait until the genesis doc becomes available
|
||||||
// This is for Mintnet compatibility.
|
// This is for Mintnet compatibility.
|
||||||
// TODO: If Mintnet gets deprecated or genesis_file is
|
// TODO: If Mintnet gets deprecated or genesis_file is
|
||||||
// always available, remove.
|
// always available, remove.
|
||||||
genDocFile := config.GetString("genesis_file")
|
genDocFile := config.GetString("genesis_file")
|
||||||
if !FileExists(genDocFile) {
|
if !cmn.FileExists(genDocFile) {
|
||||||
log.Notice(Fmt("Waiting for genesis file %v...", genDocFile))
|
log.Notice(cmn.Fmt("Waiting for genesis file %v...", genDocFile))
|
||||||
for {
|
for {
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
if !FileExists(genDocFile) {
|
if !cmn.FileExists(genDocFile) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
jsonBlob, err := ioutil.ReadFile(genDocFile)
|
jsonBlob, err := ioutil.ReadFile(genDocFile)
|
||||||
if err != nil {
|
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)
|
genDoc, err := types.GenesisDocFromJSON(jsonBlob)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(Fmt("Error reading GenesisDoc: %v", err))
|
return fmt.Errorf("Error reading GenesisDoc: %v", err)
|
||||||
}
|
}
|
||||||
if genDoc.ChainID == "" {
|
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)
|
config.Set("chain_id", genDoc.ChainID)
|
||||||
}
|
}
|
||||||
@ -114,11 +115,13 @@ func runNode(cmd *cobra.Command, args []string) {
|
|||||||
// Create & start node
|
// Create & start node
|
||||||
n := node.NewNodeDefault(config)
|
n := node.NewNodeDefault(config)
|
||||||
if _, err := n.Start(); err != nil {
|
if _, err := n.Start(); err != nil {
|
||||||
Exit(Fmt("Failed to start node: %v", err))
|
return fmt.Errorf("Failed to start node: %v", err)
|
||||||
} else {
|
} else {
|
||||||
log.Notice("Started node", "nodeInfo", n.Switch().NodeInfo())
|
log.Notice("Started node", "nodeInfo", n.Switch().NodeInfo())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trap signal, run forever.
|
// Trap signal, run forever.
|
||||||
n.RunForever()
|
n.RunForever()
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
. "github.com/tendermint/tmlibs/common"
|
"github.com/spf13/viper"
|
||||||
cfg "github.com/tendermint/go-config"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getTMRoot(rootDir string) string {
|
func getTMRoot(rootDir string) string {
|
||||||
@ -25,85 +25,89 @@ func getTMRoot(rootDir string) string {
|
|||||||
|
|
||||||
func initTMRoot(rootDir string) {
|
func initTMRoot(rootDir string) {
|
||||||
rootDir = getTMRoot(rootDir)
|
rootDir = getTMRoot(rootDir)
|
||||||
EnsureDir(rootDir, 0700)
|
cmn.EnsureDir(rootDir, 0700)
|
||||||
EnsureDir(rootDir+"/data", 0700)
|
cmn.EnsureDir(rootDir+"/data", 0700)
|
||||||
|
|
||||||
configFilePath := path.Join(rootDir, "config.toml")
|
configFilePath := path.Join(rootDir, "config.toml")
|
||||||
|
|
||||||
// Write default config file if missing.
|
// Write default config file if missing.
|
||||||
if !FileExists(configFilePath) {
|
if !cmn.FileExists(configFilePath) {
|
||||||
// Ask user for moniker
|
// Ask user for moniker
|
||||||
// moniker := cfg.Prompt("Type hostname: ", "anonymous")
|
// moniker := cfg.Prompt("Type hostname: ", "anonymous")
|
||||||
MustWriteFile(configFilePath, []byte(defaultConfig("anonymous")), 0644)
|
cmn.MustWriteFile(configFilePath, []byte(defaultConfig("anonymous")), 0644)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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")
|
config := viper.New()
|
||||||
mapConfig, err := cfg.ReadMapConfigFromFile(configFilePath)
|
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))
|
cmn.Exit(cmn.Fmt("Could not read config from directory %v: %v", rootDir, 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")
|
cmn.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")
|
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.
|
//mapConfig.SetRequired("chain_id") // blows up if you try to use it before setting.
|
||||||
mapConfig.SetDefault("genesis_file", rootDir+"/genesis.json")
|
config.SetDefault("genesis_file", rootDir+"/genesis.json")
|
||||||
mapConfig.SetDefault("proxy_app", "tcp://127.0.0.1:46658")
|
config.SetDefault("proxy_app", "tcp://127.0.0.1:46658")
|
||||||
mapConfig.SetDefault("abci", "socket")
|
config.SetDefault("abci", "socket")
|
||||||
mapConfig.SetDefault("moniker", "anonymous")
|
config.SetDefault("moniker", "anonymous")
|
||||||
mapConfig.SetDefault("node_laddr", "tcp://0.0.0.0:46656")
|
config.SetDefault("node_laddr", "tcp://0.0.0.0:46656")
|
||||||
mapConfig.SetDefault("seeds", "")
|
config.SetDefault("seeds", "")
|
||||||
// mapConfig.SetDefault("seeds", "goldenalchemist.chaintest.net:46656")
|
// config.SetDefault("seeds", "goldenalchemist.chaintest.net:46656")
|
||||||
mapConfig.SetDefault("fast_sync", true)
|
config.SetDefault("fast_sync", true)
|
||||||
mapConfig.SetDefault("skip_upnp", false)
|
config.SetDefault("skip_upnp", false)
|
||||||
mapConfig.SetDefault("addrbook_file", rootDir+"/addrbook.json")
|
config.SetDefault("addrbook_file", rootDir+"/addrbook.json")
|
||||||
mapConfig.SetDefault("addrbook_strict", true) // disable to allow connections locally
|
config.SetDefault("addrbook_strict", true) // disable to allow connections locally
|
||||||
mapConfig.SetDefault("pex_reactor", false) // enable for peer exchange
|
config.SetDefault("pex_reactor", false) // enable for peer exchange
|
||||||
mapConfig.SetDefault("priv_validator_file", rootDir+"/priv_validator.json")
|
config.SetDefault("priv_validator_file", rootDir+"/priv_validator.json")
|
||||||
mapConfig.SetDefault("db_backend", "leveldb")
|
config.SetDefault("db_backend", "leveldb")
|
||||||
mapConfig.SetDefault("db_dir", rootDir+"/data")
|
config.SetDefault("db_dir", rootDir+"/data")
|
||||||
mapConfig.SetDefault("log_level", "info")
|
config.SetDefault("log_level", "info")
|
||||||
mapConfig.SetDefault("rpc_laddr", "tcp://0.0.0.0:46657")
|
config.SetDefault("rpc_laddr", "tcp://0.0.0.0:46657")
|
||||||
mapConfig.SetDefault("grpc_laddr", "")
|
config.SetDefault("grpc_laddr", "")
|
||||||
mapConfig.SetDefault("prof_laddr", "")
|
config.SetDefault("prof_laddr", "")
|
||||||
mapConfig.SetDefault("revision_file", rootDir+"/revision")
|
config.SetDefault("revision_file", rootDir+"/revision")
|
||||||
mapConfig.SetDefault("cs_wal_file", rootDir+"/data/cs.wal/wal")
|
config.SetDefault("cs_wal_file", rootDir+"/data/cs.wal/wal")
|
||||||
mapConfig.SetDefault("cs_wal_light", false)
|
config.SetDefault("cs_wal_light", false)
|
||||||
mapConfig.SetDefault("filter_peers", false)
|
config.SetDefault("filter_peers", false)
|
||||||
|
|
||||||
mapConfig.SetDefault("block_size", 10000) // max number of txs
|
config.SetDefault("block_size", 10000) // max number of txs
|
||||||
mapConfig.SetDefault("block_part_size", 65536) // part size 64K
|
config.SetDefault("block_part_size", 65536) // part size 64K
|
||||||
mapConfig.SetDefault("disable_data_hash", false)
|
config.SetDefault("disable_data_hash", false)
|
||||||
|
|
||||||
// all timeouts are in ms
|
// all timeouts are in ms
|
||||||
mapConfig.SetDefault("timeout_handshake", 10000)
|
config.SetDefault("timeout_handshake", 10000)
|
||||||
mapConfig.SetDefault("timeout_propose", 3000)
|
config.SetDefault("timeout_propose", 3000)
|
||||||
mapConfig.SetDefault("timeout_propose_delta", 500)
|
config.SetDefault("timeout_propose_delta", 500)
|
||||||
mapConfig.SetDefault("timeout_prevote", 1000)
|
config.SetDefault("timeout_prevote", 1000)
|
||||||
mapConfig.SetDefault("timeout_prevote_delta", 500)
|
config.SetDefault("timeout_prevote_delta", 500)
|
||||||
mapConfig.SetDefault("timeout_precommit", 1000)
|
config.SetDefault("timeout_precommit", 1000)
|
||||||
mapConfig.SetDefault("timeout_precommit_delta", 500)
|
config.SetDefault("timeout_precommit_delta", 500)
|
||||||
mapConfig.SetDefault("timeout_commit", 1000)
|
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)
|
config.SetDefault("skip_timeout_commit", false)
|
||||||
mapConfig.SetDefault("mempool_recheck", true)
|
config.SetDefault("mempool_recheck", true)
|
||||||
mapConfig.SetDefault("mempool_recheck_empty", true)
|
config.SetDefault("mempool_recheck_empty", true)
|
||||||
mapConfig.SetDefault("mempool_broadcast", true)
|
config.SetDefault("mempool_broadcast", true)
|
||||||
mapConfig.SetDefault("mempool_wal_dir", rootDir+"/data/mempool.wal")
|
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.
|
||||||
|
@ -3,12 +3,14 @@
|
|||||||
package tendermint_test
|
package tendermint_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
. "github.com/tendermint/tmlibs/common"
|
. "github.com/tendermint/tmlibs/common"
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
"github.com/tendermint/tmlibs/logger"
|
"github.com/tendermint/tmlibs/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,7 +45,6 @@ func initTMRoot(rootDir string) {
|
|||||||
// Write default config file if missing.
|
// Write default config file if missing.
|
||||||
if !FileExists(configFilePath) {
|
if !FileExists(configFilePath) {
|
||||||
// Ask user for moniker
|
// Ask user for moniker
|
||||||
// moniker := cfg.Prompt("Type hostname: ", "anonymous")
|
|
||||||
MustWriteFile(configFilePath, []byte(defaultConfig("anonymous")), 0644)
|
MustWriteFile(configFilePath, []byte(defaultConfig("anonymous")), 0644)
|
||||||
}
|
}
|
||||||
if !FileExists(genesisFilePath) {
|
if !FileExists(genesisFilePath) {
|
||||||
@ -53,65 +54,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")
|
config := viper.New()
|
||||||
mapConfig, err := cfg.ReadMapConfigFromFile(configFilePath)
|
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") {
|
if config.IsSet("chain_id") {
|
||||||
Exit("Cannot set 'chain_id' via config.toml")
|
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)
|
config.SetDefault("chain_id", "tendermint_test")
|
||||||
mapConfig.SetDefault("block_part_size", 65536) // part size 64K
|
config.SetDefault("genesis_file", rootDir+"/genesis.json")
|
||||||
mapConfig.SetDefault("disable_data_hash", false)
|
config.SetDefault("proxy_app", "dummy")
|
||||||
mapConfig.SetDefault("timeout_handshake", 10000)
|
config.SetDefault("abci", "socket")
|
||||||
mapConfig.SetDefault("timeout_propose", 2000)
|
config.SetDefault("moniker", "anonymous")
|
||||||
mapConfig.SetDefault("timeout_propose_delta", 1)
|
config.SetDefault("node_laddr", "tcp://0.0.0.0:36656")
|
||||||
mapConfig.SetDefault("timeout_prevote", 10)
|
config.SetDefault("fast_sync", false)
|
||||||
mapConfig.SetDefault("timeout_prevote_delta", 1)
|
config.SetDefault("skip_upnp", true)
|
||||||
mapConfig.SetDefault("timeout_precommit", 10)
|
config.SetDefault("addrbook_file", rootDir+"/addrbook.json")
|
||||||
mapConfig.SetDefault("timeout_precommit_delta", 1)
|
config.SetDefault("addrbook_strict", true) // disable to allow connections locally
|
||||||
mapConfig.SetDefault("timeout_commit", 10)
|
config.SetDefault("pex_reactor", false) // enable for peer exchange
|
||||||
mapConfig.SetDefault("skip_timeout_commit", true)
|
config.SetDefault("priv_validator_file", rootDir+"/priv_validator.json")
|
||||||
mapConfig.SetDefault("mempool_recheck", true)
|
config.SetDefault("db_backend", "memdb")
|
||||||
mapConfig.SetDefault("mempool_recheck_empty", true)
|
config.SetDefault("db_dir", rootDir+"/data")
|
||||||
mapConfig.SetDefault("mempool_broadcast", true)
|
config.SetDefault("log_level", "info")
|
||||||
mapConfig.SetDefault("mempool_wal_dir", "")
|
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)
|
||||||
|
|
||||||
mapConfig.SetDefault("tx_index", "kv")
|
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", "")
|
||||||
|
|
||||||
logger.SetLogLevel(mapConfig.GetString("log_level"))
|
config.SetDefault("tx_index", "kv")
|
||||||
|
|
||||||
return mapConfig
|
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,13 +5,13 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/config/tendermint_test"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
. "github.com/tendermint/tmlibs/common"
|
"github.com/tendermint/tendermint/config/tendermint_test"
|
||||||
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 +36,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)
|
||||||
|
@ -11,23 +11,24 @@ 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"
|
|
||||||
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 +234,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 +257,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)
|
||||||
|
@ -10,11 +10,12 @@ 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"
|
|
||||||
"github.com/tendermint/go-wire"
|
"github.com/tendermint/go-wire"
|
||||||
|
auto "github.com/tendermint/tmlibs/autofile"
|
||||||
|
cmn "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"
|
||||||
@ -108,7 +109,7 @@ func (cs *ConsensusState) catchupReplay(csHeight int) error {
|
|||||||
gr.Close()
|
gr.Close()
|
||||||
}
|
}
|
||||||
if found {
|
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
|
// Search for last height marker
|
||||||
@ -143,7 +144,7 @@ func (cs *ConsensusState) catchupReplay(csHeight int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO (0.10.0): uncomment
|
// 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)
|
log.Notice("Catchup by replaying consensus messages", "height", csHeight)
|
||||||
@ -199,14 +200,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}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +222,7 @@ func (h *Handshaker) Handshake(proxyApp proxy.AppConns) error {
|
|||||||
// handshake is done via info request on the query conn
|
// handshake is done via info request on the query conn
|
||||||
res, err := proxyApp.Query().InfoSync()
|
res, err := proxyApp.Query().InfoSync()
|
||||||
if err != nil {
|
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
|
blockHeight := int(res.LastBlockHeight) // XXX: beware overflow
|
||||||
@ -238,7 +239,7 @@ func (h *Handshaker) Handshake(proxyApp proxy.AppConns) error {
|
|||||||
return nil
|
return nil
|
||||||
|
|
||||||
} else if err != 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)
|
log.Notice("Completed ABCI Handshake - Tendermint and App are synced", "appHeight", blockHeight, "appHash", appHash)
|
||||||
@ -266,11 +267,11 @@ func (h *Handshaker) ReplayBlocks(appHash []byte, appBlockHeight int, proxyApp p
|
|||||||
|
|
||||||
} else if storeBlockHeight < stateBlockHeight {
|
} else if storeBlockHeight < stateBlockHeight {
|
||||||
// the state should never be ahead of the store (this is under tendermint's control)
|
// 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 {
|
} else if storeBlockHeight > stateBlockHeight+1 {
|
||||||
// store should be at most one ahead of the state (this is under tendermint's control)
|
// 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.
|
// Now either store is equal to state, or one ahead.
|
||||||
@ -313,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
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,7 +369,7 @@ func (h *Handshaker) replayBlock(height int, proxyApp proxy.AppConnConsensus) ([
|
|||||||
|
|
||||||
func (h *Handshaker) checkAppHash(appHash []byte) error {
|
func (h *Handshaker) checkAppHash(appHash []byte) error {
|
||||||
if !bytes.Equal(h.state.AppHash, appHash) {
|
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
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -8,24 +8,25 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"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"
|
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"
|
||||||
|
cmn "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 {
|
||||||
Exit(Fmt("Error during consensus replay: %v", err))
|
cmn.Exit(cmn.Fmt("Error during consensus replay: %v", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +115,7 @@ func (pb *playback) replayReset(count int, newStepCh chan interface{}) error {
|
|||||||
pb.fp = fp
|
pb.fp = fp
|
||||||
pb.scanner = bufio.NewScanner(fp)
|
pb.scanner = bufio.NewScanner(fp)
|
||||||
count = pb.count - count
|
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.count = 0
|
||||||
pb.cs = newCS
|
pb.cs = newCS
|
||||||
for i := 0; pb.scanner.Scan() && i < count; i++ {
|
for i := 0; pb.scanner.Scan() && i < count; i++ {
|
||||||
@ -149,9 +150,9 @@ func (pb *playback) replayConsoleLoop() int {
|
|||||||
bufReader := bufio.NewReader(os.Stdin)
|
bufReader := bufio.NewReader(os.Stdin)
|
||||||
line, more, err := bufReader.ReadLine()
|
line, more, err := bufReader.ReadLine()
|
||||||
if more {
|
if more {
|
||||||
Exit("input is too long")
|
cmn.Exit("input is too long")
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
Exit(err.Error())
|
cmn.Exit(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
tokens := strings.Split(string(line), " ")
|
tokens := strings.Split(string(line), " ")
|
||||||
@ -236,7 +237,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)
|
||||||
@ -249,7 +250,7 @@ func newConsensusStateForReplay(config cfg.Config) *ConsensusState {
|
|||||||
proxyApp := proxy.NewAppConns(config, proxy.DefaultClientCreator(config), NewHandshaker(config, state, blockStore))
|
proxyApp := proxy.NewAppConns(config, proxy.DefaultClientCreator(config), NewHandshaker(config, state, blockStore))
|
||||||
_, err := proxyApp.Start()
|
_, err := proxyApp.Start()
|
||||||
if err != nil {
|
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
|
// add the chainid to the global config
|
||||||
@ -258,7 +259,7 @@ func newConsensusStateForReplay(config cfg.Config) *ConsensusState {
|
|||||||
// Make event switch
|
// Make event switch
|
||||||
eventSwitch := types.NewEventSwitch()
|
eventSwitch := types.NewEventSwitch()
|
||||||
if _, err := eventSwitch.Start(); err != nil {
|
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())
|
mempool := mempl.NewMempool(config, proxyApp.Mempool())
|
||||||
|
@ -12,17 +12,17 @@ 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"
|
|
||||||
"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 +408,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 +602,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 +617,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}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,13 +10,13 @@ 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"
|
|
||||||
"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"
|
||||||
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -56,7 +56,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"),
|
||||||
@ -222,9 +222,9 @@ type PrivValidator interface {
|
|||||||
|
|
||||||
// Tracks consensus state across block heights and rounds.
|
// Tracks consensus state across block heights and rounds.
|
||||||
type ConsensusState struct {
|
type ConsensusState struct {
|
||||||
BaseService
|
cmn.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 +255,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,
|
||||||
@ -276,7 +276,7 @@ func NewConsensusState(config cfg.Config, state *sm.State, proxyAppConn proxy.Ap
|
|||||||
// Don't call scheduleRound0 yet.
|
// Don't call scheduleRound0 yet.
|
||||||
// We do that upon Start().
|
// We do that upon Start().
|
||||||
cs.reconstructLastCommit(state)
|
cs.reconstructLastCommit(state)
|
||||||
cs.BaseService = *NewBaseService(log, "ConsensusState", cs)
|
cs.BaseService = *cmn.NewBaseService(log, "ConsensusState", cs)
|
||||||
return cs
|
return cs
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,7 +290,7 @@ func (cs *ConsensusState) SetEventSwitch(evsw types.EventSwitch) {
|
|||||||
|
|
||||||
func (cs *ConsensusState) String() string {
|
func (cs *ConsensusState) String() string {
|
||||||
// better not to access shared variables
|
// 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 {
|
func (cs *ConsensusState) GetState() *sm.State {
|
||||||
@ -398,7 +398,7 @@ func (cs *ConsensusState) Wait() {
|
|||||||
|
|
||||||
// Open file to log all consensus messages and timeouts for deterministic accountability
|
// Open file to log all consensus messages and timeouts for deterministic accountability
|
||||||
func (cs *ConsensusState) OpenWAL(walFile string) (err error) {
|
func (cs *ConsensusState) OpenWAL(walFile string) (err error) {
|
||||||
err = EnsureDir(path.Dir(walFile), 0700)
|
err = cmn.EnsureDir(path.Dir(walFile), 0700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error ensuring ConsensusState wal dir", "error", err.Error())
|
log.Error("Error ensuring ConsensusState wal dir", "error", err.Error())
|
||||||
return err
|
return err
|
||||||
@ -519,11 +519,11 @@ func (cs *ConsensusState) reconstructLastCommit(state *sm.State) {
|
|||||||
}
|
}
|
||||||
added, err := lastPrecommits.AddVote(precommit)
|
added, err := lastPrecommits.AddVote(precommit)
|
||||||
if !added || err != nil {
|
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() {
|
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
|
cs.LastCommit = lastPrecommits
|
||||||
}
|
}
|
||||||
@ -532,13 +532,13 @@ func (cs *ConsensusState) reconstructLastCommit(state *sm.State) {
|
|||||||
// The round becomes 0 and cs.Step becomes RoundStepNewHeight.
|
// The round becomes 0 and cs.Step becomes RoundStepNewHeight.
|
||||||
func (cs *ConsensusState) updateToState(state *sm.State) {
|
func (cs *ConsensusState) updateToState(state *sm.State) {
|
||||||
if cs.CommitRound > -1 && 0 < cs.Height && cs.Height != state.LastBlockHeight {
|
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))
|
cs.Height, state.LastBlockHeight))
|
||||||
}
|
}
|
||||||
if cs.state != nil && cs.state.LastBlockHeight+1 != cs.Height {
|
if cs.state != nil && cs.state.LastBlockHeight+1 != cs.Height {
|
||||||
// This might happen when someone else is mutating cs.state.
|
// This might happen when someone else is mutating cs.state.
|
||||||
// Someone forgot to pass in state.Copy() somewhere?!
|
// 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))
|
cs.state.LastBlockHeight+1, cs.Height))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,7 +555,7 @@ func (cs *ConsensusState) updateToState(state *sm.State) {
|
|||||||
lastPrecommits := (*types.VoteSet)(nil)
|
lastPrecommits := (*types.VoteSet)(nil)
|
||||||
if cs.CommitRound > -1 && cs.Votes != nil {
|
if cs.CommitRound > -1 && cs.Votes != nil {
|
||||||
if !cs.Votes.Precommits(cs.CommitRound).HasTwoThirdsMajority() {
|
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)
|
lastPrecommits = cs.Votes.Precommits(cs.CommitRound)
|
||||||
}
|
}
|
||||||
@ -723,7 +723,7 @@ func (cs *ConsensusState) handleTimeout(ti timeoutInfo, rs RoundState) {
|
|||||||
types.FireEventTimeoutWait(cs.evsw, cs.RoundStateEvent())
|
types.FireEventTimeoutWait(cs.evsw, cs.RoundStateEvent())
|
||||||
cs.enterNewRound(ti.Height, ti.Round+1)
|
cs.enterNewRound(ti.Height, ti.Round+1)
|
||||||
default:
|
default:
|
||||||
panic(Fmt("Invalid timeout step: %v", ti.Step))
|
panic(cmn.Fmt("Invalid timeout step: %v", ti.Step))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -738,7 +738,7 @@ func (cs *ConsensusState) handleTimeout(ti timeoutInfo, rs RoundState) {
|
|||||||
// NOTE: cs.StartTime was already set for height.
|
// NOTE: cs.StartTime was already set for height.
|
||||||
func (cs *ConsensusState) enterNewRound(height int, round int) {
|
func (cs *ConsensusState) enterNewRound(height int, round int) {
|
||||||
if cs.Height != height || round < cs.Round || (cs.Round == round && cs.Step != RoundStepNewHeight) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -746,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.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
|
// Increment validators if necessary
|
||||||
validators := cs.Validators
|
validators := cs.Validators
|
||||||
@ -780,10 +780,10 @@ func (cs *ConsensusState) enterNewRound(height int, round int) {
|
|||||||
// Enter: from NewRound(height,round).
|
// Enter: from NewRound(height,round).
|
||||||
func (cs *ConsensusState) enterPropose(height int, round int) {
|
func (cs *ConsensusState) enterPropose(height int, round int) {
|
||||||
if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPropose <= cs.Step) {
|
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
|
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() {
|
defer func() {
|
||||||
// Done enterPropose:
|
// Done enterPropose:
|
||||||
@ -850,7 +850,7 @@ func (cs *ConsensusState) defaultDecideProposal(height, round int) {
|
|||||||
cs.sendInternalMessage(msgInfo{&BlockPartMessage{cs.Height, cs.Round, part}, ""})
|
cs.sendInternalMessage(msgInfo{&BlockPartMessage{cs.Height, cs.Round, part}, ""})
|
||||||
}
|
}
|
||||||
log.Info("Signed proposal", "height", height, "round", round, "proposal", proposal)
|
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 {
|
} else {
|
||||||
if !cs.replayMode {
|
if !cs.replayMode {
|
||||||
log.Warn("enterPropose: Error signing proposal", "height", height, "round", round, "error", err)
|
log.Warn("enterPropose: Error signing proposal", "height", height, "round", round, "error", err)
|
||||||
@ -906,7 +906,7 @@ func (cs *ConsensusState) createProposalBlock() (block *types.Block, blockParts
|
|||||||
// Otherwise vote nil.
|
// Otherwise vote nil.
|
||||||
func (cs *ConsensusState) enterPrevote(height int, round int) {
|
func (cs *ConsensusState) enterPrevote(height int, round int) {
|
||||||
if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPrevote <= cs.Step) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -924,7 +924,7 @@ func (cs *ConsensusState) enterPrevote(height int, round int) {
|
|||||||
// TODO: catchup event?
|
// 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
|
// Sign and broadcast vote as necessary
|
||||||
cs.doPrevote(height, round)
|
cs.doPrevote(height, round)
|
||||||
@ -967,13 +967,13 @@ func (cs *ConsensusState) defaultDoPrevote(height int, round int) {
|
|||||||
// Enter: any +2/3 prevotes at next round.
|
// Enter: any +2/3 prevotes at next round.
|
||||||
func (cs *ConsensusState) enterPrevoteWait(height int, round int) {
|
func (cs *ConsensusState) enterPrevoteWait(height int, round int) {
|
||||||
if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPrevoteWait <= cs.Step) {
|
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
|
return
|
||||||
}
|
}
|
||||||
if !cs.Votes.Prevotes(round).HasTwoThirdsAny() {
|
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() {
|
defer func() {
|
||||||
// Done enterPrevoteWait:
|
// Done enterPrevoteWait:
|
||||||
@ -993,11 +993,11 @@ func (cs *ConsensusState) enterPrevoteWait(height int, round int) {
|
|||||||
// else, precommit nil otherwise.
|
// else, precommit nil otherwise.
|
||||||
func (cs *ConsensusState) enterPrecommit(height int, round int) {
|
func (cs *ConsensusState) enterPrecommit(height int, round int) {
|
||||||
if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPrecommit <= cs.Step) {
|
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
|
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() {
|
defer func() {
|
||||||
// Done enterPrecommit:
|
// Done enterPrecommit:
|
||||||
@ -1024,7 +1024,7 @@ func (cs *ConsensusState) enterPrecommit(height int, round int) {
|
|||||||
// the latest POLRound should be this round
|
// the latest POLRound should be this round
|
||||||
polRound, _ := cs.Votes.POLInfo()
|
polRound, _ := cs.Votes.POLInfo()
|
||||||
if polRound < round {
|
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.
|
// +2/3 prevoted nil. Unlock and precommit nil.
|
||||||
@ -1058,7 +1058,7 @@ func (cs *ConsensusState) enterPrecommit(height int, round int) {
|
|||||||
log.Notice("enterPrecommit: +2/3 prevoted proposal block. Locking", "hash", blockID.Hash)
|
log.Notice("enterPrecommit: +2/3 prevoted proposal block. Locking", "hash", blockID.Hash)
|
||||||
// Validate the block.
|
// Validate the block.
|
||||||
if err := cs.state.ValidateBlock(cs.ProposalBlock); err != nil {
|
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.LockedRound = round
|
||||||
cs.LockedBlock = cs.ProposalBlock
|
cs.LockedBlock = cs.ProposalBlock
|
||||||
@ -1087,13 +1087,13 @@ func (cs *ConsensusState) enterPrecommit(height int, round int) {
|
|||||||
// Enter: any +2/3 precommits for next round.
|
// Enter: any +2/3 precommits for next round.
|
||||||
func (cs *ConsensusState) enterPrecommitWait(height int, round int) {
|
func (cs *ConsensusState) enterPrecommitWait(height int, round int) {
|
||||||
if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPrecommitWait <= cs.Step) {
|
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
|
return
|
||||||
}
|
}
|
||||||
if !cs.Votes.Precommits(round).HasTwoThirdsAny() {
|
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() {
|
defer func() {
|
||||||
// Done enterPrecommitWait:
|
// Done enterPrecommitWait:
|
||||||
@ -1109,10 +1109,10 @@ func (cs *ConsensusState) enterPrecommitWait(height int, round int) {
|
|||||||
// Enter: +2/3 precommits for block
|
// Enter: +2/3 precommits for block
|
||||||
func (cs *ConsensusState) enterCommit(height int, commitRound int) {
|
func (cs *ConsensusState) enterCommit(height int, commitRound int) {
|
||||||
if cs.Height != height || RoundStepCommit <= cs.Step {
|
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
|
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() {
|
defer func() {
|
||||||
// Done enterCommit:
|
// Done enterCommit:
|
||||||
@ -1128,7 +1128,7 @@ func (cs *ConsensusState) enterCommit(height int, commitRound int) {
|
|||||||
|
|
||||||
blockID, ok := cs.Votes.Precommits(commitRound).TwoThirdsMajority()
|
blockID, ok := cs.Votes.Precommits(commitRound).TwoThirdsMajority()
|
||||||
if !ok {
|
if !ok {
|
||||||
PanicSanity("RunActionCommit() expects +2/3 precommits")
|
cmn.PanicSanity("RunActionCommit() expects +2/3 precommits")
|
||||||
}
|
}
|
||||||
|
|
||||||
// The Locked* fields no longer matter.
|
// The Locked* fields no longer matter.
|
||||||
@ -1155,7 +1155,7 @@ func (cs *ConsensusState) enterCommit(height int, commitRound int) {
|
|||||||
// If we have the block AND +2/3 commits for it, finalize.
|
// If we have the block AND +2/3 commits for it, finalize.
|
||||||
func (cs *ConsensusState) tryFinalizeCommit(height int) {
|
func (cs *ConsensusState) tryFinalizeCommit(height int) {
|
||||||
if cs.Height != height {
|
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()
|
blockID, ok := cs.Votes.Precommits(cs.CommitRound).TwoThirdsMajority()
|
||||||
@ -1176,7 +1176,7 @@ func (cs *ConsensusState) tryFinalizeCommit(height int) {
|
|||||||
// Increment height and goto RoundStepNewHeight
|
// Increment height and goto RoundStepNewHeight
|
||||||
func (cs *ConsensusState) finalizeCommit(height int) {
|
func (cs *ConsensusState) finalizeCommit(height int) {
|
||||||
if cs.Height != height || cs.Step != RoundStepCommit {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1184,21 +1184,21 @@ func (cs *ConsensusState) finalizeCommit(height int) {
|
|||||||
block, blockParts := cs.ProposalBlock, cs.ProposalBlockParts
|
block, blockParts := cs.ProposalBlock, cs.ProposalBlockParts
|
||||||
|
|
||||||
if !ok {
|
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) {
|
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) {
|
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 {
|
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)
|
"height", block.Height, "hash", block.Hash(), "root", block.AppHash)
|
||||||
log.Info(Fmt("%v", block))
|
log.Info(cmn.Fmt("%v", block))
|
||||||
|
|
||||||
fail.Fail() // XXX
|
fail.Fail() // XXX
|
||||||
|
|
||||||
@ -1393,7 +1393,7 @@ func (cs *ConsensusState) addVote(vote *types.Vote, peerKey string) (added bool,
|
|||||||
}
|
}
|
||||||
added, err = cs.LastCommit.AddVote(vote)
|
added, err = cs.LastCommit.AddVote(vote)
|
||||||
if added {
|
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})
|
types.FireEventVote(cs.evsw, types.EventDataVote{vote})
|
||||||
|
|
||||||
// if we can skip timeoutCommit and have all the votes now,
|
// if we can skip timeoutCommit and have all the votes now,
|
||||||
@ -1474,7 +1474,7 @@ func (cs *ConsensusState) addVote(vote *types.Vote, peerKey string) (added bool,
|
|||||||
cs.enterPrecommitWait(height, vote.Round)
|
cs.enterPrecommitWait(height, vote.Round)
|
||||||
}
|
}
|
||||||
default:
|
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()
|
// Either duplicate, or error upon cs.Votes.AddByIndex()
|
||||||
|
50
glide.lock
generated
50
glide.lock
generated
@ -1,18 +1,18 @@
|
|||||||
hash: 9096fc4e29eff8fac3708ed30deacac67b7a181f0192b177006105dccdb16686
|
hash: 6f8962f6ca0e25b8e43bc6e496bd46c9ff3a79dcf789578efeeaee2fffc39c6e
|
||||||
updated: 2017-04-21T18:39:37.154946943-04:00
|
updated: 2017-04-25T14:48:36.999444976-04:00
|
||||||
imports:
|
imports:
|
||||||
- name: github.com/btcsuite/btcd
|
- name: github.com/btcsuite/btcd
|
||||||
version: 583684b21bfbde9b5fc4403916fd7c807feb0289
|
version: 583684b21bfbde9b5fc4403916fd7c807feb0289
|
||||||
subpackages:
|
subpackages:
|
||||||
- btcec
|
- btcec
|
||||||
- name: github.com/BurntSushi/toml
|
|
||||||
version: 99064174e013895bbd9b025c31100bd1d9b590ca
|
|
||||||
- name: github.com/davecgh/go-spew
|
- name: github.com/davecgh/go-spew
|
||||||
version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9
|
version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9
|
||||||
subpackages:
|
subpackages:
|
||||||
- spew
|
- spew
|
||||||
- name: github.com/ebuchman/fail-test
|
- name: github.com/ebuchman/fail-test
|
||||||
version: 95f809107225be108efcf10a3509e4ea6ceef3c4
|
version: 95f809107225be108efcf10a3509e4ea6ceef3c4
|
||||||
|
- name: github.com/fsnotify/fsnotify
|
||||||
|
version: 4da3e2cfbabc9f751898f250b49f2439785783a1
|
||||||
- name: github.com/go-stack/stack
|
- name: github.com/go-stack/stack
|
||||||
version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82
|
version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82
|
||||||
- name: github.com/gogo/protobuf
|
- name: github.com/gogo/protobuf
|
||||||
@ -27,24 +27,53 @@ imports:
|
|||||||
version: d9eb7a3d35ec988b8585d4a0068e462c27d28380
|
version: d9eb7a3d35ec988b8585d4a0068e462c27d28380
|
||||||
- name: github.com/gorilla/websocket
|
- name: github.com/gorilla/websocket
|
||||||
version: 3ab3a8b8831546bd18fd182c20687ca853b2bb13
|
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
|
- name: github.com/inconshreveable/mousetrap
|
||||||
version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75
|
version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75
|
||||||
- name: github.com/jmhodges/levigo
|
- name: github.com/jmhodges/levigo
|
||||||
version: c42d9e0ca023e2198120196f842701bb4c55d7b9
|
version: c42d9e0ca023e2198120196f842701bb4c55d7b9
|
||||||
|
- name: github.com/magiconair/properties
|
||||||
|
version: 51463bfca2576e06c62a8504b5c0f06d61312647
|
||||||
- name: github.com/mattn/go-colorable
|
- name: github.com/mattn/go-colorable
|
||||||
version: d228849504861217f796da67fae4f6e347643f15
|
version: d228849504861217f796da67fae4f6e347643f15
|
||||||
- name: github.com/mattn/go-isatty
|
- name: github.com/mattn/go-isatty
|
||||||
version: 30a891c33c7cde7b02a981314b4228ec99380cca
|
version: 30a891c33c7cde7b02a981314b4228ec99380cca
|
||||||
|
- name: github.com/mitchellh/mapstructure
|
||||||
|
version: 53818660ed4955e899c0bcafa97299a388bd7c8e
|
||||||
|
- name: github.com/pelletier/go-buffruneio
|
||||||
|
version: c37440a7cf42ac63b919c752ca73a85067e05992
|
||||||
|
- name: github.com/pelletier/go-toml
|
||||||
|
version: 13d49d4606eb801b8f01ae542b4afc4c6ee3d84a
|
||||||
- name: github.com/pkg/errors
|
- name: github.com/pkg/errors
|
||||||
version: 645ef00459ed84a119197bfb8d8205042c6df63d
|
version: 645ef00459ed84a119197bfb8d8205042c6df63d
|
||||||
- name: github.com/pmezard/go-difflib
|
- name: github.com/pmezard/go-difflib
|
||||||
version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
|
version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
|
||||||
subpackages:
|
subpackages:
|
||||||
- difflib
|
- difflib
|
||||||
|
- name: github.com/spf13/afero
|
||||||
|
version: 9be650865eab0c12963d8753212f4f9c66cdcf12
|
||||||
|
subpackages:
|
||||||
|
- mem
|
||||||
|
- name: github.com/spf13/cast
|
||||||
|
version: acbeb36b902d72a7a4c18e8f3241075e7ab763e4
|
||||||
- name: github.com/spf13/cobra
|
- name: github.com/spf13/cobra
|
||||||
version: fcd0c5a1df88f5d6784cb4feead962c3f3d0b66c
|
version: fcd0c5a1df88f5d6784cb4feead962c3f3d0b66c
|
||||||
|
- name: github.com/spf13/jwalterweatherman
|
||||||
|
version: fa7ca7e836cf3a8bb4ebf799f472c12d7e903d66
|
||||||
- name: github.com/spf13/pflag
|
- name: github.com/spf13/pflag
|
||||||
version: 9ff6c6923cfffbcd502984b8e0c80539a94968b7
|
version: 9ff6c6923cfffbcd502984b8e0c80539a94968b7
|
||||||
|
- name: github.com/spf13/viper
|
||||||
|
version: 5d46e70da8c0b6f812e0b170b7a985753b5c63cb
|
||||||
- name: github.com/stretchr/testify
|
- name: github.com/stretchr/testify
|
||||||
version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0
|
version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0
|
||||||
subpackages:
|
subpackages:
|
||||||
@ -66,7 +95,7 @@ imports:
|
|||||||
- leveldb/table
|
- leveldb/table
|
||||||
- leveldb/util
|
- leveldb/util
|
||||||
- name: github.com/tendermint/abci
|
- name: github.com/tendermint/abci
|
||||||
version: be61e273cebeb64866a83c578f92b22cf2169cdd
|
version: c709d3cc857929a8dd36a90da3640122d7e75770
|
||||||
subpackages:
|
subpackages:
|
||||||
- client
|
- client
|
||||||
- example/counter
|
- example/counter
|
||||||
@ -78,10 +107,6 @@ imports:
|
|||||||
subpackages:
|
subpackages:
|
||||||
- edwards25519
|
- edwards25519
|
||||||
- extra25519
|
- extra25519
|
||||||
- name: github.com/tendermint/go-common
|
|
||||||
version: f9e3db037330c8a8d61d3966de8473eaf01154fa
|
|
||||||
- name: github.com/tendermint/go-config
|
|
||||||
version: 620dcbbd7d587cf3599dedbf329b64311b0c307a
|
|
||||||
- name: github.com/tendermint/go-crypto
|
- name: github.com/tendermint/go-crypto
|
||||||
version: 9b95da8fa4187f6799558d89b271dc8ab6485615
|
version: 9b95da8fa4187f6799558d89b271dc8ab6485615
|
||||||
- name: github.com/tendermint/go-wire
|
- name: github.com/tendermint/go-wire
|
||||||
@ -136,6 +161,11 @@ imports:
|
|||||||
version: d75a52659825e75fff6158388dddc6a5b04f9ba5
|
version: d75a52659825e75fff6158388dddc6a5b04f9ba5
|
||||||
subpackages:
|
subpackages:
|
||||||
- unix
|
- unix
|
||||||
|
- name: golang.org/x/text
|
||||||
|
version: f4b4367115ec2de254587813edaa901bc1c723a8
|
||||||
|
subpackages:
|
||||||
|
- transform
|
||||||
|
- unicode/norm
|
||||||
- name: google.golang.org/grpc
|
- name: google.golang.org/grpc
|
||||||
version: cbcceb2942a489498cf22b2f918536e819d33f0a
|
version: cbcceb2942a489498cf22b2f918536e819d33f0a
|
||||||
subpackages:
|
subpackages:
|
||||||
@ -149,4 +179,6 @@ imports:
|
|||||||
- stats
|
- stats
|
||||||
- tap
|
- tap
|
||||||
- transport
|
- transport
|
||||||
|
- name: gopkg.in/yaml.v2
|
||||||
|
version: cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b
|
||||||
testImports: []
|
testImports: []
|
||||||
|
@ -10,6 +10,7 @@ import:
|
|||||||
- package: github.com/gorilla/websocket
|
- package: github.com/gorilla/websocket
|
||||||
- package: github.com/pkg/errors
|
- package: github.com/pkg/errors
|
||||||
- package: github.com/spf13/cobra
|
- package: github.com/spf13/cobra
|
||||||
|
- package: github.com/spf13/viper
|
||||||
- package: github.com/stretchr/testify
|
- package: github.com/stretchr/testify
|
||||||
subpackages:
|
subpackages:
|
||||||
- require
|
- require
|
||||||
@ -19,8 +20,6 @@ import:
|
|||||||
- client
|
- client
|
||||||
- example/dummy
|
- example/dummy
|
||||||
- types
|
- types
|
||||||
- package: github.com/tendermint/go-config
|
|
||||||
version: develop
|
|
||||||
- package: github.com/tendermint/go-crypto
|
- package: github.com/tendermint/go-crypto
|
||||||
version: develop
|
version: develop
|
||||||
- package: github.com/tendermint/go-wire
|
- package: github.com/tendermint/go-wire
|
||||||
|
@ -7,13 +7,14 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
|
"github.com/tendermint/tendermint/proxy"
|
||||||
|
"github.com/tendermint/tendermint/types"
|
||||||
auto "github.com/tendermint/tmlibs/autofile"
|
auto "github.com/tendermint/tmlibs/autofile"
|
||||||
"github.com/tendermint/tmlibs/clist"
|
"github.com/tendermint/tmlibs/clist"
|
||||||
. "github.com/tendermint/tmlibs/common"
|
. "github.com/tendermint/tmlibs/common"
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
"github.com/tendermint/tendermint/proxy"
|
|
||||||
"github.com/tendermint/tendermint/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -47,7 +48,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 +67,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,12 +6,13 @@ 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"
|
|
||||||
"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 +25,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,
|
||||||
|
25
node/node.go
25
node/node.go
@ -7,19 +7,18 @@ 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"
|
|
||||||
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 +27,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 +37,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 +58,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 +135,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)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package p2p
|
package p2p
|
||||||
|
|
||||||
import (
|
import (
|
||||||
cfg "github.com/tendermint/go-config"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -24,7 +24,7 @@ const (
|
|||||||
configFuzzProbSleep = "fuzz_prob_sleep"
|
configFuzzProbSleep = "fuzz_prob_sleep"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setConfigDefaults(config cfg.Config) {
|
func setConfigDefaults(config *viper.Viper) {
|
||||||
// Switch default config
|
// Switch default config
|
||||||
config.SetDefault(configKeyDialTimeoutSeconds, 3)
|
config.SetDefault(configKeyDialTimeoutSeconds, 3)
|
||||||
config.SetDefault(configKeyHandshakeTimeoutSeconds, 20)
|
config.SetDefault(configKeyHandshakeTimeoutSeconds, 20)
|
||||||
|
@ -7,7 +7,8 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cfg "github.com/tendermint/go-config"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
crypto "github.com/tendermint/go-crypto"
|
crypto "github.com/tendermint/go-crypto"
|
||||||
"github.com/tendermint/log15"
|
"github.com/tendermint/log15"
|
||||||
. "github.com/tendermint/tmlibs/common"
|
. "github.com/tendermint/tmlibs/common"
|
||||||
@ -61,7 +62,7 @@ incoming messages are received on the reactor.
|
|||||||
type Switch struct {
|
type Switch struct {
|
||||||
BaseService
|
BaseService
|
||||||
|
|
||||||
config cfg.Config
|
config *viper.Viper
|
||||||
listeners []Listener
|
listeners []Listener
|
||||||
reactors map[string]Reactor
|
reactors map[string]Reactor
|
||||||
chDescs []*ChannelDescriptor
|
chDescs []*ChannelDescriptor
|
||||||
@ -80,7 +81,7 @@ var (
|
|||||||
ErrSwitchMaxPeersPerIPRange = errors.New("IP range has too many peers")
|
ErrSwitchMaxPeersPerIPRange = errors.New("IP range has too many peers")
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewSwitch(config cfg.Config) *Switch {
|
func NewSwitch(config *viper.Viper) *Switch {
|
||||||
setConfigDefaults(config)
|
setConfigDefaults(config)
|
||||||
|
|
||||||
sw := &Switch{
|
sw := &Switch{
|
||||||
@ -529,7 +530,7 @@ func makeSwitch(i int, network, version string, initSwitch func(int, *Switch) *S
|
|||||||
privKey := crypto.GenPrivKeyEd25519()
|
privKey := crypto.GenPrivKeyEd25519()
|
||||||
// new switch, add reactors
|
// new switch, add reactors
|
||||||
// TODO: let the config be passed in?
|
// TODO: let the config be passed in?
|
||||||
s := initSwitch(i, NewSwitch(cfg.NewMapConfig(nil)))
|
s := initSwitch(i, NewSwitch(viper.New()))
|
||||||
s.SetNodeInfo(&NodeInfo{
|
s.SetNodeInfo(&NodeInfo{
|
||||||
PubKey: privKey.PubKey().Unwrap().(crypto.PubKeyEd25519),
|
PubKey: privKey.PubKey().Unwrap().(crypto.PubKeyEd25519),
|
||||||
Moniker: Fmt("switch%d", i),
|
Moniker: Fmt("switch%d", i),
|
||||||
@ -572,7 +573,7 @@ func (sw *Switch) addPeerWithConnectionAndConfig(conn net.Conn, config *PeerConf
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func peerConfigFromGoConfig(config cfg.Config) *PeerConfig {
|
func peerConfigFromGoConfig(config *viper.Viper) *PeerConfig {
|
||||||
return &PeerConfig{
|
return &PeerConfig{
|
||||||
AuthEnc: config.GetBool(configKeyAuthEnc),
|
AuthEnc: config.GetBool(configKeyAuthEnc),
|
||||||
Fuzz: config.GetBool(configFuzzEnable),
|
Fuzz: config.GetBool(configFuzzEnable),
|
||||||
|
@ -8,20 +8,21 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
. "github.com/tendermint/tmlibs/common"
|
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
crypto "github.com/tendermint/go-crypto"
|
crypto "github.com/tendermint/go-crypto"
|
||||||
wire "github.com/tendermint/go-wire"
|
wire "github.com/tendermint/go-wire"
|
||||||
|
. "github.com/tendermint/tmlibs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
config cfg.Config
|
config *viper.Viper
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
config = cfg.NewMapConfig(nil)
|
config = viper.New()
|
||||||
setConfigDefaults(config)
|
setConfigDefaults(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,11 +4,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/tendermint/tmlibs/common"
|
|
||||||
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/server"
|
"github.com/tendermint/abci/server"
|
||||||
"github.com/tendermint/abci/types"
|
"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"
|
var SOCKET = "socket"
|
||||||
|
|
||||||
func TestEcho(t *testing.T) {
|
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)
|
clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true)
|
||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
s, err := server.NewSocketServer(sockPath, dummy.NewDummyApplication())
|
s, err := server.NewSocketServer(sockPath, dummy.NewDummyApplication())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
cmn.Exit(err.Error())
|
||||||
}
|
}
|
||||||
defer s.Stop()
|
defer s.Stop()
|
||||||
// Start client
|
// Start client
|
||||||
cli, err := clientCreator.NewABCIClient()
|
cli, err := clientCreator.NewABCIClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
cmn.Exit(err.Error())
|
||||||
}
|
}
|
||||||
proxy := NewAppConnTest(cli)
|
proxy := NewAppConnTest(cli)
|
||||||
t.Log("Connected")
|
t.Log("Connected")
|
||||||
|
|
||||||
for i := 0; i < 1000; i++ {
|
for i := 0; i < 1000; i++ {
|
||||||
proxy.EchoAsync(Fmt("echo-%v", i))
|
proxy.EchoAsync(cmn.Fmt("echo-%v", i))
|
||||||
}
|
}
|
||||||
proxy.FlushSync()
|
proxy.FlushSync()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkEcho(b *testing.B) {
|
func BenchmarkEcho(b *testing.B) {
|
||||||
b.StopTimer() // Initialize
|
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)
|
clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true)
|
||||||
// Start server
|
// Start server
|
||||||
s, err := server.NewSocketServer(sockPath, dummy.NewDummyApplication())
|
s, err := server.NewSocketServer(sockPath, dummy.NewDummyApplication())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
cmn.Exit(err.Error())
|
||||||
}
|
}
|
||||||
defer s.Stop()
|
defer s.Stop()
|
||||||
// Start client
|
// Start client
|
||||||
cli, err := clientCreator.NewABCIClient()
|
cli, err := clientCreator.NewABCIClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
cmn.Exit(err.Error())
|
||||||
}
|
}
|
||||||
proxy := NewAppConnTest(cli)
|
proxy := NewAppConnTest(cli)
|
||||||
b.Log("Connected")
|
b.Log("Connected")
|
||||||
@ -98,18 +98,18 @@ func BenchmarkEcho(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestInfo(t *testing.T) {
|
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)
|
clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true)
|
||||||
// Start server
|
// Start server
|
||||||
s, err := server.NewSocketServer(sockPath, dummy.NewDummyApplication())
|
s, err := server.NewSocketServer(sockPath, dummy.NewDummyApplication())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
cmn.Exit(err.Error())
|
||||||
}
|
}
|
||||||
defer s.Stop()
|
defer s.Stop()
|
||||||
// Start client
|
// Start client
|
||||||
cli, err := clientCreator.NewABCIClient()
|
cli, err := clientCreator.NewABCIClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
cmn.Exit(err.Error())
|
||||||
}
|
}
|
||||||
proxy := NewAppConnTest(cli)
|
proxy := NewAppConnTest(cli)
|
||||||
t.Log("Connected")
|
t.Log("Connected")
|
||||||
|
@ -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")
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/spf13/viper"
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//-----------------------------
|
//-----------------------------
|
||||||
@ -16,7 +16,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 +34,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 +46,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,
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
cfg "github.com/tendermint/go-config"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
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 +34,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 +49,7 @@ var (
|
|||||||
txIndexer txindex.TxIndexer
|
txIndexer txindex.TxIndexer
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetConfig(c cfg.Config) {
|
func SetConfig(c *viper.Viper) {
|
||||||
config = c
|
config = c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@ package core
|
|||||||
import (
|
import (
|
||||||
data "github.com/tendermint/go-wire/data"
|
data "github.com/tendermint/go-wire/data"
|
||||||
rpc "github.com/tendermint/tendermint/rpc/server"
|
rpc "github.com/tendermint/tendermint/rpc/server"
|
||||||
"github.com/tendermint/tendermint/rpc/types"
|
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/tendermint/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/tendermint/core/types"
|
||||||
|
"github.com/tendermint/tendermint/rpc/types"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -39,7 +39,9 @@ var Routes = map[string]*rpc.RPCFunc{
|
|||||||
// control API
|
// control API
|
||||||
"dial_seeds": rpc.NewRPCFunc(UnsafeDialSeedsResult, "seeds"),
|
"dial_seeds": rpc.NewRPCFunc(UnsafeDialSeedsResult, "seeds"),
|
||||||
"unsafe_flush_mempool": rpc.NewRPCFunc(UnsafeFlushMempool, ""),
|
"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
|
// profiler API
|
||||||
"unsafe_start_cpu_profiler": rpc.NewRPCFunc(UnsafeStartCPUProfilerResult, "filename"),
|
"unsafe_start_cpu_profiler": rpc.NewRPCFunc(UnsafeStartCPUProfilerResult, "filename"),
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
rpc "github.com/tendermint/tendermint/rpc/client"
|
rpc "github.com/tendermint/tendermint/rpc/client"
|
||||||
"github.com/tendermint/tendermint/rpc/tendermint/core"
|
"github.com/tendermint/tendermint/rpc/tendermint/core"
|
||||||
@ -66,8 +67,8 @@ func TestJSONBroadcastTxSync(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testBroadcastTxSync(t *testing.T, client rpc.HTTPClient) {
|
func testBroadcastTxSync(t *testing.T, client rpc.HTTPClient) {
|
||||||
config.Set("block_size", 0)
|
mem := node.MempoolReactor().Mempool
|
||||||
defer config.Set("block_size", -1)
|
initMemSize := mem.Size()
|
||||||
tmResult := new(ctypes.TMResult)
|
tmResult := new(ctypes.TMResult)
|
||||||
tx := randBytes(t)
|
tx := randBytes(t)
|
||||||
_, err := client.Call("broadcast_tx_sync", map[string]interface{}{"tx": tx}, tmResult)
|
_, err := client.Call("broadcast_tx_sync", map[string]interface{}{"tx": tx}, tmResult)
|
||||||
@ -75,8 +76,7 @@ func testBroadcastTxSync(t *testing.T, client rpc.HTTPClient) {
|
|||||||
|
|
||||||
res := (*tmResult).(*ctypes.ResultBroadcastTx)
|
res := (*tmResult).(*ctypes.ResultBroadcastTx)
|
||||||
require.Equal(t, abci.CodeType_OK, res.Code)
|
require.Equal(t, abci.CodeType_OK, res.Code)
|
||||||
mem := node.MempoolReactor().Mempool
|
require.Equal(t, initMemSize+1, mem.Size())
|
||||||
require.Equal(t, 1, mem.Size())
|
|
||||||
txs := mem.Reap(1)
|
txs := mem.Reap(1)
|
||||||
require.EqualValues(t, tx, txs[0])
|
require.EqualValues(t, tx, txs[0])
|
||||||
mem.Flush()
|
mem.Flush()
|
||||||
@ -357,51 +357,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
|
// unsafe_set_config
|
||||||
|
|
||||||
var stringVal = "my string"
|
//var stringVal = "my string"
|
||||||
var intVal = 987654321
|
//var intVal = 987654321
|
||||||
var boolVal = true
|
//var boolVal = true
|
||||||
|
//
|
||||||
// don't change these
|
//// don't change these
|
||||||
var testCasesUnsafeSetConfig = [][]string{
|
//var testCasesUnsafeSetConfig = [][]string{
|
||||||
[]string{"string", "key1", stringVal},
|
// []string{"string", "key1", stringVal},
|
||||||
[]string{"int", "key2", fmt.Sprintf("%v", intVal)},
|
// []string{"int", "key2", fmt.Sprintf("%v", intVal)},
|
||||||
[]string{"bool", "key3", fmt.Sprintf("%v", boolVal)},
|
// []string{"bool", "key3", fmt.Sprintf("%v", boolVal)},
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func TestURIUnsafeSetConfig(t *testing.T) {
|
//func TestURIUnsafeSetConfig(t *testing.T) {
|
||||||
for _, testCase := range testCasesUnsafeSetConfig {
|
// for _, testCase := range testCasesUnsafeSetConfig {
|
||||||
tmResult := new(ctypes.TMResult)
|
// tmResult := new(ctypes.TMResult)
|
||||||
_, err := GetURIClient().Call("unsafe_set_config", map[string]interface{}{
|
// _, err := GetURIClient().Call("unsafe_set_config", map[string]interface{}{
|
||||||
"type": testCase[0],
|
// "type": testCase[0],
|
||||||
"key": testCase[1],
|
// "key": testCase[1],
|
||||||
"value": testCase[2],
|
// "value": testCase[2],
|
||||||
}, tmResult)
|
// }, tmResult)
|
||||||
require.Nil(t, err)
|
// require.Nil(t, err)
|
||||||
}
|
// }
|
||||||
testUnsafeSetConfig(t)
|
// testUnsafeSetConfig(t)
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func TestJSONUnsafeSetConfig(t *testing.T) {
|
//func TestJSONUnsafeSetConfig(t *testing.T) {
|
||||||
for _, testCase := range testCasesUnsafeSetConfig {
|
// for _, testCase := range testCasesUnsafeSetConfig {
|
||||||
tmResult := new(ctypes.TMResult)
|
// tmResult := new(ctypes.TMResult)
|
||||||
_, err := GetJSONClient().Call("unsafe_set_config",
|
// _, err := GetJSONClient().Call("unsafe_set_config",
|
||||||
map[string]interface{}{"type": testCase[0], "key": testCase[1], "value": testCase[2]},
|
// map[string]interface{}{"type": testCase[0], "key": testCase[1], "value": testCase[2]},
|
||||||
tmResult)
|
// tmResult)
|
||||||
require.Nil(t, err)
|
// require.Nil(t, err)
|
||||||
}
|
// }
|
||||||
testUnsafeSetConfig(t)
|
// testUnsafeSetConfig(t)
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func testUnsafeSetConfig(t *testing.T) {
|
//func testUnsafeSetConfig(t *testing.T) {
|
||||||
require := require.New(t)
|
// require := require.New(t)
|
||||||
s := config.GetString("key1")
|
// s := config.GetString("key1")
|
||||||
require.Equal(stringVal, s)
|
// require.Equal(stringVal, s)
|
||||||
|
//
|
||||||
i := config.GetInt("key2")
|
// i := config.GetInt("key2")
|
||||||
require.Equal(intVal, i)
|
// require.Equal(intVal, i)
|
||||||
|
//
|
||||||
b := config.GetBool("key3")
|
// b := config.GetBool("key3")
|
||||||
require.Equal(boolVal, b)
|
// require.Equal(boolVal, b)
|
||||||
}
|
//}
|
||||||
|
@ -9,24 +9,22 @@ 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"
|
|
||||||
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 *viper.Viper
|
||||||
config cfg.Config
|
|
||||||
)
|
|
||||||
|
|
||||||
const tmLogLevel = "error"
|
const tmLogLevel = "error"
|
||||||
|
|
||||||
@ -56,7 +54,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)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package state
|
package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@ -36,20 +36,20 @@ type (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (e ErrUnknownBlock) Error() string {
|
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 {
|
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 {
|
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 {
|
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 {
|
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)
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,11 @@ import (
|
|||||||
|
|
||||||
fail "github.com/ebuchman/fail-test"
|
fail "github.com/ebuchman/fail-test"
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/tmlibs/common"
|
|
||||||
crypto "github.com/tendermint/go-crypto"
|
crypto "github.com/tendermint/go-crypto"
|
||||||
"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"
|
||||||
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -126,7 +126,7 @@ func updateValidators(validators *types.ValidatorSet, changedValidators []*abci.
|
|||||||
power := int64(v.Power)
|
power := int64(v.Power)
|
||||||
// mind the overflow from uint64
|
// mind the overflow from uint64
|
||||||
if power < 0 {
|
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)
|
_, val := validators.GetByAddress(address)
|
||||||
@ -134,20 +134,20 @@ func updateValidators(validators *types.ValidatorSet, changedValidators []*abci.
|
|||||||
// add val
|
// add val
|
||||||
added := validators.Add(types.NewValidator(pubkey, power))
|
added := validators.Add(types.NewValidator(pubkey, power))
|
||||||
if !added {
|
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 {
|
} else if v.Power == 0 {
|
||||||
// remove val
|
// remove val
|
||||||
_, removed := validators.Remove(address)
|
_, removed := validators.Remove(address)
|
||||||
if !removed {
|
if !removed {
|
||||||
return errors.New(Fmt("Failed to remove validator %X)"))
|
return errors.New(cmn.Fmt("Failed to remove validator %X)"))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// update val
|
// update val
|
||||||
val.VotingPower = power
|
val.VotingPower = power
|
||||||
updated := validators.Update(val)
|
updated := validators.Update(val)
|
||||||
if !updated {
|
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
|
// return a bit array of validators that signed the last commit
|
||||||
// NOTE: assumes commits have already been authenticated
|
// NOTE: assumes commits have already been authenticated
|
||||||
func commitBitArrayFromBlock(block *types.Block) *BitArray {
|
func commitBitArrayFromBlock(block *types.Block) *cmn.BitArray {
|
||||||
signed := NewBitArray(len(block.LastCommit.Precommits))
|
signed := cmn.NewBitArray(len(block.LastCommit.Precommits))
|
||||||
for i, precommit := range block.LastCommit.Precommits {
|
for i, precommit := range block.LastCommit.Precommits {
|
||||||
if precommit != nil {
|
if precommit != nil {
|
||||||
signed.SetIndex(i, true) // val_.LastCommitHeight = block.Height - 1
|
signed.SetIndex(i, true) // val_.LastCommitHeight = block.Height - 1
|
||||||
@ -187,7 +187,7 @@ func (s *State) validateBlock(block *types.Block) error {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if len(block.LastCommit.Precommits) != s.LastValidators.Size() {
|
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)))
|
s.LastValidators.Size(), len(block.LastCommit.Precommits)))
|
||||||
}
|
}
|
||||||
err := s.LastValidators.VerifyCommit(
|
err := s.LastValidators.VerifyCommit(
|
||||||
|
@ -6,10 +6,11 @@ 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"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
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"
|
||||||
@ -64,7 +65,7 @@ func loadState(db dbm.DB, key []byte) *State {
|
|||||||
wire.ReadBinaryPtr(&s, r, 0, n, err)
|
wire.ReadBinaryPtr(&s, r, 0, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
// DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
|
// 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.
|
// TODO: ensure that buf is completely read.
|
||||||
}
|
}
|
||||||
@ -108,7 +109,7 @@ func (s *State) LoadABCIResponses() *ABCIResponses {
|
|||||||
wire.ReadBinaryPtr(abciResponses, r, 0, n, err)
|
wire.ReadBinaryPtr(abciResponses, r, 0, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
// DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
|
// 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.
|
// TODO: ensure that buf is completely read.
|
||||||
}
|
}
|
||||||
@ -123,7 +124,7 @@ func (s *State) Bytes() []byte {
|
|||||||
buf, n, err := new(bytes.Buffer), new(int), new(error)
|
buf, n, err := new(bytes.Buffer), new(int), new(error)
|
||||||
wire.WriteBinary(s, buf, n, err)
|
wire.WriteBinary(s, buf, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
PanicCrisis(*err)
|
cmn.PanicCrisis(*err)
|
||||||
}
|
}
|
||||||
return buf.Bytes()
|
return buf.Bytes()
|
||||||
}
|
}
|
||||||
@ -168,7 +169,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"))
|
||||||
@ -203,7 +204,7 @@ func (a *ABCIResponses) Bytes() []byte {
|
|||||||
buf, n, err := new(bytes.Buffer), new(int), new(error)
|
buf, n, err := new(bytes.Buffer), new(int), new(error)
|
||||||
wire.WriteBinary(*a, buf, n, err)
|
wire.WriteBinary(*a, buf, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
PanicCrisis(*err)
|
cmn.PanicCrisis(*err)
|
||||||
}
|
}
|
||||||
return buf.Bytes()
|
return buf.Bytes()
|
||||||
}
|
}
|
||||||
@ -217,11 +218,11 @@ func (a *ABCIResponses) Bytes() []byte {
|
|||||||
func MakeGenesisStateFromFile(db dbm.DB, genDocFile string) *State {
|
func MakeGenesisStateFromFile(db dbm.DB, genDocFile string) *State {
|
||||||
genDocJSON, err := ioutil.ReadFile(genDocFile)
|
genDocJSON, err := ioutil.ReadFile(genDocFile)
|
||||||
if err != nil {
|
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)
|
genDoc, err := types.GenesisDocFromJSON(genDocJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(Fmt("Error reading GenesisDoc: %v", err))
|
cmn.Exit(cmn.Fmt("Error reading GenesisDoc: %v", err))
|
||||||
}
|
}
|
||||||
return MakeGenesisState(db, genDoc)
|
return MakeGenesisState(db, genDoc)
|
||||||
}
|
}
|
||||||
@ -231,7 +232,7 @@ func MakeGenesisStateFromFile(db dbm.DB, genDocFile string) *State {
|
|||||||
// Used in tests.
|
// Used in tests.
|
||||||
func MakeGenesisState(db dbm.DB, genDoc *types.GenesisDoc) *State {
|
func MakeGenesisState(db dbm.DB, genDoc *types.GenesisDoc) *State {
|
||||||
if len(genDoc.Validators) == 0 {
|
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() {
|
if genDoc.GenesisTime.IsZero() {
|
||||||
|
@ -14,8 +14,8 @@ fi
|
|||||||
|
|
||||||
# some libs are tested with go, others with make
|
# some libs are tested with go, others with make
|
||||||
# TODO: should be all make (post repo merge)
|
# 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_GO_TEST=(tmlibs go-crypto)
|
||||||
LIBS_MAKE_TEST=(tendermint/rpc go-wire abci)
|
LIBS_MAKE_TEST=(go-wire abci)
|
||||||
|
|
||||||
for lib in "${LIBS_GO_TEST[@]}"; do
|
for lib in "${LIBS_GO_TEST[@]}"; do
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user