Skip to content

feat: mrh watcher #974

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

feat: mrh watcher #974

wants to merge 4 commits into from

Conversation

jackstar12
Copy link
Member

@jackstar12 jackstar12 commented Jun 22, 2025

Summary by CodeRabbit

  • New Features
    • Introduced a watcher that monitors blockchain transactions for reverse swaps and broadcasts relevant status updates.
    • Added support for a new swap update status: "transaction.direct".
  • Improvements
    • Enhanced database query capabilities for retrieving reverse swap routing hints.
    • Updated the application to handle and log direct transaction updates for swaps.
  • Tests
    • Added comprehensive tests to verify correct handling and broadcasting of direct transaction updates.

Copy link

coderabbitai bot commented Jun 22, 2025

Walkthrough

This change introduces a new asynchronous watcher, MrhWatcher, to monitor blockchain transactions for reverse swaps, propagating updates through the system. Supporting changes include new database query capabilities, transaction utility methods, and status handling in both Rust and TypeScript components to recognize and process direct transaction updates.

Changes

File(s) Change Summary
boltzr/src/chain/mod.rs Added public module declaration for mrh_watcher.
boltzr/src/chain/mrh_watcher.rs Introduced MrhWatcher struct and implementation for monitoring transactions and broadcasting swap status updates; includes async test.
boltzr/src/chain/utils.rs Added txid_hex method to Transaction enum for hex string extraction of transaction ID.
boltzr/src/db/helpers/reverse_swap.rs Extended ReverseSwapHelper trait and implementations with get_routing_hints method querying routing hints by script pubkeys.
boltzr/src/swap/manager.rs Spawned an MrhWatcher task in Manager::start, integrating it into the swap management lifecycle.
boltzr/src/swap/status.rs
lib/consts/Enums.ts
Added TransactionDirect variant/member to SwapUpdate enum (Rust) and SwapUpdateEvent enum (TypeScript).
lib/sidecar/Sidecar.ts Added handling for TransactionDirect status in handleSentSwapUpdate, emitting swap.update event with transaction info.
test/integration/sidecar/Sidecar.spec.ts Added test verifying TransactionDirect update handling and event emission in Sidecar.

Sequence Diagram(s)

sequenceDiagram
    participant Blockchain as Blockchain Stream
    participant MrhWatcher
    participant Database
    participant BroadcastChannel
    participant Sidecar

    Blockchain->>MrhWatcher: New Transaction
    MrhWatcher->>Database: Query routing hints for outputs
    Database-->>MrhWatcher: Matching routing hints
    MrhWatcher->>BroadcastChannel: SwapStatus(TransactionDirect)
    BroadcastChannel->>Sidecar: SwapStatus(TransactionDirect)
    Sidecar->>Sidecar: handleSentSwapUpdate(TransactionDirect)
    Sidecar->>gRPC Stream: Write SwapUpdateRequest
Loading

Poem

A watcher wakes with eager eyes,
To scan the chain for swap surprise.
With hints it queries, swift and bright,
And broadcasts news through day and night.
Direct transactions now in view—
The sidecar logs each update too!
Hooray for swaps, and code anew! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-23T20_38_17_498Z-debug-0.log

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

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.

@jackstar12 jackstar12 force-pushed the feat/mrh-watcher branch 2 times, most recently from 779cea2 to 4d84988 Compare June 22, 2025 16:21
@jackstar12
Copy link
Member Author

@coderabbitai review

Copy link

coderabbitai bot commented Jun 22, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 2

🧹 Nitpick comments (2)
boltzr/src/swap/status.rs (1)

24-25: LGTM! Consistent enum variant addition.

The new TransactionDirect variant follows the existing pattern and matches the corresponding TypeScript enum value. The serialization string is consistent with the naming convention.

Consider adding this variant to the test cases in the test_swap_update_parse function to ensure it's properly covered.

boltzr/src/chain/mrh_watcher.rs (1)

65-65: Define the status string as a constant.

The status string "transaction.direct" is hardcoded. Consider defining it as a constant for better maintainability and consistency.

Add a constant at the module level:

const TRANSACTION_DIRECT_STATUS: &str = "transaction.direct";

Then use it in the SwapStatus construction:

-            status: "transaction.direct".to_string(),
+            status: TRANSACTION_DIRECT_STATUS.to_string(),
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f565cba and 4d84988.

