stop peer if it sends invalid vote

This commit is contained in:
Anton Kaliaev
2018-03-05 13:04:31 +04:00
parent bcf54b0aa3
commit 266974cb59
2 changed files with 53 additions and 1 deletions

View File

@ -63,6 +63,19 @@ func (ti *timeoutInfo) String() string {
return fmt.Sprintf("%v ; %d/%d %v", ti.Duration, ti.Height, ti.Round, ti.Step)
}
type peerError struct {
err error
peerID p2p.ID
}
func (e peerError) Error() string {
return fmt.Sprintf("error with peer %v: %s", e.peerID, e.err.Error())
}
const (
peerErrorEvent = "cs.PeerError"
)
// ConsensusState handles execution of the consensus algorithm.
// It processes votes and proposals, and upon reaching agreement,
// commits blocks to the chain and executes them against the application.
@ -582,7 +595,8 @@ func (cs *ConsensusState) handleMsg(mi msgInfo) {
// if the vote gives us a 2/3-any or 2/3-one, we transition
err := cs.tryAddVote(msg.Vote, peerID)
if err == ErrAddingVote {
// TODO: punish peer
// punish peer
cs.eventBus.Publish(peerErrorEvent, types.TMEventData{peerError{err, peerID}})
}
// NOTE: the vote is broadcast to peers by the reactor listening