From 1a1b9aaaab8f0107d81289d4934f757dd0951259 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Sun, 5 Jul 2015 21:01:59 -0700 Subject: [PATCH] fix HeightVoteSet SetRound(0) bug which wipes out Prevotes; More logging for consensus/state addVote() --- consensus/height_vote_set.go | 2 +- consensus/state.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/consensus/height_vote_set.go b/consensus/height_vote_set.go index 0dce526d3..945ee2c9e 100644 --- a/consensus/height_vote_set.go +++ b/consensus/height_vote_set.go @@ -69,7 +69,7 @@ func (hvs *HeightVoteSet) SetRound(round int) { if _, ok := hvs.roundVoteSets[r]; ok { continue // Already exists because peerCatchupRounds. } - hvs.addRound(round) + hvs.addRound(r) } hvs.round = round } diff --git a/consensus/state.go b/consensus/state.go index 69f65b7ea..a9811ebc2 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -1054,6 +1054,8 @@ func (cs *ConsensusState) AddVote(address []byte, vote *types.Vote, peerKey stri //----------------------------------------------------------------------------- func (cs *ConsensusState) addVote(address []byte, vote *types.Vote, peerKey string) (added bool, index int, err error) { + log.Debug("addVote", "voteHeight", vote.Height, "voteType", vote.Type, "csHeight", cs.Height) + // A precommit for the previous height? if vote.Height+1 == cs.Height && vote.Type == types.VoteTypePrecommit { added, index, err = cs.LastCommit.AddByAddress(address, vote) @@ -1129,10 +1131,12 @@ func (cs *ConsensusState) addVote(address []byte, vote *types.Vote, peerKey stri panic(Fmt("Unexpected vote type %X", vote.Type)) // Should not happen. } } + // Either duplicate, or error upon cs.Votes.AddByAddress() return } - // Height mismatch, bad peer? TODO + // Height mismatch, bad peer? + log.Debug("Vote ignored and not added", "voteHeight", vote.Height, "csHeight", cs.Height) return }