Browse Source

ValidatorSet#GetByAddress: return -1 if no validator was found

pull/1391/head
Anton Kaliaev 6 years ago
parent
commit
37ce6b195a
No known key found for this signature in database GPG Key ID: 7B6881D965918214
2 changed files with 5 additions and 6 deletions
  1. +1
    -5
      consensus/state.go
  2. +4
    -1
      types/validator_set.go

+ 1
- 5
consensus/state.go View File

@ -720,11 +720,7 @@ func (cs *ConsensusState) needProofBlock(height int64) bool {
func (cs *ConsensusState) proposalHeartbeat(height int64, round int) {
counter := 0
addr := cs.privValidator.GetAddress()
valIndex, v := cs.Validators.GetByAddress(addr)
if v == nil {
// not a validator
valIndex = -1
}
valIndex, _ := cs.Validators.GetByAddress(addr)
chainID := cs.state.ChainID
for {
rs := cs.GetRoundState()


+ 4
- 1
types/validator_set.go View File

@ -90,14 +90,17 @@ func (valSet *ValidatorSet) HasAddress(address []byte) bool {
return idx != len(valSet.Validators) && bytes.Equal(valSet.Validators[idx].Address, address)
}
// GetByAddress returns an index of the validator with address and validator
// itself if found. Otherwise, -1 and nil are returned.
func (valSet *ValidatorSet) GetByAddress(address []byte) (index int, val *Validator) {
idx := sort.Search(len(valSet.Validators), func(i int) bool {
return bytes.Compare(address, valSet.Validators[i].Address) <= 0
})
if idx != len(valSet.Validators) && bytes.Equal(valSet.Validators[idx].Address, address) {
return idx, valSet.Validators[idx].Copy()
} else {
return -1, nil
}
return 0, nil
}
// GetByIndex returns the validator by index.


Loading…
Cancel
Save