Browse Source

check vote exists before verifiying

pull/205/head
Ethan Buchman 9 years ago
parent
commit
eaf222a756
1 changed files with 11 additions and 6 deletions
  1. +11
    -6
      types/vote_set.go

+ 11
- 6
types/vote_set.go View File

@ -128,17 +128,16 @@ func (voteSet *VoteSet) addVote(val *Validator, valIndex int, vote *Vote) (bool,
return false, 0, ErrVoteUnexpectedStep
}
// Check signature.
if !val.PubKey.VerifyBytes(SignBytes(config.GetString("chain_id"), vote), vote.Signature) {
// Bad signature.
return false, 0, ErrVoteInvalidSignature
}
// If vote already exists, return false.
if existingVote := voteSet.votes[valIndex]; existingVote != nil {
if bytes.Equal(existingVote.BlockHash, vote.BlockHash) {
return false, valIndex, nil
} else {
// Check signature.
if !val.PubKey.VerifyBytes(SignBytes(config.GetString("chain_id"), vote), vote.Signature) {
// Bad signature.
return false, 0, ErrVoteInvalidSignature
}
return false, valIndex, &ErrVoteConflictingSignature{
VoteA: existingVote,
VoteB: vote,
@ -146,6 +145,12 @@ func (voteSet *VoteSet) addVote(val *Validator, valIndex int, vote *Vote) (bool,
}
}
// Check signature.
if !val.PubKey.VerifyBytes(SignBytes(config.GetString("chain_id"), vote), vote.Signature) {
// Bad signature.
return false, 0, ErrVoteInvalidSignature
}
// Add vote.
voteSet.votes[valIndex] = vote
voteSet.votesBitArray.SetIndex(valIndex, true)


Loading…
Cancel
Save