Skip to content

Commit

Permalink
add mismatch genesis peer reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
timwu20 committed Feb 2, 2022
1 parent a494c25 commit 14d02de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dot/network/block_announce.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"math/big"

"github.com/ChainSafe/gossamer/dot/peerset"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/pkg/scale"
Expand Down Expand Up @@ -176,6 +177,10 @@ func (s *Service) validateBlockAnnounceHandshake(from peer.ID, hs Handshake) err
}

if bhs.GenesisHash != s.blockState.GenesisHash() {
s.host.cm.peerSetHandler.ReportPeer(peerset.ReputationChange{
Value: peerset.GenesisMismatch,
Reason: peerset.GenesisMismatchReason,
}, from)
return errors.New("genesis hash mismatch")
}

Expand Down
5 changes: 5 additions & 0 deletions dot/peerset/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,9 @@ const (
BadJustificationValue Reputation = -(1 << 16)
// BadJustificationReason is used when peer send invalid justification.
BadJustificationReason = "Bad justification"

// GenesisMismatch is used when peer has a different genesis
GenesisMismatch Reputation = math.MinInt32
// GenesisMismatchReason used when a peer has a different genesis
GenesisMismatchReason = "Genesis mismatch"
)

0 comments on commit 14d02de

Please sign in to comment.