From b0d8f552c505ae0adc5a8fe22525af31b9a71081 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Mon, 5 Mar 2018 15:35:50 +0400 Subject: [PATCH] return err if peer has sent a vote that does not match our round --- consensus/types/height_vote_set.go | 11 +++++++---- consensus/types/height_vote_set_test.go | 4 ++-- types/vote.go | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/consensus/types/height_vote_set.go b/consensus/types/height_vote_set.go index 7db932045..a155bce08 100644 --- a/consensus/types/height_vote_set.go +++ b/consensus/types/height_vote_set.go @@ -1,6 +1,7 @@ package types import ( + "errors" "fmt" "strings" "sync" @@ -15,6 +16,10 @@ type RoundVoteSet struct { Precommits *types.VoteSet } +var ( + GotVoteFromUnwantedRoundError = errors.New("Peer has sent a vote that does not match our round for more than one round") +) + /* Keeps track of all VoteSets from round 0 to round 'round'. @@ -117,10 +122,8 @@ func (hvs *HeightVoteSet) AddVote(vote *types.Vote, peerID p2p.ID) (added bool, voteSet = hvs.getVoteSet(vote.Round, vote.Type) hvs.peerCatchupRounds[peerID] = append(rndz, vote.Round) } else { - // Peer has sent a vote that does not match our round, - // for more than one round. Bad peer! - // TODO punish peer. - // log.Warn("Deal with peer giving votes from unwanted rounds") + // punish peer + err = GotVoteFromUnwantedRoundError return } } diff --git a/consensus/types/height_vote_set_test.go b/consensus/types/height_vote_set_test.go index 5719d7eea..246c0b711 100644 --- a/consensus/types/height_vote_set_test.go +++ b/consensus/types/height_vote_set_test.go @@ -34,8 +34,8 @@ func TestPeerCatchupRounds(t *testing.T) { vote1001_0 := makeVoteHR(t, 1, 1001, privVals, 0) added, err = hvs.AddVote(vote1001_0, "peer1") - if err != nil { - t.Error("AddVote error", err) + if err != GotVoteFromUnwantedRoundError { + t.Errorf("Expected GotVoteFromUnwantedRoundError, but got %v", err) } if added { t.Error("Expected to *not* add vote from peer, too many catchup rounds.") diff --git a/types/vote.go b/types/vote.go index 6b36e0f4f..ceb6e985e 100644 --- a/types/vote.go +++ b/types/vote.go @@ -6,7 +6,7 @@ import ( "fmt" "time" - "github.com/tendermint/go-crypto" + crypto "github.com/tendermint/go-crypto" "github.com/tendermint/tendermint/wire" cmn "github.com/tendermint/tmlibs/common" )