ValidatorSet#GetByAddress: return -1 if no validator was found
This commit is contained in:
parent
7aa6d36258
commit
37ce6b195a
|
@ -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()
|
||||
|
|
|
@ -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…
Reference in New Issue