|
@ -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
|
|
|