From 14d02de3d2f509ec56e41c91a5b2e03cc0f79daa Mon Sep 17 00:00:00 2001 From: Tim Wu Date: Wed, 2 Feb 2022 12:36:45 -0500 Subject: [PATCH] add mismatch genesis peer reporting --- dot/network/block_announce.go | 5 +++++ dot/peerset/constants.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/dot/network/block_announce.go b/dot/network/block_announce.go index 5edf37f104..2a06a0843c 100644 --- a/dot/network/block_announce.go +++ b/dot/network/block_announce.go @@ -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" @@ -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") } diff --git a/dot/peerset/constants.go b/dot/peerset/constants.go index d46922e692..c4011d534d 100644 --- a/dot/peerset/constants.go +++ b/dot/peerset/constants.go @@ -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" )