mirror of
https://github.com/tendermint/tendermint.git
synced 2026-04-25 18:20:31 +00:00
fix out of range error in VoteSet.addVote
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
)
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user