📒 Files selected for processing (8)
  • boltzr/src/chain/mod.rs (1 hunks)
  • boltzr/src/chain/mrh_watcher.rs (1 hunks)
  • boltzr/src/chain/utils.rs (1 hunks)
  • boltzr/src/db/helpers/reverse_swap.rs (3 hunks)
  • boltzr/src/swap/manager.rs (3 hunks)
  • boltzr/src/swap/status.rs (1 hunks)
  • lib/consts/Enums.ts (1 hunks)
  • lib/sidecar/Sidecar.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build (ubuntu-latest, 20, stable)
  • GitHub Check: build-rust (ubuntu-latest, 20, stable)
  • GitHub Check: build-rust (ubuntu-latest, 20, stable)
  • GitHub Check: build (ubuntu-latest, 20, stable)
🔇 Additional comments (6)
boltzr/src/chain/utils.rs (1)

46-51: LGTM! Clean implementation of transaction ID extraction.

The method correctly handles both Bitcoin and Elements transaction types, using the appropriate txid extraction methods for each. The hex conversion is consistent and the implementation follows Rust conventions.

boltzr/src/chain/mod.rs (1)

10-10: LGTM! Standard module declaration.

The module declaration follows the existing pattern and is properly positioned with other module declarations.

lib/consts/Enums.ts (1)

51-51: LGTM! Consistent enum addition.

The new TransactionDirect enum member follows the existing naming convention and is properly positioned with other transaction-related events.

lib/sidecar/Sidecar.ts (1)

484-492: LGTM! Proper handling of TransactionDirect updates.

The implementation correctly:

  • Logs the update for debugging purposes
  • Creates and sends the appropriate swap update request
  • Uses optional chaining to safely handle potential undefined subscribeSwapUpdatesCall
  • Returns early to prevent fallthrough to the default case

The logic is consistent with the existing codebase patterns.

boltzr/src/db/helpers/reverse_swap.rs (1)

8-56: LGTM! Clean database helper implementation.

The new get_routing_hints method and its implementation follow the established patterns in this module. The type alias, trait method, and Diesel query are all properly structured.

boltzr/src/chain/mrh_watcher.rs (1)

1-161: Well-structured implementation with comprehensive test coverage.

The MrhWatcher implementation is clean and follows good async patterns. The test effectively validates the core functionality using mocks.

@jackstar12 jackstar12 force-pushed the feat/mrh-watcher branch 2 times, most recently from a2abc9d to 501f233 Compare June 23, 2025 19:42
@jackstar12 jackstar12 force-pushed the feat/mrh-watcher branch 2 times, most recently from 123586d to 9f0738b Compare June 23, 2025 20:24
@jackstar12 jackstar12 marked this pull request as ready for review June 23, 2025 20:37
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: 0

🧹 Nitpick comments (1)
test/integration/sidecar/Sidecar.spec.ts (1)

81-103: Good test coverage for TransactionDirect handling with minor suggestions.

The test case follows existing patterns and correctly verifies the new TransactionDirect functionality. However, consider these improvements:

  1. Address type casting: The as any cast on line 88 suggests potential type safety issues. Consider using proper typing or creating a proper mock.

  2. Consider edge case testing: The test only covers the happy path. You might want to add tests for error scenarios, such as missing transaction info or invalid data.

-      update.setTransactionInfo(transactionInfo as any);
+      update.setTransactionInfo(transactionInfo);

If the type casting is necessary due to protobuf type constraints, consider adding a comment explaining why the cast is required.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4d84988 and a5cc029.

📒 Files selected for processing (9)
  • boltzr/src/chain/mod.rs (1 hunks)
  • boltzr/src/chain/mrh_watcher.rs (1 hunks)
  • boltzr/src/chain/utils.rs (1 hunks)
  • boltzr/src/db/helpers/reverse_swap.rs (3 hunks)
  • boltzr/src/swap/manager.rs (3 hunks)
  • boltzr/src/swap/status.rs (1 hunks)
  • lib/consts/Enums.ts (1 hunks)
  • lib/sidecar/Sidecar.ts (1 hunks)
  • test/integration/sidecar/Sidecar.spec.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (8)
  • boltzr/src/chain/mod.rs
  • lib/consts/Enums.ts
  • lib/sidecar/Sidecar.ts
  • boltzr/src/swap/status.rs
  • boltzr/src/swap/manager.rs
  • boltzr/src/chain/utils.rs
  • boltzr/src/db/helpers/reverse_swap.rs
  • boltzr/src/chain/mrh_watcher.rs
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build-rust (ubuntu-latest, 20, stable)
  • GitHub Check: build (ubuntu-latest, 20, stable)
  • GitHub Check: build-rust (ubuntu-latest, 20, stable)
  • GitHub Check: build (ubuntu-latest, 20, stable)
🔇 Additional comments (1)
test/integration/sidecar/Sidecar.spec.ts (1)

9-13: LGTM! Mock enhancement supports new test case.

The addition of the emit method to the eventHandler mock is consistent with the existing pattern and necessary for testing the new TransactionDirect functionality.

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