Browse Source

minor changes from @odeke-em PR #725

pull/735/merge
Ethan Buchman 7 years ago
parent
commit
5466720d75
3 changed files with 8 additions and 2 deletions
  1. +3
    -2
      types/validator_set.go
  2. +1
    -0
      types/vote.go
  3. +4
    -0
      types/vote_set.go

+ 3
- 2
types/validator_set.go View File

@ -100,9 +100,10 @@ func (valSet *ValidatorSet) GetByAddress(address []byte) (index int, val *Valida
} }
// GetByIndex returns the validator by index. // GetByIndex returns the validator by index.
// It returns nil values if index >= len(ValidatorSet.Validators)
// It returns nil values if index < 0 or
// index >= len(ValidatorSet.Validators)
func (valSet *ValidatorSet) GetByIndex(index int) (address []byte, val *Validator) { func (valSet *ValidatorSet) GetByIndex(index int) (address []byte, val *Validator) {
if index >= len(valSet.Validators) {
if index < 0 || index >= len(valSet.Validators) {
return nil, nil return nil, nil
} }
val = valSet.Validators[index] val = valSet.Validators[index]


+ 1
- 0
types/vote.go View File

@ -17,6 +17,7 @@ var (
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")
) )
type ErrVoteConflictingVotes struct { type ErrVoteConflictingVotes struct {


+ 4
- 0
types/vote_set.go View File

@ -123,6 +123,7 @@ func (voteSet *VoteSet) Size() int {
// Conflicting votes return added=*, err=ErrVoteConflictingVotes. // Conflicting votes return added=*, err=ErrVoteConflictingVotes.
// NOTE: vote should not be mutated after adding. // NOTE: vote should not be mutated after adding.
// NOTE: VoteSet must not be nil // NOTE: VoteSet must not be nil
// NOTE: Vote must not be nil
func (voteSet *VoteSet) AddVote(vote *Vote) (added bool, err error) { func (voteSet *VoteSet) AddVote(vote *Vote) (added bool, err error) {
if voteSet == nil { if voteSet == nil {
cmn.PanicSanity("AddVote() on nil VoteSet") cmn.PanicSanity("AddVote() on nil VoteSet")
@ -135,6 +136,9 @@ func (voteSet *VoteSet) AddVote(vote *Vote) (added bool, err error) {
// NOTE: Validates as much as possible before attempting to verify the signature. // NOTE: Validates as much as possible before attempting to verify the signature.
func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) { func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) {
if vote == nil {
return false, ErrVoteNil
}
valIndex := vote.ValidatorIndex valIndex := vote.ValidatorIndex
valAddr := vote.ValidatorAddress valAddr := vote.ValidatorAddress
blockKey := vote.BlockID.Key() blockKey := vote.BlockID.Key()


Loading…
Cancel
Save