mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
cleanup go-config/viper and some unnamed imports
This commit is contained in:
parent
72c4be35e8
commit
fcf78a5da7
@ -8,7 +8,6 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
"github.com/tendermint/go-wire"
|
"github.com/tendermint/go-wire"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
"github.com/tendermint/tendermint/proxy"
|
"github.com/tendermint/tendermint/proxy"
|
||||||
|
@ -2,7 +2,6 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
|
||||||
|
|
||||||
tmcfg "github.com/tendermint/tendermint/config/tendermint"
|
tmcfg "github.com/tendermint/tendermint/config/tendermint"
|
||||||
"github.com/tendermint/tmlibs/logger"
|
"github.com/tendermint/tmlibs/logger"
|
||||||
|
@ -7,9 +7,9 @@ import (
|
|||||||
|
|
||||||
"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{
|
||||||
@ -90,11 +90,11 @@ func runNode(cmd *cobra.Command, args []string) error {
|
|||||||
// 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)
|
||||||
|
@ -6,9 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
. "github.com/tendermint/tmlibs/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func getTMRoot(rootDir string) string {
|
func getTMRoot(rootDir string) string {
|
||||||
@ -27,16 +25,16 @@ 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,16 +48,16 @@ func GetConfig(rootDir string) *viper.Viper {
|
|||||||
config.AddConfigPath(rootDir)
|
config.AddConfigPath(rootDir)
|
||||||
err := config.ReadInConfig()
|
err := config.ReadInConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(Fmt("Could not read config from directory %v: %v", rootDir, err))
|
cmn.Exit(cmn.Fmt("Could not read config from directory %v: %v", rootDir, err))
|
||||||
}
|
}
|
||||||
//config.WatchConfig()
|
//config.WatchConfig()
|
||||||
|
|
||||||
// Set defaults or panic
|
// Set defaults or panic
|
||||||
if config.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 config.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.
|
||||||
config.SetDefault("genesis_file", rootDir+"/genesis.json")
|
config.SetDefault("genesis_file", rootDir+"/genesis.json")
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
. "github.com/tendermint/tmlibs/common"
|
. "github.com/tendermint/tmlibs/common"
|
||||||
"github.com/tendermint/tmlibs/logger"
|
"github.com/tendermint/tmlibs/logger"
|
||||||
)
|
)
|
||||||
@ -46,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) {
|
||||||
|
@ -8,8 +8,6 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/config/tendermint_test"
|
"github.com/tendermint/tendermint/config/tendermint_test"
|
||||||
|
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
"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/common"
|
||||||
|
@ -15,7 +15,6 @@ import (
|
|||||||
|
|
||||||
abcicli "github.com/tendermint/abci/client"
|
abcicli "github.com/tendermint/abci/client"
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
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"
|
||||||
|
@ -13,10 +13,9 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
"github.com/tendermint/go-wire"
|
"github.com/tendermint/go-wire"
|
||||||
auto "github.com/tendermint/tmlibs/autofile"
|
auto "github.com/tendermint/tmlibs/autofile"
|
||||||
. "github.com/tendermint/tmlibs/common"
|
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"
|
||||||
@ -110,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
|
||||||
@ -145,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)
|
||||||
@ -223,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
|
||||||
@ -240,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)
|
||||||
@ -268,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.
|
||||||
@ -315,7 +314,7 @@ func (h *Handshaker) ReplayBlocks(appHash []byte, appBlockHeight int, proxyApp p
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PanicSanity("Should never happen")
|
cmn.PanicSanity("Should never happen")
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,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
|
||||||
|
@ -10,13 +10,12 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
bc "github.com/tendermint/tendermint/blockchain"
|
bc "github.com/tendermint/tendermint/blockchain"
|
||||||
mempl "github.com/tendermint/tendermint/mempool"
|
mempl "github.com/tendermint/tendermint/mempool"
|
||||||
"github.com/tendermint/tendermint/proxy"
|
"github.com/tendermint/tendermint/proxy"
|
||||||
sm "github.com/tendermint/tendermint/state"
|
sm "github.com/tendermint/tendermint/state"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
. "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
dbm "github.com/tendermint/tmlibs/db"
|
dbm "github.com/tendermint/tmlibs/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,7 +26,7 @@ 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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,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++ {
|
||||||
@ -151,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), " ")
|
||||||
@ -251,7 +250,7 @@ func newConsensusStateForReplay(config *viper.Viper) *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
|
||||||
@ -260,7 +259,7 @@ func newConsensusStateForReplay(config *viper.Viper) *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())
|
||||||
|
@ -15,7 +15,6 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
"github.com/tendermint/abci/example/dummy"
|
"github.com/tendermint/abci/example/dummy"
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
"github.com/tendermint/go-crypto"
|
"github.com/tendermint/go-crypto"
|
||||||
"github.com/tendermint/go-wire"
|
"github.com/tendermint/go-wire"
|
||||||
"github.com/tendermint/tendermint/config/tendermint_test"
|
"github.com/tendermint/tendermint/config/tendermint_test"
|
||||||
|
@ -12,12 +12,11 @@ import (
|
|||||||
"github.com/ebuchman/fail-test"
|
"github.com/ebuchman/fail-test"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
"github.com/tendermint/go-wire"
|
"github.com/tendermint/go-wire"
|
||||||
"github.com/tendermint/tendermint/proxy"
|
"github.com/tendermint/tendermint/proxy"
|
||||||
sm "github.com/tendermint/tendermint/state"
|
sm "github.com/tendermint/tendermint/state"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
. "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -223,7 +222,7 @@ 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 *viper.Viper
|
config *viper.Viper
|
||||||
proxyAppConn proxy.AppConnConsensus
|
proxyAppConn proxy.AppConnConsensus
|
||||||
@ -277,7 +276,7 @@ func NewConsensusState(config *viper.Viper, state *sm.State, proxyAppConn proxy.
|
|||||||
// 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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,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 {
|
||||||
@ -399,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
|
||||||
@ -520,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
|
||||||
}
|
}
|
||||||
@ -533,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))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,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)
|
||||||
}
|
}
|
||||||
@ -724,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))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -739,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -747,7 +746,7 @@ func (cs *ConsensusState) enterNewRound(height int, round int) {
|
|||||||
log.Warn("Need to set a buffer and log.Warn() here for sanity.", "startTime", cs.StartTime, "now", now)
|
log.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
|
||||||
@ -781,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:
|
||||||
@ -851,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)
|
||||||
@ -907,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -925,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)
|
||||||
@ -968,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:
|
||||||
@ -994,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:
|
||||||
@ -1025,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.
|
||||||
@ -1059,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
|
||||||
@ -1088,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:
|
||||||
@ -1110,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:
|
||||||
@ -1129,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.
|
||||||
@ -1156,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()
|
||||||
@ -1177,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1185,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
|
||||||
|
|
||||||
@ -1394,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,
|
||||||
@ -1475,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()
|
||||||
|
18
glide.lock
generated
18
glide.lock
generated
@ -1,12 +1,10 @@
|
|||||||
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:
|
||||||
@ -55,7 +53,7 @@ imports:
|
|||||||
- name: github.com/pelletier/go-buffruneio
|
- name: github.com/pelletier/go-buffruneio
|
||||||
version: c37440a7cf42ac63b919c752ca73a85067e05992
|
version: c37440a7cf42ac63b919c752ca73a85067e05992
|
||||||
- name: github.com/pelletier/go-toml
|
- name: github.com/pelletier/go-toml
|
||||||
version: fe206efb84b2bc8e8cfafe6b4c1826622be969e3
|
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
|
||||||
@ -67,7 +65,7 @@ imports:
|
|||||||
subpackages:
|
subpackages:
|
||||||
- mem
|
- mem
|
||||||
- name: github.com/spf13/cast
|
- name: github.com/spf13/cast
|
||||||
version: ce135a4ebeee6cfe9a26c93ee0d37825f26113c7
|
version: acbeb36b902d72a7a4c18e8f3241075e7ab763e4
|
||||||
- name: github.com/spf13/cobra
|
- name: github.com/spf13/cobra
|
||||||
version: fcd0c5a1df88f5d6784cb4feead962c3f3d0b66c
|
version: fcd0c5a1df88f5d6784cb4feead962c3f3d0b66c
|
||||||
- name: github.com/spf13/jwalterweatherman
|
- name: github.com/spf13/jwalterweatherman
|
||||||
@ -75,7 +73,7 @@ imports:
|
|||||||
- name: github.com/spf13/pflag
|
- name: github.com/spf13/pflag
|
||||||
version: 9ff6c6923cfffbcd502984b8e0c80539a94968b7
|
version: 9ff6c6923cfffbcd502984b8e0c80539a94968b7
|
||||||
- name: github.com/spf13/viper
|
- name: github.com/spf13/viper
|
||||||
version: 84f94806c67f59dd7ae87bc5351f7a9c94a4558d
|
version: 5d46e70da8c0b6f812e0b170b7a985753b5c63cb
|
||||||
- name: github.com/stretchr/testify
|
- name: github.com/stretchr/testify
|
||||||
version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0
|
version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0
|
||||||
subpackages:
|
subpackages:
|
||||||
@ -97,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
|
||||||
@ -109,10 +107,6 @@ imports:
|
|||||||
subpackages:
|
subpackages:
|
||||||
- edwards25519
|
- edwards25519
|
||||||
- extra25519
|
- extra25519
|
||||||
- name: github.com/tendermint/go-common
|
|
||||||
version: 6af2364fa91ef2f3afc8ba0db33b66d9d3ae006c
|
|
||||||
subpackages:
|
|
||||||
- test
|
|
||||||
- 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
|
||||||
|
14
glide.yaml
14
glide.yaml
@ -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
|
||||||
@ -39,17 +38,6 @@ import:
|
|||||||
- flowrate
|
- flowrate
|
||||||
- logger
|
- logger
|
||||||
- merkle
|
- merkle
|
||||||
- package: github.com/gogo/protobuf
|
|
||||||
version: ^0.3
|
|
||||||
subpackages:
|
|
||||||
- proto
|
|
||||||
- package: github.com/gorilla/websocket
|
|
||||||
version: ^1.1.0
|
|
||||||
- package: github.com/spf13/cobra
|
|
||||||
- package: github.com/spf13/viper
|
|
||||||
- package: github.com/spf13/pflag
|
|
||||||
- package: github.com/pkg/errors
|
|
||||||
version: ^0.8.0
|
|
||||||
- package: golang.org/x/crypto
|
- package: golang.org/x/crypto
|
||||||
subpackages:
|
subpackages:
|
||||||
- nacl/box
|
- nacl/box
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
"github.com/tendermint/tendermint/proxy"
|
"github.com/tendermint/tendermint/proxy"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
auto "github.com/tendermint/tmlibs/autofile"
|
auto "github.com/tendermint/tmlibs/autofile"
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
"github.com/tendermint/go-wire"
|
"github.com/tendermint/go-wire"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
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"
|
||||||
bc "github.com/tendermint/tendermint/blockchain"
|
bc "github.com/tendermint/tendermint/blockchain"
|
||||||
|
@ -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")
|
||||||
|
@ -2,7 +2,6 @@ package proxy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package core
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
|
|
||||||
crypto "github.com/tendermint/go-crypto"
|
crypto "github.com/tendermint/go-crypto"
|
||||||
"github.com/tendermint/tendermint/consensus"
|
"github.com/tendermint/tendermint/consensus"
|
||||||
|
@ -15,7 +15,6 @@ import (
|
|||||||
logger "github.com/tendermint/tmlibs/logger"
|
logger "github.com/tendermint/tmlibs/logger"
|
||||||
|
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
cfg "github.com/tendermint/go-config"
|
|
||||||
"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"
|
||||||
|
@ -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(
|
||||||
|
@ -8,8 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
cfg "github.com/tendermint/go-config"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
. "github.com/tendermint/tmlibs/common"
|
|
||||||
dbm "github.com/tendermint/tmlibs/db"
|
dbm "github.com/tendermint/tmlibs/db"
|
||||||
|
|
||||||
"github.com/tendermint/go-wire"
|
"github.com/tendermint/go-wire"
|
||||||
@ -66,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.
|
||||||
}
|
}
|
||||||
@ -110,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.
|
||||||
}
|
}
|
||||||
@ -125,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()
|
||||||
}
|
}
|
||||||
@ -205,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()
|
||||||
}
|
}
|
||||||
@ -219,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)
|
||||||
}
|
}
|
||||||
@ -233,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