From d4f1876d12b8044170674197fecbcbb12a04262e Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Fri, 5 Jun 2020 15:04:45 +0200 Subject: [PATCH] consensus: change logging and handling of height mismatch (#4954) --- consensus/state.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/consensus/state.go b/consensus/state.go index f43294eb5..b2ad377a6 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -33,7 +33,6 @@ var ( ErrInvalidProposalSignature = errors.New("error invalid proposal signature") ErrInvalidProposalPOLRound = errors.New("error invalid proposal POL round") ErrAddingVote = errors.New("error adding vote") - ErrVoteHeightMismatch = errors.New("error vote height mismatch") ) //----------------------------------------------------------------------------- @@ -1762,9 +1761,7 @@ func (cs *State) tryAddVote(vote *types.Vote, peerID p2p.ID) (bool, error) { // But if it's a conflicting sig, add it to the cs.evpool. // If it's otherwise invalid, punish peer. // nolint: gocritic - if err == ErrVoteHeightMismatch { - return added, err - } else if voteErr, ok := err.(*types.ErrVoteConflictingVotes); ok { + if voteErr, ok := err.(*types.ErrVoteConflictingVotes); ok { pubKey, err := cs.privValidator.GetPubKey() if err != nil { return false, fmt.Errorf("can't get pubkey: %w", err) @@ -1817,15 +1814,15 @@ func (cs *State) addVote( // A precommit for the previous height? // These come in while we wait timeoutCommit - if vote.Height+1 == cs.Height { - if !(cs.Step == cstypes.RoundStepNewHeight && vote.Type == tmproto.PrecommitType) { - // TODO: give the reason .. - // fmt.Errorf("tryAddVote: Wrong height, not a LastCommit straggler commit.") - return added, ErrVoteHeightMismatch + if vote.Height+1 == cs.Height && vote.Type == tmproto.PrecommitType { + if cs.Step != cstypes.RoundStepNewHeight { + // Late precommit at prior height is ignored + cs.Logger.Debug("Precommit vote came in after commit timeout and has been ignored", "vote", vote) + return } added, err = cs.LastCommit.AddVote(vote) if !added { - return added, err + return } cs.Logger.Info(fmt.Sprintf("Added to lastPrecommits: %v", cs.LastCommit.StringShort())) @@ -1845,7 +1842,6 @@ func (cs *State) addVote( // Height mismatch is ignored. // Not necessarily a bad peer, but not favourable behaviour. if vote.Height != cs.Height { - err = ErrVoteHeightMismatch cs.Logger.Info("Vote ignored and not added", "voteHeight", vote.Height, "csHeight", cs.Height, "peerID", peerID) return }