diff --git a/types/evidence.go b/types/evidence.go index d6b408119..94bab1a38 100644 --- a/types/evidence.go +++ b/types/evidence.go @@ -149,10 +149,10 @@ func (dve *DuplicateVoteEvidence) Verify(chainID string) error { // Signatures must be valid if !dve.PubKey.VerifyBytes(SignBytes(chainID, dve.VoteA), dve.VoteA.Signature) { - return ErrVoteInvalidSignature + return fmt.Errorf("DuplicateVoteEvidence Error verifying VoteA: %v", ErrVoteInvalidSignature) } if !dve.PubKey.VerifyBytes(SignBytes(chainID, dve.VoteB), dve.VoteB.Signature) { - return ErrVoteInvalidSignature + return fmt.Errorf("DuplicateVoteEvidence Error verifying VoteB: %v", ErrVoteInvalidSignature) } return nil diff --git a/types/vote.go b/types/vote.go index 3136e4bb8..4397152c7 100644 --- a/types/vote.go +++ b/types/vote.go @@ -14,12 +14,13 @@ import ( ) var ( - ErrVoteUnexpectedStep = errors.New("Unexpected step") - ErrVoteInvalidValidatorIndex = errors.New("Invalid validator index") - ErrVoteInvalidValidatorAddress = errors.New("Invalid validator address") - ErrVoteInvalidSignature = errors.New("Invalid signature") - ErrVoteInvalidBlockHash = errors.New("Invalid block hash") - ErrVoteNil = errors.New("Nil vote") + ErrVoteUnexpectedStep = errors.New("Unexpected step") + ErrVoteInvalidValidatorIndex = errors.New("Invalid validator index") + ErrVoteInvalidValidatorAddress = errors.New("Invalid validator address") + ErrVoteInvalidSignature = errors.New("Invalid signature") + ErrVoteInvalidBlockHash = errors.New("Invalid block hash") + ErrVoteNonDeterministicSignature = errors.New("Non-deterministic signature") + ErrVoteNil = errors.New("Nil vote") ) type ErrVoteConflictingVotes struct { diff --git a/types/vote_set.go b/types/vote_set.go index 3f8a96e3a..34f989567 100644 --- a/types/vote_set.go +++ b/types/vote_set.go @@ -6,6 +6,8 @@ import ( "strings" "sync" + "github.com/pkg/errors" + cmn "github.com/tendermint/tmlibs/common" ) @@ -145,27 +147,32 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) { // Ensure that validator index was set if valIndex < 0 { - return false, ErrVoteInvalidValidatorIndex + return false, errors.Wrap(ErrVoteInvalidValidatorIndex, "Index < 0") } else if len(valAddr) == 0 { - return false, ErrVoteInvalidValidatorAddress + return false, errors.Wrap(ErrVoteInvalidValidatorAddress, "Empty address") } // Make sure the step matches. if (vote.Height != voteSet.height) || (vote.Round != voteSet.round) || (vote.Type != voteSet.type_) { - return false, ErrVoteUnexpectedStep + return false, errors.Wrapf(ErrVoteUnexpectedStep, "Got %d/%d/%d, expected %d/%d/%d", + voteSet.height, voteSet.round, voteSet.type_, + vote.Height, vote.Round, vote.Type) } // Ensure that signer is a validator. lookupAddr, val := voteSet.valSet.GetByIndex(valIndex) if val == nil { - return false, ErrVoteInvalidValidatorIndex + return false, errors.Wrapf(ErrVoteInvalidValidatorIndex, + "Cannot find validator %d in valSet of size %d", valIndex, voteSet.valSet.Size()) } // Ensure that the signer has the right address if !bytes.Equal(valAddr, lookupAddr) { - return false, ErrVoteInvalidValidatorAddress + return false, errors.Wrapf(ErrVoteInvalidValidatorAddress, + "vote.ValidatorAddress (%X) does not match address (%X) for vote.ValidatorIndex (%d)", + valAddr, lookupAddr, valIndex) } // If we already know of this vote, return false. @@ -173,13 +180,13 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) { if existing.Signature.Equals(vote.Signature) { return false, nil // duplicate } else { - return false, ErrVoteInvalidSignature // NOTE: assumes deterministic signatures + return false, errors.Wrapf(ErrVoteNonDeterministicSignature, "Existing vote: %v; New vote: %v", existing, vote) } } // Check signature. if err := vote.Verify(voteSet.chainID, val.PubKey); err != nil { - return false, err + return false, errors.Wrapf(err, "Failed to verify vote with ChainID %s and PubKey %s", voteSet.chainID, val.PubKey) } // Add vote and get conflicting vote if any