Skip to content
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

Add LoggingMisbehaviorService #413

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

neekolas
Copy link
Contributor

@neekolas neekolas commented Jan 15, 2025

TL;DR

Introduces a very-lightweight misbehavior reporting system that simply logs the misbehavior reports in a structured format.

This can be used in tests, and deployed to nodes. We will eventually replace this with a system that saves misbehavior reports to the DB.

What changed?

  • Created a new misbehavior package with interfaces and implementations for handling node misbehavior
  • Added SafetyFailureReport structure to capture details about safety violations
  • Implemented LoggingMisbehaviorService that logs misbehavior reports with relevant metadata
  • Added support for tracking duplicate sequence IDs and other safety-related issues
  • Included comprehensive test coverage for the logging service

How to test?

  1. Run the unit tests in misbehavior_test.go
  2. Verify log output contains expected fields:
    • misbehavior_type
    • misbehaving_node_id
    • submitted_by_node
    • envelopes

Why make this change?

To establish a foundation for detecting and handling node misbehavior in the network, particularly focusing on safety violations. This system will help maintain network integrity by tracking and logging suspicious activities, with future expansion planned for handling liveness failures.

Summary by CodeRabbit

  • New Features

    • Introduced a new MisbehaviorService interface for handling safety failures
    • Added LoggingMisbehaviorService to log misbehavior reports
    • Created SafetyFailureReport to capture details of node misbehavior
  • Tests

    • Added comprehensive test for logging misbehavior service functionality

The changes enhance the system's ability to detect, log, and report node misbehavior with a structured approach.

Copy link

coderabbitai bot commented Jan 15, 2025

Warning

Rate limit exceeded

@neekolas has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 26 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 8bdd8b9 and 7666a1b.

📒 Files selected for processing (4)
  • pkg/misbehavior/interface.go (1 hunks)
  • pkg/misbehavior/misbehavior.go (1 hunks)
  • pkg/misbehavior/misbehavior_test.go (1 hunks)
  • pkg/misbehavior/report.go (1 hunks)

Walkthrough

A new misbehavior package has been introduced to handle safety failure reporting in the system. The package defines an interface MisbehaviorService with a SafetyFailure method, and provides a LoggingMisbehaviorService implementation that logs misbehavior incidents. The SafetyFailureReport struct captures details about node misbehavior, including the node ID, misbehavior type, submission status, and related envelopes. A corresponding test has been added to validate the logging functionality.

Changes

File Change Summary
pkg/misbehavior/interface.go Added MisbehaviorService interface with SafetyFailure method
pkg/misbehavior/misbehavior.go Implemented LoggingMisbehaviorService with SafetyFailure method for logging misbehavior reports
pkg/misbehavior/misbehavior_test.go Added test TestLoggingMisbehaviorService to validate misbehavior logging
pkg/misbehavior/report.go Introduced SafetyFailureReport struct and NewSafetyFailureReport constructor

Sequence Diagram

sequenceDiagram
    participant Client
    participant MisbehaviorService
    participant Logger

    Client->>MisbehaviorService: SafetyFailure(report)
    MisbehaviorService->>Logger: Log misbehavior details
    Logger-->>MisbehaviorService: Logging complete
    MisbehaviorService-->>Client: Return nil
Loading

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor Author

neekolas commented Jan 15, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@neekolas neekolas marked this pull request as ready for review January 15, 2025 19:18
@neekolas neekolas requested a review from a team as a code owner January 15, 2025 19:18
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (1)
pkg/misbehavior/interface.go (1)

3-6: Add interface documentation.

The interface looks good, but could benefit from documentation explaining its purpose and contract. Consider adding a comment describing:

  • The purpose of this service
  • What constitutes a safety failure
  • Expected behavior when SafetyFailure is called
+// MisbehaviorService defines the contract for handling node misbehavior in the system.
+// Implementations of this interface are responsible for processing and responding to
+// various types of misbehavior reports.
 type MisbehaviorService interface {
+    // SafetyFailure handles reports of safety violations by nodes in the system.
+    // It returns an error if the report cannot be processed.
     SafetyFailure(report *SafetyFailureReport) error
     // TODO:nm add liveness failures
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 93e176c and 8bdd8b9.

📒 Files selected for processing (4)
  • pkg/misbehavior/interface.go (1 hunks)
  • pkg/misbehavior/misbehavior.go (1 hunks)
  • pkg/misbehavior/misbehavior_test.go (1 hunks)
  • pkg/misbehavior/report.go (1 hunks)

pkg/misbehavior/report.go Outdated Show resolved Hide resolved
pkg/misbehavior/report.go Outdated Show resolved Hide resolved
pkg/misbehavior/misbehavior.go Show resolved Hide resolved
pkg/misbehavior/misbehavior.go Outdated Show resolved Hide resolved
pkg/misbehavior/misbehavior_test.go Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
pkg/misbehavior/interface.go (1)

3-6: Consider documenting the interface and method.

The interface looks clean and focused, but adding documentation would help explain:

  • The purpose of MisbehaviorService
  • What constitutes a safety failure
  • The expected behavior when SafetyFailure returns an error

Also, regarding the TODO comment - would you like me to create a GitHub issue to track the addition of liveness failures?

pkg/misbehavior/report.go (1)

8-13: Consider adding field documentation and accessor methods.

The struct fields are unexported which provides good encapsulation, but:

  • Add documentation for each field explaining its purpose
  • Consider adding getter methods since the fields are unexported but likely needed by consumers
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 93e176c and 8bdd8b9.

📒 Files selected for processing (4)
  • pkg/misbehavior/interface.go (1 hunks)
  • pkg/misbehavior/misbehavior.go (1 hunks)
  • pkg/misbehavior/misbehavior_test.go (1 hunks)
  • pkg/misbehavior/report.go (1 hunks)
🔇 Additional comments (1)
pkg/misbehavior/misbehavior.go (1)

7-17: LGTM! Good use of named logger.

The type documentation and constructor implementation look clean and follow best practices.

pkg/misbehavior/report.go Outdated Show resolved Hide resolved
pkg/misbehavior/misbehavior.go Outdated Show resolved Hide resolved
pkg/misbehavior/misbehavior_test.go Outdated Show resolved Hide resolved
@neekolas neekolas force-pushed the 01-15-add_loggingmisbehaviorservice branch from 8bdd8b9 to c5226fd Compare January 15, 2025 20:00
@neekolas neekolas force-pushed the 01-15-add_loggingmisbehaviorservice branch from c5226fd to 6443a91 Compare January 15, 2025 20:07
@neekolas neekolas force-pushed the 01-15-add_loggingmisbehaviorservice branch from 6443a91 to 7666a1b Compare January 15, 2025 20:09
Copy link
Collaborator

@mkysel mkysel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right now the package is not hooked up to the server. I assume there will be future PRs that do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants