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

revert(relayer): potential deadlock #3036

Merged
merged 2 commits into from
Aug 19, 2024
Merged

revert(relayer): potential deadlock #3036

merged 2 commits into from
Aug 19, 2024

Conversation

dwasse
Copy link
Collaborator

@dwasse dwasse commented Aug 19, 2024

Description
A clear and concise description of the features you're adding in this pull request.

Additional context
Add any other context about the problem you're solving.

Metadata

  • Fixes #[Link to Issue]

Summary by CodeRabbit

  • New Features

    • Enhanced request handling process with streamlined logic for balance management.
  • Bug Fixes

    • Removed balance locking mechanisms to simplify methods, which may improve performance.
  • Refactor

    • Adjusted the QuoteRequestHandler and Relayer to eliminate balance-related fields and methods, indicating a shift in balance management strategy.
  • Documentation

    • Improved comments for better clarity regarding the changes in concurrency control mechanisms.

Copy link
Contributor

coderabbitai bot commented Aug 19, 2024

Walkthrough

The recent changes streamline the balance management and request handling in the relayer service. Key modifications include the removal of mutex locks associated with balance checks, simplifying the logic and improving performance. However, these adjustments raise potential concerns about concurrency issues, indicating a shift in synchronization mechanisms and possibly altering how balance-related functionality is handled overall.

Changes

Files Change Summary
services/rfq/relayer/service/handlers.go, services/rfq/relayer/service/statushandler.go Significant modifications to balance handling: removal of balanceMtx and related logic, altering request flow in QuoteRequestHandler.
services/rfq/relayer/service/relayer.go Removal of balanceMtx from Relayer struct and its initialization, indicating a simplification in concurrency control mechanisms.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant QuoteRequestHandler
    participant Relayer

    Client->>QuoteRequestHandler: Submit Quote Request
    QuoteRequestHandler->>QuoteRequestHandler: Handle Seen
    QuoteRequestHandler->>Relayer: Commit Pending Balance
    Relayer->>QuoteRequestHandler: Process Request
    QuoteRequestHandler->>Client: Response
Loading

Poem

In fields of code, a change did sprout,
A hop, a skip, no locks about! 🐇
The requests now flow, swift as a breeze,
With balances free, it’s sure to please!
Let’s dance and cheer, for each new line,
A simpler path, oh how divine! 🌼


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

@github-actions github-actions bot added go Pull requests that update Go code size/s labels Aug 19, 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

This pull request reverts changes related to balance locking mechanisms in the RFQ relayer service, simplifying the code but potentially impacting concurrency control.

  • Removed commitPendingBalance function and associated locking in handleSeen and handleNotEnoughInventory functions
  • Eliminated balanceMtx field from Relayer and QuoteRequestHandler structs
  • Simplified balance checking process in handleSeen, directly using GetCommittableBalance
  • Removed getBalanceMtxKey function, indicating a change in balance-related synchronization
  • These changes may improve performance but could introduce potential thread safety issues

3 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings

