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

RFQ Relayer: check for db status mismatch #2769

Merged
merged 4 commits into from
Jun 23, 2024
Merged

Conversation

dwasse
Copy link
Collaborator

@dwasse dwasse commented Jun 21, 2024

Summary by CodeRabbit

  • Bug Fixes
    • Added a check to ensure the status of a request has not changed before proceeding with the next step, improving stability and accuracy of request handling.

Copy link
Contributor

coderabbitai bot commented Jun 21, 2024

Walkthrough

A new validation step has been introduced in the statushandler.go file within the services/rfq/relayer/service package. This verification ensures that the status of a request remains unchanged since it was last processed before proceeding further in the middleware chain.

Changes

Files Change Summary
services/rfq/relayer/service/statushandler.go Added a check for the immutability of the request status in the mutexMiddleware function.
... Modified the exported function mutexMiddleware to include this new validation.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Relayer
    participant Middleware
    participant StatusChecker

    Client->>Relayer: Request Quote
    Relayer->>Middleware: Call mutexMiddleware
    Middleware->>StatusChecker: Check status
    Note right of StatusChecker: Validate unchanged status

    alt Status unchanged
        StatusChecker-->>Middleware: Status unchanged
        Middleware->>Relayer: Proceed with Request
        Relayer->>Client: Send Quote Response
    else Status changed
        StatusChecker-->>Middleware: Status changed
        Middleware->>Relayer: Abort request
        Relayer->>Client: Send Error Response
    end
Loading

Poem

In the code we weave so tight,
A status check in morning light, 🌅
Ensures our steps are always right,
Before we delve into the night.
Mutex dances, guards the way,
Stability shines bright today. ✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@github-actions github-actions bot added go Pull requests that update Go code size/xs labels Jun 21, 2024
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

  • Introduced status mismatch check for quote requests
  • Fetch current status from database and compare with request status
  • Prevent handler from processing if status mismatch detected

1 file(s) reviewed, no comment(s)

Copy link
Contributor

@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: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6c089de and cdd042e.

Files selected for processing (1)
  • services/rfq/relayer/service/statushandler.go (1 hunks)

Comment on lines +108 to +120
// make sure the status has not changed since we last saw it
dbReq, err := r.db.GetQuoteRequestByID(ctx, req.TransactionID)
if err != nil {
return fmt.Errorf("could not get request: %w", err)
}
if dbReq.Status != req.Status {
span.SetAttributes(
attribute.Bool("status_changed", true),
attribute.String("db_status", dbReq.Status.String()),
attribute.String("handler_status", req.Status.String()),
)
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure robust error handling and log details for status mismatch.

The addition of a status check in mutexMiddleware is crucial for consistency in handling quote requests. However, when a status mismatch occurs, the function returns nil without any specific error or log, which might make debugging difficult when status mismatches occur frequently.

Consider logging this event or handling it more explicitly to aid in troubleshooting and provide better visibility into the system's behavior.

if dbReq.Status != req.Status {
    span.SetAttributes(
        attribute.Bool("status_changed", true),
        attribute.String("db_status", dbReq.Status.String()),
        attribute.String("handler_status", req.Status.String()),
    )
+   // Log the status mismatch for better traceability
+   log.Warn("Status mismatch detected", "db_status", dbReq.Status, "request_status", req.Status)
-   return nil
+   return fmt.Errorf("status mismatch detected between database and handler")
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// make sure the status has not changed since we last saw it
dbReq, err := r.db.GetQuoteRequestByID(ctx, req.TransactionID)
if err != nil {
return fmt.Errorf("could not get request: %w", err)
}
if dbReq.Status != req.Status {
span.SetAttributes(
attribute.Bool("status_changed", true),
attribute.String("db_status", dbReq.Status.String()),
attribute.String("handler_status", req.Status.String()),
)
return nil
}
// make sure the status has not changed since we last saw it
dbReq, err := r.db.GetQuoteRequestByID(ctx, req.TransactionID)
if err != nil {
return fmt.Errorf("could not get request: %w", err)
}
if dbReq.Status != req.Status {
span.SetAttributes(
attribute.Bool("status_changed", true),
attribute.String("db_status", dbReq.Status.String()),
attribute.String("handler_status", req.Status.String()),
)
// Log the status mismatch for better traceability
log.Warn("Status mismatch detected", "db_status", dbReq.Status, "request_status", req.Status)
return fmt.Errorf("status mismatch detected between database and handler")
}

Copy link

codecov bot commented Jun 21, 2024

Codecov Report

Attention: Patch coverage is 0% with 13 lines in your changes missing coverage. Please review.

Project coverage is 25.69165%. Comparing base (87afd9b) to head (1d846cb).

Files Patch % Lines
services/rfq/relayer/service/statushandler.go 0.00000% 13 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #2769         +/-   ##
===================================================
- Coverage   25.69814%   25.69165%   -0.00649%     
===================================================
  Files            699         699                 
  Lines          51494       51507         +13     
  Branches          80          80                 
===================================================
  Hits           13233       13233                 
- Misses         36914       36927         +13     
  Partials        1347        1347                 
Flag Coverage Δ
opbot 0.00000% <ø> (ø)
rfq 27.02332% <0.00000%> (-0.06903%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

cloudflare-workers-and-pages bot commented Jun 21, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1d846cb
Status: ✅  Deploy successful!
Preview URL: https://a39c0657.sanguine-fe.pages.dev
Branch Preview URL: https://feat-status-mismatch.sanguine-fe.pages.dev

View logs

Copy link
Contributor

@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: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cdd042e and 1d846cb.

Files selected for processing (1)
  • services/rfq/relayer/service/statushandler.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • services/rfq/relayer/service/statushandler.go

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Added validation check for request status consistency in RFQ Relayer
  • Introduced new Slack bot (opbot) with commands and configurations
  • Updated dependencies in multiple go.mod files
  • Enhanced README with new entry for opbot
  • Added Dockerfile for opbot service

61 file(s) reviewed, no comment(s)

@trajan0x trajan0x merged commit d3ef268 into master Jun 23, 2024
33 of 35 checks passed
@trajan0x trajan0x deleted the feat/status-mismatch branch June 23, 2024 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code size/xs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants