Browse Source

consensus: add some more checks to vote counting (#7253) (#7262)

(cherry picked from commit b3b90f820c)

Co-authored-by: Callum Waters <cmwaters19@gmail.com>
pull/7268/head
mergify[bot] 3 years ago
committed by GitHub
parent
commit
4a664931b4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions
  1. +7
    -1
      internal/consensus/peer_state.go
  2. +3
    -0
      types/vote_set.go

+ 7
- 1
internal/consensus/peer_state.go View File

@ -193,7 +193,10 @@ func (ps *PeerState) PickVoteToSend(votes types.VoteSetReader) (*types.Vote, boo
} }
if index, ok := votes.BitArray().Sub(psVotes).PickRandom(); ok { if index, ok := votes.BitArray().Sub(psVotes).PickRandom(); ok {
return votes.GetByIndex(int32(index)), true
vote := votes.GetByIndex(int32(index))
if vote != nil {
return vote, true
}
} }
return nil, false return nil, false
@ -358,6 +361,9 @@ func (ps *PeerState) BlockPartsSent() int {
// SetHasVote sets the given vote as known by the peer // SetHasVote sets the given vote as known by the peer
func (ps *PeerState) SetHasVote(vote *types.Vote) { func (ps *PeerState) SetHasVote(vote *types.Vote) {
if vote == nil {
return
}
ps.mtx.Lock() ps.mtx.Lock()
defer ps.mtx.Unlock() defer ps.mtx.Unlock()


+ 3
- 0
types/vote_set.go View File

@ -372,6 +372,9 @@ func (voteSet *VoteSet) GetByIndex(valIndex int32) *Vote {
} }
voteSet.mtx.Lock() voteSet.mtx.Lock()
defer voteSet.mtx.Unlock() defer voteSet.mtx.Unlock()
if int(valIndex) >= len(voteSet.votes) {
return nil
}
return voteSet.votes[valIndex] return voteSet.votes[valIndex]
} }


Loading…
Cancel
Save