Browse Source

consensus: change logging and handling of height mismatch (#4954)

pull/4971/head
Callum Waters 4 years ago
committed by GitHub
parent
commit
d4f1876d12
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 11 deletions
  1. +7
    -11
      consensus/state.go

+ 7
- 11
consensus/state.go View File

@ -33,7 +33,6 @@ var (
ErrInvalidProposalSignature = errors.New("error invalid proposal signature") ErrInvalidProposalSignature = errors.New("error invalid proposal signature")
ErrInvalidProposalPOLRound = errors.New("error invalid proposal POL round") ErrInvalidProposalPOLRound = errors.New("error invalid proposal POL round")
ErrAddingVote = errors.New("error adding vote") 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. // But if it's a conflicting sig, add it to the cs.evpool.
// If it's otherwise invalid, punish peer. // If it's otherwise invalid, punish peer.
// nolint: gocritic // 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() pubKey, err := cs.privValidator.GetPubKey()
if err != nil { if err != nil {
return false, fmt.Errorf("can't get pubkey: %w", err) return false, fmt.Errorf("can't get pubkey: %w", err)
@ -1817,15 +1814,15 @@ func (cs *State) addVote(
// A precommit for the previous height? // A precommit for the previous height?
// These come in while we wait timeoutCommit // 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) added, err = cs.LastCommit.AddVote(vote)
if !added { if !added {
return added, err
return
} }
cs.Logger.Info(fmt.Sprintf("Added to lastPrecommits: %v", cs.LastCommit.StringShort())) cs.Logger.Info(fmt.Sprintf("Added to lastPrecommits: %v", cs.LastCommit.StringShort()))
@ -1845,7 +1842,6 @@ func (cs *State) addVote(
// Height mismatch is ignored. // Height mismatch is ignored.
// Not necessarily a bad peer, but not favourable behaviour. // Not necessarily a bad peer, but not favourable behaviour.
if vote.Height != cs.Height { if vote.Height != cs.Height {
err = ErrVoteHeightMismatch
cs.Logger.Info("Vote ignored and not added", "voteHeight", vote.Height, "csHeight", cs.Height, "peerID", peerID) cs.Logger.Info("Vote ignored and not added", "voteHeight", vote.Height, "csHeight", cs.Height, "peerID", peerID)
return return
} }


Loading…
Cancel
Save