fix HeightVoteSet SetRound(0) bug which wipes out Prevotes; More logging for consensus/state addVote()

This commit is contained in:
Jae Kwon 2015-07-05 21:01:59 -07:00
parent 16a1404cfe
commit 1a1b9aaaab
2 changed files with 6 additions and 2 deletions

View File

@ -69,7 +69,7 @@ func (hvs *HeightVoteSet) SetRound(round int) {
if _, ok := hvs.roundVoteSets[r]; ok { if _, ok := hvs.roundVoteSets[r]; ok {
continue // Already exists because peerCatchupRounds. continue // Already exists because peerCatchupRounds.
} }
hvs.addRound(round) hvs.addRound(r)
} }
hvs.round = round hvs.round = round
} }

View File

@ -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) { 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? // A precommit for the previous height?
if vote.Height+1 == cs.Height && vote.Type == types.VoteTypePrecommit { if vote.Height+1 == cs.Height && vote.Type == types.VoteTypePrecommit {
added, index, err = cs.LastCommit.AddByAddress(address, vote) 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. panic(Fmt("Unexpected vote type %X", vote.Type)) // Should not happen.
} }
} }
// Either duplicate, or error upon cs.Votes.AddByAddress()
return return
} }
// Height mismatch, bad peer? TODO // Height mismatch, bad peer?
log.Debug("Vote ignored and not added", "voteHeight", vote.Height, "csHeight", cs.Height)
return return
} }