Skip to content

Commit d8b159f

Browse files
committed
Start submitting misbehavior reports
1 parent c5226fd commit d8b159f

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

pkg/sync/syncWorker.go

+24-10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/xmtp/xmtpd/pkg/db/queries"
1313
envUtils "github.com/xmtp/xmtpd/pkg/envelopes"
1414
clientInterceptors "github.com/xmtp/xmtpd/pkg/interceptors/client"
15+
"github.com/xmtp/xmtpd/pkg/misbehavior"
1516
"github.com/xmtp/xmtpd/pkg/proto/xmtpv4/envelopes"
1617
"github.com/xmtp/xmtpd/pkg/proto/xmtpv4/message_api"
1718
"github.com/xmtp/xmtpd/pkg/registrant"
@@ -31,6 +32,7 @@ type syncWorker struct {
3132
subscriptions map[uint32]struct{}
3233
subscriptionsMutex sync.RWMutex
3334
cancel context.CancelFunc
35+
misbehaviorService misbehavior.MisbehaviorService
3436
}
3537

3638
type originatorStream struct {
@@ -58,14 +60,15 @@ func startSyncWorker(
5860
ctx, cancel := context.WithCancel(ctx)
5961

6062
s := &syncWorker{
61-
ctx: ctx,
62-
log: log.Named("syncWorker"),
63-
nodeRegistry: nodeRegistry,
64-
registrant: registrant,
65-
store: store,
66-
wg: sync.WaitGroup{},
67-
subscriptions: make(map[uint32]struct{}),
68-
cancel: cancel,
63+
ctx: ctx,
64+
log: log.Named("syncWorker"),
65+
nodeRegistry: nodeRegistry,
66+
registrant: registrant,
67+
store: store,
68+
wg: sync.WaitGroup{},
69+
subscriptions: make(map[uint32]struct{}),
70+
cancel: cancel,
71+
misbehaviorService: misbehavior.NewLoggingMisbehaviorService(log),
6972
}
7073
if err := s.start(); err != nil {
7174
return nil, err
@@ -362,8 +365,19 @@ func (s *syncWorker) validateAndInsertEnvelope(
362365
lastNs = stream.lastEnvelope.OriginatorNs()
363366
}
364367
if env.OriginatorSequenceID() != lastSequenceID+1 || env.OriginatorNs() < lastNs {
365-
// TODO(rich) Submit misbehavior report and continue
366-
s.log.Error("Received out of order envelope")
368+
if report, err := misbehavior.NewSafetyFailureReport(
369+
stream.nodeID,
370+
message_api.Misbehavior_MISBEHAVIOR_OUT_OF_ORDER,
371+
true,
372+
[]*envUtils.OriginatorEnvelope{stream.lastEnvelope, env},
373+
); err == nil {
374+
if err = s.misbehaviorService.SafetyFailure(report); err != nil {
375+
s.log.Debug("Failed to submit misbehavior report", zap.Error(err))
376+
}
377+
} else {
378+
s.log.Debug("Failed to create misbehavior report", zap.Error(err))
379+
}
380+
367381
}
368382

369383
if env.OriginatorSequenceID() > lastSequenceID {

0 commit comments

Comments
 (0)