Skip to content

Commit

Permalink
feat(dot/network): add mismatched genesis peer reporting (#2265)
Browse files Browse the repository at this point in the history
* add mismatch genesis peer reporting

* double timeout in compareBlocksByNumberWithRetry

* add more timeout

* try to fix checks
  • Loading branch information
timwu20 authored Feb 11, 2022
1 parent 3ae3401 commit a1d7269
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
on:
pull_request:
types:
- opened
- edited
- reopened
paths:
- .github/workflows/checks.yml
- .github/PULL_REQUEST/pull_request.go
Expand Down
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"
)
2 changes: 1 addition & 1 deletion tests/stress/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func compareBlocksByNumberWithRetry(t *testing.T, nodes []*utils.Node, num strin
var hashes map[common.Hash][]string
var err error

timeout := time.After(30 * time.Second)
timeout := time.After(60 * time.Second)
doneBlockProduction:
for {
time.Sleep(time.Second)
Expand Down
2 changes: 1 addition & 1 deletion tests/stress/stress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestSync_SingleBlockProducer(t *testing.T) {
require.NoError(t, err)
nodes = append(nodes, node)

time.Sleep(time.Second * 30)
time.Sleep(time.Second * 60)

defer func() {
errList := utils.StopNodes(t, nodes)
Expand Down

0 comments on commit a1d7269

Please sign in to comment.