mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-14 22:01:20 +00:00
types: better error messages for votes
This commit is contained in:
@ -149,10 +149,10 @@ func (dve *DuplicateVoteEvidence) Verify(chainID string) error {
|
|||||||
|
|
||||||
// Signatures must be valid
|
// Signatures must be valid
|
||||||
if !dve.PubKey.VerifyBytes(SignBytes(chainID, dve.VoteA), dve.VoteA.Signature) {
|
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) {
|
if !dve.PubKey.VerifyBytes(SignBytes(chainID, dve.VoteB), dve.VoteB.Signature) {
|
||||||
return ErrVoteInvalidSignature
|
return fmt.Errorf("DuplicateVoteEvidence Error verifying VoteB: %v", ErrVoteInvalidSignature)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -14,12 +14,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrVoteUnexpectedStep = errors.New("Unexpected step")
|
ErrVoteUnexpectedStep = errors.New("Unexpected step")
|
||||||
ErrVoteInvalidValidatorIndex = errors.New("Invalid validator index")
|
ErrVoteInvalidValidatorIndex = errors.New("Invalid validator index")
|
||||||
ErrVoteInvalidValidatorAddress = errors.New("Invalid validator address")
|
ErrVoteInvalidValidatorAddress = errors.New("Invalid validator address")
|
||||||
ErrVoteInvalidSignature = errors.New("Invalid signature")
|
ErrVoteInvalidSignature = errors.New("Invalid signature")
|
||||||
ErrVoteInvalidBlockHash = errors.New("Invalid block hash")
|
ErrVoteInvalidBlockHash = errors.New("Invalid block hash")
|
||||||
ErrVoteNil = errors.New("Nil vote")
|
ErrVoteNonDeterministicSignature = errors.New("Non-deterministic signature")
|
||||||
|
ErrVoteNil = errors.New("Nil vote")
|
||||||
)
|
)
|
||||||
|
|
||||||
type ErrVoteConflictingVotes struct {
|
type ErrVoteConflictingVotes struct {
|
||||||
|
@ -6,6 +6,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
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
|
// Ensure that validator index was set
|
||||||
if valIndex < 0 {
|
if valIndex < 0 {
|
||||||
return false, ErrVoteInvalidValidatorIndex
|
return false, errors.Wrap(ErrVoteInvalidValidatorIndex, "Index < 0")
|
||||||
} else if len(valAddr) == 0 {
|
} else if len(valAddr) == 0 {
|
||||||
return false, ErrVoteInvalidValidatorAddress
|
return false, errors.Wrap(ErrVoteInvalidValidatorAddress, "Empty address")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the step matches.
|
// Make sure the step matches.
|
||||||
if (vote.Height != voteSet.height) ||
|
if (vote.Height != voteSet.height) ||
|
||||||
(vote.Round != voteSet.round) ||
|
(vote.Round != voteSet.round) ||
|
||||||
(vote.Type != voteSet.type_) {
|
(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.
|
// Ensure that signer is a validator.
|
||||||
lookupAddr, val := voteSet.valSet.GetByIndex(valIndex)
|
lookupAddr, val := voteSet.valSet.GetByIndex(valIndex)
|
||||||
if val == nil {
|
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
|
// Ensure that the signer has the right address
|
||||||
if !bytes.Equal(valAddr, lookupAddr) {
|
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.
|
// 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) {
|
if existing.Signature.Equals(vote.Signature) {
|
||||||
return false, nil // duplicate
|
return false, nil // duplicate
|
||||||
} else {
|
} else {
|
||||||
return false, ErrVoteInvalidSignature // NOTE: assumes deterministic signatures
|
return false, errors.Wrapf(ErrVoteNonDeterministicSignature, "Existing vote: %v; New vote: %v", existing, vote)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check signature.
|
// Check signature.
|
||||||
if err := vote.Verify(voteSet.chainID, val.PubKey); err != nil {
|
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
|
// Add vote and get conflicting vote if any
|
||||||
|
Reference in New Issue
Block a user