Skip to content

Commit a1d7269

Browse files
authored
feat(dot/network): add mismatched genesis peer reporting (#2265)
* add mismatch genesis peer reporting * double timeout in compareBlocksByNumberWithRetry * add more timeout * try to fix checks
1 parent 3ae3401 commit a1d7269

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

.github/workflows/checks.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
on:
22
pull_request:
3-
types:
4-
- opened
5-
- edited
6-
- reopened
73
paths:
84
- .github/workflows/checks.yml
95
- .github/PULL_REQUEST/pull_request.go

dot/network/block_announce.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"math/big"
1010

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

178179
if bhs.GenesisHash != s.blockState.GenesisHash() {
180+
s.host.cm.peerSetHandler.ReportPeer(peerset.ReputationChange{
181+
Value: peerset.GenesisMismatch,
182+
Reason: peerset.GenesisMismatchReason,
183+
}, from)
179184
return errors.New("genesis hash mismatch")
180185
}
181186

dot/peerset/constants.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,9 @@ const (
6262
BadJustificationValue Reputation = -(1 << 16)
6363
// BadJustificationReason is used when peer send invalid justification.
6464
BadJustificationReason = "Bad justification"
65+
66+
// GenesisMismatch is used when peer has a different genesis
67+
GenesisMismatch Reputation = math.MinInt32
68+
// GenesisMismatchReason used when a peer has a different genesis
69+
GenesisMismatchReason = "Genesis mismatch"
6570
)

tests/stress/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func compareBlocksByNumberWithRetry(t *testing.T, nodes []*utils.Node, num strin
113113
var hashes map[common.Hash][]string
114114
var err error
115115

116-
timeout := time.After(30 * time.Second)
116+
timeout := time.After(60 * time.Second)
117117
doneBlockProduction:
118118
for {
119119
time.Sleep(time.Second)

tests/stress/stress_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestSync_SingleBlockProducer(t *testing.T) {
102102
require.NoError(t, err)
103103
nodes = append(nodes, node)
104104

105-
time.Sleep(time.Second * 30)
105+
time.Sleep(time.Second * 60)
106106

107107
defer func() {
108108
errList := utils.StopNodes(t, nodes)

0 commit comments

Comments
 (0)