-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start submitting misbehavior reports #414
base: 01-15-add_loggingmisbehaviorservice
Are you sure you want to change the base?
Start submitting misbehavior reports #414
Conversation
WalkthroughThe changes introduce misbehavior reporting functionality to the Changes
Sequence DiagramsequenceDiagram
participant SW as SyncWorker
participant MS as MisbehaviorService
participant ENV as Envelope
SW ->> SW: Receive Envelope
alt Out-of-Order Envelope Detected
SW ->> SW: Create Safety Failure Report
SW ->> MS: submitOutOfOrderReport()
MS -->> SW: Report Submitted
else Normal Envelope
SW ->> SW: Process Normally
end
Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
68175fe
to
d8b159f
Compare
c5226fd
to
6443a91
Compare
d8b159f
to
d3f2f32
Compare
6443a91
to
7666a1b
Compare
d3f2f32
to
0319ff8
Compare
pkg/sync/syncWorker.go
Outdated
@@ -362,8 +365,19 @@ 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 report, err := misbehavior.NewSafetyFailureReport( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really struggle to read this inlined error handling. We generally don't use the format.
The explicit formatting is much more readable:
report, err := misbehavior.NewSafetyFailureReport(
stream.nodeID,
message_api.Misbehavior_MISBEHAVIOR_OUT_OF_ORDER,
true,
[]*envUtils.OriginatorEnvelope{stream.lastEnvelope, env},
)
if err != nil {
// Log the error if the report creation fails
s.log.Debug("Failed to create misbehavior report", zap.Error(err))
return // Exit early or handle it as appropriate
}
// Submit the misbehavior report
err = s.misbehaviorService.SafetyFailure(report)
if err != nil {
// Log the error if the report submission fails
s.log.Debug("Failed to submit misbehavior report", zap.Error(err))
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. I don't love the double nesting here.
I'll move to its own function so that I can early return, since this whole code path is optional
0319ff8
to
0b49138
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pkg/sync/syncWorker.go (1)
63-71
: Consider making misbehaviorService configurable.Currently, the service is hardcoded to use a logging implementation. Consider making it configurable through the constructor to improve testability and flexibility.
func startSyncWorker( ctx context.Context, log *zap.Logger, nodeRegistry registry.NodeRegistry, registrant *registrant.Registrant, store *sql.DB, + misbehaviorService misbehavior.MisbehaviorService, ) (*syncWorker, error) { ctx, cancel := context.WithCancel(ctx) + if misbehaviorService == nil { + misbehaviorService = misbehavior.NewLoggingMisbehaviorService(log) + } s := &syncWorker{ 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), + misbehaviorService: misbehaviorService, }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
pkg/sync/syncWorker.go
(5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Graphite / mergeability_check
- GitHub Check: Test (Node)
- GitHub Check: Graphite / mergeability_check
🔇 Additional comments (2)
pkg/sync/syncWorker.go (2)
15-15
: LGTM! Clean integration of misbehavior reporting.The new import and field addition are well-structured and align with the PR objectives.
Also applies to: 35-35
368-371
: LGTM! Good error handling approach.The error handling is clean and follows the feedback from previous reviews. Appropriately continues processing even if report submission fails.
TL;DR
Added misbehavior reporting for out-of-order envelopes in the sync worker.
What changed?
How to test?
Why make this change?
To improve network reliability by tracking and reporting out-of-order envelope submissions, which could indicate node misbehavior or network issues. This helps maintain the integrity of message ordering and enables better monitoring of node behavior.
Summary by CodeRabbit
New Features
Improvements