Browse Source

fix out of range error in VoteSet.addVote

pull/697/head
Ethan Buchman 7 years ago
parent
commit
97e9802255
3 changed files with 12 additions and 5 deletions
  1. +5
    -0
      types/validator_set.go
  2. +3
    -3
      types/vote.go
  3. +4
    -2
      types/vote_set.go

+ 5
- 0
types/validator_set.go View File

@ -99,7 +99,12 @@ func (valSet *ValidatorSet) GetByAddress(address []byte) (index int, val *Valida
}
}
// GetByIndex returns the validator by index.
// It returns nil values if index >= len(ValidatorSet.Validators)
func (valSet *ValidatorSet) GetByIndex(index int) (address []byte, val *Validator) {
if index >= len(valSet.Validators) {
return nil, nil
}
val = valSet.Validators[index]
return val.Address, val.Copy()
}


+ 3
- 3
types/vote.go View File

@ -13,9 +13,9 @@ import (
var (
ErrVoteUnexpectedStep = errors.New("Unexpected step")
ErrVoteInvalidValidatorIndex = errors.New("Invalid round vote validator index")
ErrVoteInvalidValidatorAddress = errors.New("Invalid round vote validator address")
ErrVoteInvalidSignature = errors.New("Invalid round vote signature")
ErrVoteInvalidValidatorIndex = errors.New("Invalid validator index")
ErrVoteInvalidValidatorAddress = errors.New("Invalid validator address")
ErrVoteInvalidSignature = errors.New("Invalid signature")
ErrVoteInvalidBlockHash = errors.New("Invalid block hash")
)


+ 4
- 2
types/vote_set.go View File

@ -140,8 +140,10 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) {
blockKey := vote.BlockID.Key()
// Ensure that validator index was set
if valIndex < 0 || len(valAddr) == 0 {
panic("Validator index or address was not set in vote.")
if valIndex < 0 {
return false, ErrVoteInvalidValidatorIndex
} else if len(valAddr) == 0 {
return false, ErrVoteInvalidValidatorAddress
}
// Make sure the step matches.


Loading…
Cancel
Save