From 165907fbb90d8b8a6c960885d800073d70398511 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Fri, 16 Jan 2015 02:49:15 -0800 Subject: [PATCH] Ensure correct peer vote bitarray capacity --- consensus/reactor.go | 6 ++++-- consensus/vote_set.go | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/consensus/reactor.go b/consensus/reactor.go index 40026f445..a4381bf1a 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -383,8 +383,10 @@ OUTER_LOOP: prs := ps.GetRoundState() trySendVote := func(voteSet *VoteSet, peerVoteSet BitArray) (sent bool) { - // Initialize Prevotes/Precommits/Commits if needed - ps.EnsureVoteBitArrays(prs.Height, voteSet.Size()) + if prs.Height == voteSet.Height() { + // Initialize Prevotes/Precommits/Commits if needed + ps.EnsureVoteBitArrays(prs.Height, voteSet.Size()) + } // TODO: give priority to our vote. if index, ok := voteSet.BitArray().Sub(peerVoteSet.Copy()).PickRandom(); ok { diff --git a/consensus/vote_set.go b/consensus/vote_set.go index 03e63d3b8..9bf098cb6 100644 --- a/consensus/vote_set.go +++ b/consensus/vote_set.go @@ -54,6 +54,14 @@ func NewVoteSet(height uint, round uint, type_ byte, valSet *sm.ValidatorSet) *V } } +func (voteSet *VoteSet) Height() uint { + if voteSet == nil { + return 0 + } else { + return voteSet.height + } +} + func (voteSet *VoteSet) Size() uint { if voteSet == nil { return 0