@@ -167,7 +165,6 @@ func NewRelayer(ctx context.Context, metricHandler metrics.Handler, cfg relconfi
apiClient: apiClient,
semaphore: semaphore.NewWeighted(maxConcurrentRequests),
handlerMtx: mapmutex.NewStringMapMutex(),
Copy link

Choose a reason for hiding this comment

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

logic: balanceMtx initialization removed. Verify if balance synchronization is still properly handled.

Copy link

codecov bot commented Aug 19, 2024

Codecov Report

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

Project coverage is 23.37680%. Comparing base (9dfde6c) to head (d032bfa).
Report is 3 commits behind head on master.

Files Patch % Lines
services/rfq/relayer/service/handlers.go 0.00000% 7 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #3036         +/-   ##
===================================================
- Coverage   23.38100%   23.37680%   -0.00421%     
===================================================
  Files            644         644                 
  Lines          50139       50148          +9     
  Branches          82          82                 
===================================================
  Hits           11723       11723                 
- Misses         37255       37264          +9     
  Partials        1161        1161                 
Flag Coverage Δ
opbot 0.48900% <ø> (ø)
promexporter 6.94006% <ø> (ø)
rfq 21.79024% <0.00000%> (-0.02536%) ⬇️

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

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: d032bfa
Status: ✅  Deploy successful!
Preview URL: https://d75a042d.sanguine-fe.pages.dev
Branch Preview URL: https://fix-revert-2994.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 9dfde6c and d032bfa.

Files selected for processing (3)
  • services/rfq/relayer/service/handlers.go (3 hunks)
  • services/rfq/relayer/service/relayer.go (2 hunks)
  • services/rfq/relayer/service/statushandler.go (2 hunks)
Additional comments not posted (8)
services/rfq/relayer/service/statushandler.go (3)

Line range hint 34-34: Review the removal of balanceMtx.

The balanceMtx field has been removed from the QuoteRequestHandler struct. Ensure that balance synchronization is handled appropriately elsewhere to avoid concurrency issues.


Line range hint 61-61: Verify synchronization sufficiency with handlerMtx.

The requestToHandler function now initializes QuoteRequestHandler without balanceMtx, relying on handlerMtx. Ensure this is sufficient for all synchronization needs.


Line range hint 88-90: Ensure adequate locking with handlerMtx.

The mutexMiddleware function uses handlerMtx for locking. Verify that this provides adequate synchronization for the operations performed.

services/rfq/relayer/service/relayer.go (2)

64-64: Review the removal of balanceMtx.

The balanceMtx field has been removed from the Relayer struct. Ensure that balance synchronization is handled appropriately elsewhere to avoid concurrency issues.


Line range hint 119-119: Verify impact of removing balanceMtx initialization.

The NewRelayer function no longer initializes balanceMtx. Ensure that this change does not affect functionality or introduce concurrency issues.

Verification successful

Impact of Removing balanceMtx Initialization Verified

The removal of balanceMtx initialization in the NewRelayer function was part of a commit that reverted a previous feature adding mutex on committable balance consumption. This indicates that balanceMtx was used for synchronizing balance requests but has been intentionally removed, likely due to a design decision or because it was no longer needed.

  • The commit history shows that balanceMtx and its associated logic were completely removed, suggesting that the codebase has been refactored to function without it.
  • There are no remaining references to balanceMtx in the current codebase, confirming its removal and the absence of dependency issues.

Therefore, the removal of balanceMtx does not negatively impact the current functionality or introduce concurrency issues. The code has been adjusted accordingly to operate without this mutex.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of removing `balanceMtx` initialization in `NewRelayer`.

# Test: Check for any dependencies on `balanceMtx` initialization that might affect functionality.
rg --type go 'NewRelayer'

Length of output: 3456


Script:

#!/bin/bash
# Description: Search for references to `balanceMtx` in the codebase to assess its previous usage.

# Find all occurrences of `balanceMtx` to understand its role and impact.
rg --type go 'balanceMtx'

Length of output: 25


Script:

#!/bin/bash
# Description: Check the version control history for any recent changes related to `balanceMtx`.

# Search the git log for any commits mentioning `balanceMtx`.
git log -p -S 'balanceMtx'

Length of output: 53648

services/rfq/relayer/service/handlers.go (3)

490-495: Verify safety of removing balance locking logic.

The handleNotEnoughInventory function no longer uses balance locking logic. Ensure that this change does not introduce concurrency issues.


214-221: Verify safety of removing locking mechanisms.

The commitPendingBalance function no longer uses locking mechanisms. Ensure that this change does not introduce concurrency issues.


214-221: Verify safety of removing immediate balance commitment.

The handleSeen function no longer commits pending balances immediately. Ensure that this change does not introduce race conditions or other issues.

Verification successful

Removal of Immediate Balance Commitment is Safe

The handleSeen function's removal of immediate balance commitment is managed safely by the checks and processes in handleCommitPending. The latter ensures that requests are only processed when conditions are met, reducing the risk of race conditions.

  • The handleCommitPending function checks block confirmations and bridge status before updating request status and forwarding.
  • These mechanisms ensure that requests are handled safely and sequentially.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the safety of removing immediate balance commitment in `handleSeen`.

# Test: Check for potential race conditions or issues introduced by this change.
rg --type go 'handleSeen'

Length of output: 565


Script:

#!/bin/bash
# Search for the implementation of the `handleSeen` function to understand its logic.
ast-grep --lang go --pattern 'func (q *QuoteRequestHandler) handleSeen($_, $_, $_) $_' 

Length of output: 7031


Script:

#!/bin/bash
# Search for the implementation of the `handleCommitPending` function to verify its handling of requests.
ast-grep --lang go --pattern 'func (q *QuoteRequestHandler) handleCommitPending($_, $_, $_) $_'

Length of output: 4326

@dwasse dwasse changed the title Fix/revert 2994 revert(relayer): potential deadlock Aug 19, 2024
@aureliusbtc aureliusbtc merged commit c26fce3 into master Aug 19, 2024
34 of 35 checks passed
@aureliusbtc aureliusbtc deleted the fix/revert-2994 branch August 19, 2024 21:57
trajan0x added a commit that referenced this pull request Aug 20, 2024
trajan0x added a commit that referenced this pull request Aug 21, 2024
* Revert "revert(relayer): potential deadlock (#3036)" to reinstate #2994 

Co-authored-by: Daniel Wasserman <wassermandaniel8@gmail.com>
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/s
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants