Skip to content

Commit

Permalink
Start submitting misbehavior reports
Browse files Browse the repository at this point in the history
  • Loading branch information
neekolas committed Jan 15, 2025
1 parent c5226fd commit 68175fe
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions pkg/sync/syncWorker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/xmtp/xmtpd/pkg/db/queries"
envUtils "github.com/xmtp/xmtpd/pkg/envelopes"
clientInterceptors "github.com/xmtp/xmtpd/pkg/interceptors/client"
"github.com/xmtp/xmtpd/pkg/misbehavior"
"github.com/xmtp/xmtpd/pkg/proto/xmtpv4/envelopes"
"github.com/xmtp/xmtpd/pkg/proto/xmtpv4/message_api"
"github.com/xmtp/xmtpd/pkg/registrant"
Expand All @@ -31,6 +32,7 @@ type syncWorker struct {
subscriptions map[uint32]struct{}
subscriptionsMutex sync.RWMutex
cancel context.CancelFunc
misbehaviorService misbehavior.MisbehaviorService
}

type originatorStream struct {
Expand Down Expand Up @@ -58,14 +60,15 @@ func startSyncWorker(
ctx, cancel := context.WithCancel(ctx)

s := &syncWorker{
ctx: ctx,
log: log.Named("syncWorker"),
nodeRegistry: nodeRegistry,
registrant: registrant,
store: store,
wg: sync.WaitGroup{},
subscriptions: make(map[uint32]struct{}),
cancel: cancel,
ctx: ctx,
log: log.Named("syncWorker"),
nodeRegistry: nodeRegistry,
registrant: registrant,
store: store,
wg: sync.WaitGroup{},
subscriptions: make(map[uint32]struct{}),
cancel: cancel,
misbehaviorService: misbehavior.NewLoggingMisbehaviorService(log),
}
if err := s.start(); err != nil {
return nil, err
Expand Down Expand Up @@ -362,8 +365,16 @@ func (s *syncWorker) validateAndInsertEnvelope(
lastNs = stream.lastEnvelope.OriginatorNs()
}
if env.OriginatorSequenceID() != lastSequenceID+1 || env.OriginatorNs() < lastNs {
// TODO(rich) Submit misbehavior report and continue
s.log.Error("Received out of order envelope")
if err = s.misbehaviorService.SafetyFailure(
misbehavior.NewSafetyFailureReport(

Check failure on line 369 in pkg/sync/syncWorker.go

View workflow job for this annotation

GitHub Actions / Lint-Go

too many arguments in call to s.misbehaviorService.SafetyFailure

Check failure on line 369 in pkg/sync/syncWorker.go

View workflow job for this annotation

GitHub Actions / Lint-Go

too many arguments in call to s.misbehaviorService.SafetyFailure

Check failure on line 369 in pkg/sync/syncWorker.go

View workflow job for this annotation

GitHub Actions / Test (Node)

too many arguments in call to s.misbehaviorService.SafetyFailure
stream.nodeID,
message_api.Misbehavior_MISBEHAVIOR_OUT_OF_ORDER,
true,
[]*envUtils.OriginatorEnvelope{env, stream.lastEnvelope},
),
); err != nil {
s.log.Debug("Failed to submit misbehavior report", zap.Error(err))
}
}

if env.OriginatorSequenceID() > lastSequenceID {
Expand Down

0 comments on commit 68175fe

Please sign in to comment.