Browse Source

return err if peer has sent a vote that does not match our round

pull/1244/head
Anton Kaliaev 7 years ago
parent
commit
b0d8f552c5
No known key found for this signature in database GPG Key ID: 7B6881D965918214
3 changed files with 10 additions and 7 deletions
  1. +7
    -4
      consensus/types/height_vote_set.go
  2. +2
    -2
      consensus/types/height_vote_set_test.go
  3. +1
    -1
      types/vote.go

+ 7
- 4
consensus/types/height_vote_set.go View File

@ -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
}
}


+ 2
- 2
consensus/types/height_vote_set_test.go View File

@ -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.")


+ 1
- 1
types/vote.go View File

@ -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"
)


Loading…
Cancel
Save