From 4d209ee3491845320c2387473002bf805c30f5c8 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Fri, 26 Jun 2015 17:25:47 -0700 Subject: [PATCH] Fix consensus: use the right ValidatorSet upon Vote receive --- consensus/reactor.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/consensus/reactor.go b/consensus/reactor.go index 2032c943..236f8e8f 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -177,16 +177,19 @@ func (conR *ConsensusReactor) Receive(chId byte, peer *p2p.Peer, msgBytes []byte switch msg := msg_.(type) { case *VoteMessage: vote := msg.Vote - if rs.Height != vote.Height { - if rs.Height == vote.Height+1 { - if rs.Step == RoundStepNewHeight && vote.Type == types.VoteTypePrecommit { - goto VOTE_PASS // *ducks* - } + var validators *ValidatorSet + if rs.Height == vote.Height { + validators = rs.Validators + } else if rs.Height == vote.Height+1 { + validators = rs.LastBondedValidators + if !(rs.Step == RoundStepNewHeight && vote.Type == types.VoteTypePrecommit) { + return // Wrong height, not a LastCommit straggler commit. } + } else { return // Wrong height. Not necessarily a bad peer. } VOTE_PASS: - address, _ := rs.Validators.GetByIndex(msg.ValidatorIndex) + address, _ := validators.GetByIndex(msg.ValidatorIndex) added, index, err := conR.conS.AddVote(address, vote, peer.Key) if err != nil { // If conflicting sig, broadcast evidence tx for slashing. Else punish peer.