Browse Source

libs/common: remove deprecated PanicXXX functions (#3595)

* Remove deprecated PanicXXX functions from codebase

As per discussion over
[here](https://github.com/tendermint/tendermint/pull/3456#discussion_r278423492),
we need to remove these `PanicXXX` functions and eliminate our
dependence on them. In this PR, each and every `PanicXXX` function call
is replaced with a simple `panic` call.

* add a changelog entry
pull/3597/head
Thane Thomson 6 years ago
committed by Anton Kaliaev
parent
commit
70592cc4d8
21 changed files with 57 additions and 97 deletions
  1. +2
    -1
      CHANGELOG_PENDING.md
  2. +5
    -5
      blockchain/store.go
  3. +3
    -3
      config/toml.go
  4. +2
    -2
      consensus/reactor.go
  5. +15
    -15
      consensus/state.go
  6. +3
    -5
      consensus/types/height_vote_set.go
  7. +2
    -3
      crypto/xsalsa20symmetric/symmetric.go
  8. +0
    -32
      libs/common/errors.go
  9. +1
    -1
      libs/common/random.go
  10. +1
    -2
      libs/common/service.go
  11. +4
    -6
      libs/db/go_level_db.go
  12. +2
    -2
      node/node.go
  13. +1
    -1
      p2p/conn/connection.go
  14. +1
    -3
      p2p/netaddress.go
  15. +2
    -2
      p2p/pex/file.go
  16. +1
    -1
      p2p/switch.go
  17. +1
    -1
      p2p/trust/store.go
  18. +1
    -1
      types/part_set.go
  19. +1
    -2
      types/validator.go
  20. +1
    -1
      types/vote.go
  21. +8
    -8
      types/vote_set.go

+ 2
- 1
CHANGELOG_PENDING.md View File

@ -9,6 +9,7 @@
* Apps * Apps
* Go API * Go API
- [libs/common] Removed PanicSanity, PanicCrisis, PanicConsensus and PanicQ
* Blockchain Protocol * Blockchain Protocol
@ -25,4 +26,4 @@
- [state] [\#3537](https://github.com/tendermint/tendermint/pull/3537#issuecomment-482711833) LoadValidators: do not return an empty validator set - [state] [\#3537](https://github.com/tendermint/tendermint/pull/3537#issuecomment-482711833) LoadValidators: do not return an empty validator set
- [p2p] \#3532 limit the number of attempts to connect to a peer in seed mode - [p2p] \#3532 limit the number of attempts to connect to a peer in seed mode
to 16 (as a result, the node will stop retrying after a 35 hours time window) to 16 (as a result, the node will stop retrying after a 35 hours time window)
- [consensus] \#2723, \#3451 and \#3317 Fix non-deterministic tests
- [consensus] \#2723, \#3451 and \#3317 Fix non-deterministic tests

+ 5
- 5
blockchain/store.go View File

@ -144,14 +144,14 @@ func (bs *BlockStore) LoadSeenCommit(height int64) *types.Commit {
// most recent height. Otherwise they'd stall at H-1. // most recent height. Otherwise they'd stall at H-1.
func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) { func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) {
if block == nil { if block == nil {
cmn.PanicSanity("BlockStore can only save a non-nil block")
panic("BlockStore can only save a non-nil block")
} }
height := block.Height height := block.Height
if g, w := height, bs.Height()+1; g != w { if g, w := height, bs.Height()+1; g != w {
cmn.PanicSanity(fmt.Sprintf("BlockStore can only save contiguous blocks. Wanted %v, got %v", w, g))
panic(fmt.Sprintf("BlockStore can only save contiguous blocks. Wanted %v, got %v", w, g))
} }
if !blockParts.IsComplete() { if !blockParts.IsComplete() {
cmn.PanicSanity(fmt.Sprintf("BlockStore can only save complete block part sets"))
panic(fmt.Sprintf("BlockStore can only save complete block part sets"))
} }
// Save block meta // Save block meta
@ -188,7 +188,7 @@ func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, s
func (bs *BlockStore) saveBlockPart(height int64, index int, part *types.Part) { func (bs *BlockStore) saveBlockPart(height int64, index int, part *types.Part) {
if height != bs.Height()+1 { if height != bs.Height()+1 {
cmn.PanicSanity(fmt.Sprintf("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.Height()+1, height))
panic(fmt.Sprintf("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.Height()+1, height))
} }
partBytes := cdc.MustMarshalBinaryBare(part) partBytes := cdc.MustMarshalBinaryBare(part)
bs.db.Set(calcBlockPartKey(height, index), partBytes) bs.db.Set(calcBlockPartKey(height, index), partBytes)
@ -224,7 +224,7 @@ type BlockStoreStateJSON struct {
func (bsj BlockStoreStateJSON) Save(db dbm.DB) { func (bsj BlockStoreStateJSON) Save(db dbm.DB) {
bytes, err := cdc.MarshalJSON(bsj) bytes, err := cdc.MarshalJSON(bsj)
if err != nil { if err != nil {
cmn.PanicSanity(fmt.Sprintf("Could not marshal state bytes: %v", err))
panic(fmt.Sprintf("Could not marshal state bytes: %v", err))
} }
db.SetSync(blockStoreKey, bytes) db.SetSync(blockStoreKey, bytes)
} }


+ 3
- 3
config/toml.go View File

@ -28,13 +28,13 @@ func init() {
// and panics if it fails. // and panics if it fails.
func EnsureRoot(rootDir string) { func EnsureRoot(rootDir string) {
if err := cmn.EnsureDir(rootDir, DefaultDirPerm); err != nil { if err := cmn.EnsureDir(rootDir, DefaultDirPerm); err != nil {
cmn.PanicSanity(err.Error())
panic(err.Error())
} }
if err := cmn.EnsureDir(filepath.Join(rootDir, defaultConfigDir), DefaultDirPerm); err != nil { if err := cmn.EnsureDir(filepath.Join(rootDir, defaultConfigDir), DefaultDirPerm); err != nil {
cmn.PanicSanity(err.Error())
panic(err.Error())
} }
if err := cmn.EnsureDir(filepath.Join(rootDir, defaultDataDir), DefaultDirPerm); err != nil { if err := cmn.EnsureDir(filepath.Join(rootDir, defaultDataDir), DefaultDirPerm); err != nil {
cmn.PanicSanity(err.Error())
panic(err.Error())
} }
configFilePath := filepath.Join(rootDir, defaultConfigFilePath) configFilePath := filepath.Join(rootDir, defaultConfigFilePath)


+ 2
- 2
consensus/reactor.go View File

@ -491,7 +491,7 @@ OUTER_LOOP:
if prs.ProposalBlockParts == nil { if prs.ProposalBlockParts == nil {
blockMeta := conR.conS.blockStore.LoadBlockMeta(prs.Height) blockMeta := conR.conS.blockStore.LoadBlockMeta(prs.Height)
if blockMeta == nil { if blockMeta == nil {
cmn.PanicCrisis(fmt.Sprintf("Failed to load block %d when blockStore is at %d",
panic(fmt.Sprintf("Failed to load block %d when blockStore is at %d",
prs.Height, conR.conS.blockStore.Height())) prs.Height, conR.conS.blockStore.Height()))
} }
ps.InitProposalBlockParts(blockMeta.BlockID.PartsHeader) ps.InitProposalBlockParts(blockMeta.BlockID.PartsHeader)
@ -1110,7 +1110,7 @@ func (ps *PeerState) ensureCatchupCommitRound(height int64, round int, numValida
NOTE: This is wrong, 'round' could change. NOTE: This is wrong, 'round' could change.
e.g. if orig round is not the same as block LastCommit round. e.g. if orig round is not the same as block LastCommit round.
if ps.CatchupCommitRound != -1 && ps.CatchupCommitRound != round { if ps.CatchupCommitRound != -1 && ps.CatchupCommitRound != round {
cmn.PanicSanity(fmt.Sprintf("Conflicting CatchupCommitRound. Height: %v, Orig: %v, New: %v", height, ps.CatchupCommitRound, round))
panic(fmt.Sprintf("Conflicting CatchupCommitRound. Height: %v, Orig: %v, New: %v", height, ps.CatchupCommitRound, round))
} }
*/ */
if ps.PRS.CatchupCommitRound == round { if ps.PRS.CatchupCommitRound == round {


+ 15
- 15
consensus/state.go View File

@ -491,11 +491,11 @@ func (cs *ConsensusState) reconstructLastCommit(state sm.State) {
} }
added, err := lastPrecommits.AddVote(seenCommit.ToVote(precommit)) added, err := lastPrecommits.AddVote(seenCommit.ToVote(precommit))
if !added || err != nil { if !added || err != nil {
cmn.PanicCrisis(fmt.Sprintf("Failed to reconstruct LastCommit: %v", err))
panic(fmt.Sprintf("Failed to reconstruct LastCommit: %v", err))
} }
} }
if !lastPrecommits.HasTwoThirdsMajority() { if !lastPrecommits.HasTwoThirdsMajority() {
cmn.PanicSanity("Failed to reconstruct LastCommit: Does not have +2/3 maj")
panic("Failed to reconstruct LastCommit: Does not have +2/3 maj")
} }
cs.LastCommit = lastPrecommits cs.LastCommit = lastPrecommits
} }
@ -504,13 +504,13 @@ func (cs *ConsensusState) reconstructLastCommit(state sm.State) {
// The round becomes 0 and cs.Step becomes cstypes.RoundStepNewHeight. // The round becomes 0 and cs.Step becomes cstypes.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 {
cmn.PanicSanity(fmt.Sprintf("updateToState() expected state height of %v but found %v",
panic(fmt.Sprintf("updateToState() expected state height of %v but found %v",
cs.Height, state.LastBlockHeight)) cs.Height, state.LastBlockHeight))
} }
if !cs.state.IsEmpty() && cs.state.LastBlockHeight+1 != cs.Height { if !cs.state.IsEmpty() && 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?!
cmn.PanicSanity(fmt.Sprintf("Inconsistent cs.state.LastBlockHeight+1 %v vs cs.Height %v",
panic(fmt.Sprintf("Inconsistent cs.state.LastBlockHeight+1 %v vs cs.Height %v",
cs.state.LastBlockHeight+1, cs.Height)) cs.state.LastBlockHeight+1, cs.Height))
} }
@ -530,7 +530,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() {
cmn.PanicSanity("updateToState(state) called but last Precommit round didn't have +2/3")
panic("updateToState(state) called but last Precommit round didn't have +2/3")
} }
lastPrecommits = cs.Votes.Precommits(cs.CommitRound) lastPrecommits = cs.Votes.Precommits(cs.CommitRound)
} }
@ -1047,7 +1047,7 @@ func (cs *ConsensusState) enterPrevoteWait(height int64, round int) {
return return
} }
if !cs.Votes.Prevotes(round).HasTwoThirdsAny() { if !cs.Votes.Prevotes(round).HasTwoThirdsAny() {
cmn.PanicSanity(fmt.Sprintf("enterPrevoteWait(%v/%v), but Prevotes does not have any +2/3 votes", height, round))
panic(fmt.Sprintf("enterPrevoteWait(%v/%v), but Prevotes does not have any +2/3 votes", height, round))
} }
logger.Info(fmt.Sprintf("enterPrevoteWait(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) logger.Info(fmt.Sprintf("enterPrevoteWait(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))
@ -1103,7 +1103,7 @@ func (cs *ConsensusState) enterPrecommit(height int64, 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 {
cmn.PanicSanity(fmt.Sprintf("This POLRound should be %v but got %v", round, polRound))
panic(fmt.Sprintf("This POLRound should be %v but got %v", round, polRound))
} }
// +2/3 prevoted nil. Unlock and precommit nil. // +2/3 prevoted nil. Unlock and precommit nil.
@ -1137,7 +1137,7 @@ func (cs *ConsensusState) enterPrecommit(height int64, round int) {
logger.Info("enterPrecommit: +2/3 prevoted proposal block. Locking", "hash", blockID.Hash) logger.Info("enterPrecommit: +2/3 prevoted proposal block. Locking", "hash", blockID.Hash)
// Validate the block. // Validate the block.
if err := cs.blockExec.ValidateBlock(cs.state, cs.ProposalBlock); err != nil { if err := cs.blockExec.ValidateBlock(cs.state, cs.ProposalBlock); err != nil {
cmn.PanicConsensus(fmt.Sprintf("enterPrecommit: +2/3 prevoted for an invalid block: %v", err))
panic(fmt.Sprintf("enterPrecommit: +2/3 prevoted for an invalid block: %v", err))
} }
cs.LockedRound = round cs.LockedRound = round
cs.LockedBlock = cs.ProposalBlock cs.LockedBlock = cs.ProposalBlock
@ -1175,7 +1175,7 @@ func (cs *ConsensusState) enterPrecommitWait(height int64, round int) {
return return
} }
if !cs.Votes.Precommits(round).HasTwoThirdsAny() { if !cs.Votes.Precommits(round).HasTwoThirdsAny() {
cmn.PanicSanity(fmt.Sprintf("enterPrecommitWait(%v/%v), but Precommits does not have any +2/3 votes", height, round))
panic(fmt.Sprintf("enterPrecommitWait(%v/%v), but Precommits does not have any +2/3 votes", height, round))
} }
logger.Info(fmt.Sprintf("enterPrecommitWait(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) logger.Info(fmt.Sprintf("enterPrecommitWait(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))
@ -1214,7 +1214,7 @@ func (cs *ConsensusState) enterCommit(height int64, commitRound int) {
blockID, ok := cs.Votes.Precommits(commitRound).TwoThirdsMajority() blockID, ok := cs.Votes.Precommits(commitRound).TwoThirdsMajority()
if !ok { if !ok {
cmn.PanicSanity("RunActionCommit() expects +2/3 precommits")
panic("RunActionCommit() expects +2/3 precommits")
} }
// The Locked* fields no longer matter. // The Locked* fields no longer matter.
@ -1247,7 +1247,7 @@ func (cs *ConsensusState) tryFinalizeCommit(height int64) {
logger := cs.Logger.With("height", height) logger := cs.Logger.With("height", height)
if cs.Height != height { if cs.Height != height {
cmn.PanicSanity(fmt.Sprintf("tryFinalizeCommit() cs.Height: %v vs height: %v", cs.Height, height))
panic(fmt.Sprintf("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()
@ -1277,16 +1277,16 @@ func (cs *ConsensusState) finalizeCommit(height int64) {
block, blockParts := cs.ProposalBlock, cs.ProposalBlockParts block, blockParts := cs.ProposalBlock, cs.ProposalBlockParts
if !ok { if !ok {
cmn.PanicSanity(fmt.Sprintf("Cannot finalizeCommit, commit does not have two thirds majority"))
panic(fmt.Sprintf("Cannot finalizeCommit, commit does not have two thirds majority"))
} }
if !blockParts.HasHeader(blockID.PartsHeader) { if !blockParts.HasHeader(blockID.PartsHeader) {
cmn.PanicSanity(fmt.Sprintf("Expected ProposalBlockParts header to be commit header"))
panic(fmt.Sprintf("Expected ProposalBlockParts header to be commit header"))
} }
if !block.HashesTo(blockID.Hash) { if !block.HashesTo(blockID.Hash) {
cmn.PanicSanity(fmt.Sprintf("Cannot finalizeCommit, ProposalBlock does not hash to commit hash"))
panic(fmt.Sprintf("Cannot finalizeCommit, ProposalBlock does not hash to commit hash"))
} }
if err := cs.blockExec.ValidateBlock(cs.state, block); err != nil { if err := cs.blockExec.ValidateBlock(cs.state, block); err != nil {
cmn.PanicConsensus(fmt.Sprintf("+2/3 committed an invalid block: %v", err))
panic(fmt.Sprintf("+2/3 committed an invalid block: %v", err))
} }
cs.Logger.Info(fmt.Sprintf("Finalizing commit of block with %d txs", block.NumTxs), cs.Logger.Info(fmt.Sprintf("Finalizing commit of block with %d txs", block.NumTxs),


+ 3
- 5
consensus/types/height_vote_set.go View File

@ -6,7 +6,6 @@ import (
"strings" "strings"
"sync" "sync"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )
@ -83,7 +82,7 @@ func (hvs *HeightVoteSet) SetRound(round int) {
hvs.mtx.Lock() hvs.mtx.Lock()
defer hvs.mtx.Unlock() defer hvs.mtx.Unlock()
if hvs.round != 0 && (round < hvs.round+1) { if hvs.round != 0 && (round < hvs.round+1) {
cmn.PanicSanity("SetRound() must increment hvs.round")
panic("SetRound() must increment hvs.round")
} }
for r := hvs.round + 1; r <= round; r++ { for r := hvs.round + 1; r <= round; r++ {
if _, ok := hvs.roundVoteSets[r]; ok { if _, ok := hvs.roundVoteSets[r]; ok {
@ -96,7 +95,7 @@ func (hvs *HeightVoteSet) SetRound(round int) {
func (hvs *HeightVoteSet) addRound(round int) { func (hvs *HeightVoteSet) addRound(round int) {
if _, ok := hvs.roundVoteSets[round]; ok { if _, ok := hvs.roundVoteSets[round]; ok {
cmn.PanicSanity("addRound() for an existing round")
panic("addRound() for an existing round")
} }
// log.Debug("addRound(round)", "round", round) // log.Debug("addRound(round)", "round", round)
prevotes := types.NewVoteSet(hvs.chainID, hvs.height, round, types.PrevoteType, hvs.valSet) prevotes := types.NewVoteSet(hvs.chainID, hvs.height, round, types.PrevoteType, hvs.valSet)
@ -169,8 +168,7 @@ func (hvs *HeightVoteSet) getVoteSet(round int, type_ types.SignedMsgType) *type
case types.PrecommitType: case types.PrecommitType:
return rvs.Precommits return rvs.Precommits
default: default:
cmn.PanicSanity(fmt.Sprintf("Unexpected vote type %X", type_))
return nil
panic(fmt.Sprintf("Unexpected vote type %X", type_))
} }
} }


+ 2
- 3
crypto/xsalsa20symmetric/symmetric.go View File

@ -7,7 +7,6 @@ import (
"golang.org/x/crypto/nacl/secretbox" "golang.org/x/crypto/nacl/secretbox"
"github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto"
cmn "github.com/tendermint/tendermint/libs/common"
) )
// TODO, make this into a struct that implements crypto.Symmetric. // TODO, make this into a struct that implements crypto.Symmetric.
@ -19,7 +18,7 @@ const secretLen = 32
// The ciphertext is (secretbox.Overhead + 24) bytes longer than the plaintext. // The ciphertext is (secretbox.Overhead + 24) bytes longer than the plaintext.
func EncryptSymmetric(plaintext []byte, secret []byte) (ciphertext []byte) { func EncryptSymmetric(plaintext []byte, secret []byte) (ciphertext []byte) {
if len(secret) != secretLen { if len(secret) != secretLen {
cmn.PanicSanity(fmt.Sprintf("Secret must be 32 bytes long, got len %v", len(secret)))
panic(fmt.Sprintf("Secret must be 32 bytes long, got len %v", len(secret)))
} }
nonce := crypto.CRandBytes(nonceLen) nonce := crypto.CRandBytes(nonceLen)
nonceArr := [nonceLen]byte{} nonceArr := [nonceLen]byte{}
@ -36,7 +35,7 @@ func EncryptSymmetric(plaintext []byte, secret []byte) (ciphertext []byte) {
// The ciphertext is (secretbox.Overhead + 24) bytes longer than the plaintext. // The ciphertext is (secretbox.Overhead + 24) bytes longer than the plaintext.
func DecryptSymmetric(ciphertext []byte, secret []byte) (plaintext []byte, err error) { func DecryptSymmetric(ciphertext []byte, secret []byte) (plaintext []byte, err error) {
if len(secret) != secretLen { if len(secret) != secretLen {
cmn.PanicSanity(fmt.Sprintf("Secret must be 32 bytes long, got len %v", len(secret)))
panic(fmt.Sprintf("Secret must be 32 bytes long, got len %v", len(secret)))
} }
if len(ciphertext) <= secretbox.Overhead+nonceLen { if len(ciphertext) <= secretbox.Overhead+nonceLen {
return nil, errors.New("Ciphertext is too short") return nil, errors.New("Ciphertext is too short")


+ 0
- 32
libs/common/errors.go View File

@ -212,35 +212,3 @@ func (fe FmtError) String() string {
func (fe FmtError) Format() string { func (fe FmtError) Format() string {
return fe.format return fe.format
} }
//----------------------------------------
// Panic wrappers
// XXX DEPRECATED
// A panic resulting from a sanity check means there is a programmer error
// and some guarantee is not satisfied.
// XXX DEPRECATED
func PanicSanity(v interface{}) {
panic(fmt.Sprintf("Panicked on a Sanity Check: %v", v))
}
// A panic here means something has gone horribly wrong, in the form of data corruption or
// failure of the operating system. In a correct/healthy system, these should never fire.
// If they do, it's indicative of a much more serious problem.
// XXX DEPRECATED
func PanicCrisis(v interface{}) {
panic(fmt.Sprintf("Panicked on a Crisis: %v", v))
}
// Indicates a failure of consensus. Someone was malicious or something has
// gone horribly wrong. These should really boot us into an "emergency-recover" mode
// XXX DEPRECATED
func PanicConsensus(v interface{}) {
panic(fmt.Sprintf("Panicked on a Consensus Failure: %v", v))
}
// For those times when we're not sure if we should panic
// XXX DEPRECATED
func PanicQ(v interface{}) {
panic(fmt.Sprintf("Panicked questionably: %v", v))
}

+ 1
- 1
libs/common/random.go View File

@ -300,7 +300,7 @@ func cRandBytes(numBytes int) []byte {
b := make([]byte, numBytes) b := make([]byte, numBytes)
_, err := crand.Read(b) _, err := crand.Read(b)
if err != nil { if err != nil {
PanicCrisis(err)
panic(err)
} }
return b return b
} }

+ 1
- 2
libs/common/service.go View File

@ -194,8 +194,7 @@ func (bs *BaseService) Reset() error {
// OnReset implements Service by panicking. // OnReset implements Service by panicking.
func (bs *BaseService) OnReset() error { func (bs *BaseService) OnReset() error {
PanicSanity("The service cannot be reset")
return nil
panic("The service cannot be reset")
} }
// IsRunning implements Service by returning true or false depending on the // IsRunning implements Service by returning true or false depending on the


+ 4
- 6
libs/db/go_level_db.go View File

@ -9,8 +9,6 @@ import (
"github.com/syndtr/goleveldb/leveldb/errors" "github.com/syndtr/goleveldb/leveldb/errors"
"github.com/syndtr/goleveldb/leveldb/iterator" "github.com/syndtr/goleveldb/leveldb/iterator"
"github.com/syndtr/goleveldb/leveldb/opt" "github.com/syndtr/goleveldb/leveldb/opt"
cmn "github.com/tendermint/tendermint/libs/common"
) )
func init() { func init() {
@ -67,7 +65,7 @@ func (db *GoLevelDB) Set(key []byte, value []byte) {
value = nonNilBytes(value) value = nonNilBytes(value)
err := db.db.Put(key, value, nil) err := db.db.Put(key, value, nil)
if err != nil { if err != nil {
cmn.PanicCrisis(err)
panic(err)
} }
} }
@ -77,7 +75,7 @@ func (db *GoLevelDB) SetSync(key []byte, value []byte) {
value = nonNilBytes(value) value = nonNilBytes(value)
err := db.db.Put(key, value, &opt.WriteOptions{Sync: true}) err := db.db.Put(key, value, &opt.WriteOptions{Sync: true})
if err != nil { if err != nil {
cmn.PanicCrisis(err)
panic(err)
} }
} }
@ -86,7 +84,7 @@ func (db *GoLevelDB) Delete(key []byte) {
key = nonNilBytes(key) key = nonNilBytes(key)
err := db.db.Delete(key, nil) err := db.db.Delete(key, nil)
if err != nil { if err != nil {
cmn.PanicCrisis(err)
panic(err)
} }
} }
@ -95,7 +93,7 @@ func (db *GoLevelDB) DeleteSync(key []byte) {
key = nonNilBytes(key) key = nonNilBytes(key)
err := db.db.Delete(key, &opt.WriteOptions{Sync: true}) err := db.db.Delete(key, &opt.WriteOptions{Sync: true})
if err != nil { if err != nil {
cmn.PanicCrisis(err)
panic(err)
} }
} }


+ 2
- 2
node/node.go View File

@ -912,7 +912,7 @@ func loadGenesisDoc(db dbm.DB) (*types.GenesisDoc, error) {
var genDoc *types.GenesisDoc var genDoc *types.GenesisDoc
err := cdc.UnmarshalJSON(bytes, &genDoc) err := cdc.UnmarshalJSON(bytes, &genDoc)
if err != nil { if err != nil {
cmn.PanicCrisis(fmt.Sprintf("Failed to load genesis doc due to unmarshaling error: %v (bytes: %X)", err, bytes))
panic(fmt.Sprintf("Failed to load genesis doc due to unmarshaling error: %v (bytes: %X)", err, bytes))
} }
return genDoc, nil return genDoc, nil
} }
@ -921,7 +921,7 @@ func loadGenesisDoc(db dbm.DB) (*types.GenesisDoc, error) {
func saveGenesisDoc(db dbm.DB, genDoc *types.GenesisDoc) { func saveGenesisDoc(db dbm.DB, genDoc *types.GenesisDoc) {
bytes, err := cdc.MarshalJSON(genDoc) bytes, err := cdc.MarshalJSON(genDoc)
if err != nil { if err != nil {
cmn.PanicCrisis(fmt.Sprintf("Failed to save genesis doc due to marshaling error: %v", err))
panic(fmt.Sprintf("Failed to save genesis doc due to marshaling error: %v", err))
} }
db.SetSync(genesisDocKey, bytes) db.SetSync(genesisDocKey, bytes)
} }


+ 1
- 1
p2p/conn/connection.go View File

@ -707,7 +707,7 @@ type Channel struct {
func newChannel(conn *MConnection, desc ChannelDescriptor) *Channel { func newChannel(conn *MConnection, desc ChannelDescriptor) *Channel {
desc = desc.FillDefaults() desc = desc.FillDefaults()
if desc.Priority <= 0 { if desc.Priority <= 0 {
cmn.PanicSanity("Channel default priority must be a positive integer")
panic("Channel default priority must be a positive integer")
} }
return &Channel{ return &Channel{
conn: conn, conn: conn,


+ 1
- 3
p2p/netaddress.go View File

@ -14,8 +14,6 @@ import (
"time" "time"
"errors" "errors"
cmn "github.com/tendermint/tendermint/libs/common"
) )
// NetAddress defines information about a peer on the network // NetAddress defines information about a peer on the network
@ -48,7 +46,7 @@ func NewNetAddress(id ID, addr net.Addr) *NetAddress {
tcpAddr, ok := addr.(*net.TCPAddr) tcpAddr, ok := addr.(*net.TCPAddr)
if !ok { if !ok {
if flag.Lookup("test.v") == nil { // normal run if flag.Lookup("test.v") == nil { // normal run
cmn.PanicSanity(fmt.Sprintf("Only TCPAddrs are supported. Got: %v", addr))
panic(fmt.Sprintf("Only TCPAddrs are supported. Got: %v", addr))
} else { // in testing } else { // in testing
netAddr := NewNetAddressIPPort(net.IP("0.0.0.0"), 0) netAddr := NewNetAddressIPPort(net.IP("0.0.0.0"), 0)
netAddr.ID = id netAddr.ID = id


+ 2
- 2
p2p/pex/file.go View File

@ -53,14 +53,14 @@ func (a *addrBook) loadFromFile(filePath string) bool {
// Load addrBookJSON{} // Load addrBookJSON{}
r, err := os.Open(filePath) r, err := os.Open(filePath)
if err != nil { if err != nil {
cmn.PanicCrisis(fmt.Sprintf("Error opening file %s: %v", filePath, err))
panic(fmt.Sprintf("Error opening file %s: %v", filePath, err))
} }
defer r.Close() // nolint: errcheck defer r.Close() // nolint: errcheck
aJSON := &addrBookJSON{} aJSON := &addrBookJSON{}
dec := json.NewDecoder(r) dec := json.NewDecoder(r)
err = dec.Decode(aJSON) err = dec.Decode(aJSON)
if err != nil { if err != nil {
cmn.PanicCrisis(fmt.Sprintf("Error reading file %s: %v", filePath, err))
panic(fmt.Sprintf("Error reading file %s: %v", filePath, err))
} }
// Restore all the fields... // Restore all the fields...


+ 1
- 1
p2p/switch.go View File

@ -155,7 +155,7 @@ func (sw *Switch) AddReactor(name string, reactor Reactor) Reactor {
for _, chDesc := range reactorChannels { for _, chDesc := range reactorChannels {
chID := chDesc.ID chID := chDesc.ID
if sw.reactorsByCh[chID] != nil { if sw.reactorsByCh[chID] != nil {
cmn.PanicSanity(fmt.Sprintf("Channel %X has multiple reactors %v & %v", chID, sw.reactorsByCh[chID], reactor))
panic(fmt.Sprintf("Channel %X has multiple reactors %v & %v", chID, sw.reactorsByCh[chID], reactor))
} }
sw.chDescs = append(sw.chDescs, chDesc) sw.chDescs = append(sw.chDescs, chDesc)
sw.reactorsByCh[chID] = reactor sw.reactorsByCh[chID] = reactor


+ 1
- 1
p2p/trust/store.go View File

@ -156,7 +156,7 @@ func (tms *TrustMetricStore) loadFromDB() bool {
peers := make(map[string]MetricHistoryJSON) peers := make(map[string]MetricHistoryJSON)
err := json.Unmarshal(bytes, &peers) err := json.Unmarshal(bytes, &peers)
if err != nil { if err != nil {
cmn.PanicCrisis(fmt.Sprintf("Could not unmarshal Trust Metric Store DB data: %v", err))
panic(fmt.Sprintf("Could not unmarshal Trust Metric Store DB data: %v", err))
} }
// If history data exists in the file, // If history data exists in the file,


+ 1
- 1
types/part_set.go View File

@ -226,7 +226,7 @@ func (ps *PartSet) IsComplete() bool {
func (ps *PartSet) GetReader() io.Reader { func (ps *PartSet) GetReader() io.Reader {
if !ps.IsComplete() { if !ps.IsComplete() {
cmn.PanicSanity("Cannot GetReader() on incomplete PartSet")
panic("Cannot GetReader() on incomplete PartSet")
} }
return NewPartSetReader(ps.parts) return NewPartSetReader(ps.parts)
} }


+ 1
- 2
types/validator.go View File

@ -52,8 +52,7 @@ func (v *Validator) CompareProposerPriority(other *Validator) *Validator {
} else if result > 0 { } else if result > 0 {
return other return other
} else { } else {
cmn.PanicSanity("Cannot compare identical validators")
return nil
panic("Cannot compare identical validators")
} }
} }
} }


+ 1
- 1
types/vote.go View File

@ -93,7 +93,7 @@ func (vote *Vote) String() string {
case PrecommitType: case PrecommitType:
typeString = "Precommit" typeString = "Precommit"
default: default:
cmn.PanicSanity("Unknown vote type")
panic("Unknown vote type")
} }
return fmt.Sprintf("Vote{%v:%X %v/%02d/%v(%v) %X %X @ %s}", return fmt.Sprintf("Vote{%v:%X %v/%02d/%v(%v) %X %X @ %s}",


+ 8
- 8
types/vote_set.go View File

@ -70,7 +70,7 @@ type VoteSet struct {
// Constructs a new VoteSet struct used to accumulate votes for given height/round. // Constructs a new VoteSet struct used to accumulate votes for given height/round.
func NewVoteSet(chainID string, height int64, round int, type_ SignedMsgType, valSet *ValidatorSet) *VoteSet { func NewVoteSet(chainID string, height int64, round int, type_ SignedMsgType, valSet *ValidatorSet) *VoteSet {
if height == 0 { if height == 0 {
cmn.PanicSanity("Cannot make VoteSet for height == 0, doesn't make sense.")
panic("Cannot make VoteSet for height == 0, doesn't make sense.")
} }
return &VoteSet{ return &VoteSet{
chainID: chainID, chainID: chainID,
@ -130,7 +130,7 @@ func (voteSet *VoteSet) Size() int {
// NOTE: Vote must not be nil // NOTE: Vote must not be nil
func (voteSet *VoteSet) AddVote(vote *Vote) (added bool, err error) { func (voteSet *VoteSet) AddVote(vote *Vote) (added bool, err error) {
if voteSet == nil { if voteSet == nil {
cmn.PanicSanity("AddVote() on nil VoteSet")
panic("AddVote() on nil VoteSet")
} }
voteSet.mtx.Lock() voteSet.mtx.Lock()
defer voteSet.mtx.Unlock() defer voteSet.mtx.Unlock()
@ -196,7 +196,7 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) {
return added, NewConflictingVoteError(val, conflicting, vote) return added, NewConflictingVoteError(val, conflicting, vote)
} }
if !added { if !added {
cmn.PanicSanity("Expected to add non-conflicting vote")
panic("Expected to add non-conflicting vote")
} }
return added, nil return added, nil
} }
@ -220,7 +220,7 @@ func (voteSet *VoteSet) addVerifiedVote(vote *Vote, blockKey string, votingPower
// Already exists in voteSet.votes? // Already exists in voteSet.votes?
if existing := voteSet.votes[valIndex]; existing != nil { if existing := voteSet.votes[valIndex]; existing != nil {
if existing.BlockID.Equals(vote.BlockID) { if existing.BlockID.Equals(vote.BlockID) {
cmn.PanicSanity("addVerifiedVote does not expect duplicate votes")
panic("addVerifiedVote does not expect duplicate votes")
} else { } else {
conflicting = existing conflicting = existing
} }
@ -290,7 +290,7 @@ func (voteSet *VoteSet) addVerifiedVote(vote *Vote, blockKey string, votingPower
// NOTE: VoteSet must not be nil // NOTE: VoteSet must not be nil
func (voteSet *VoteSet) SetPeerMaj23(peerID P2PID, blockID BlockID) error { func (voteSet *VoteSet) SetPeerMaj23(peerID P2PID, blockID BlockID) error {
if voteSet == nil { if voteSet == nil {
cmn.PanicSanity("SetPeerMaj23() on nil VoteSet")
panic("SetPeerMaj23() on nil VoteSet")
} }
voteSet.mtx.Lock() voteSet.mtx.Lock()
defer voteSet.mtx.Unlock() defer voteSet.mtx.Unlock()
@ -363,7 +363,7 @@ func (voteSet *VoteSet) GetByAddress(address []byte) *Vote {
defer voteSet.mtx.Unlock() defer voteSet.mtx.Unlock()
valIndex, val := voteSet.valSet.GetByAddress(address) valIndex, val := voteSet.valSet.GetByAddress(address)
if val == nil { if val == nil {
cmn.PanicSanity("GetByAddress(address) returned nil")
panic("GetByAddress(address) returned nil")
} }
return voteSet.votes[valIndex] return voteSet.votes[valIndex]
} }
@ -530,14 +530,14 @@ func (voteSet *VoteSet) sumTotalFrac() (int64, int64, float64) {
func (voteSet *VoteSet) MakeCommit() *Commit { func (voteSet *VoteSet) MakeCommit() *Commit {
if voteSet.type_ != PrecommitType { if voteSet.type_ != PrecommitType {
cmn.PanicSanity("Cannot MakeCommit() unless VoteSet.Type is PrecommitType")
panic("Cannot MakeCommit() unless VoteSet.Type is PrecommitType")
} }
voteSet.mtx.Lock() voteSet.mtx.Lock()
defer voteSet.mtx.Unlock() defer voteSet.mtx.Unlock()
// Make sure we have a 2/3 majority // Make sure we have a 2/3 majority
if voteSet.maj23 == nil { if voteSet.maj23 == nil {
cmn.PanicSanity("Cannot MakeCommit() unless a blockhash has +2/3")
panic("Cannot MakeCommit() unless a blockhash has +2/3")
} }
// For every validator, get the precommit // For every validator, get the precommit


Loading…
Cancel
Save