Skip to content

feat(monero-rpc-pool): TCP pool#497

Merged
binarybaron merged 13 commits intomasterfrom
feat/tcp-pool
Aug 4, 2025
Merged

feat(monero-rpc-pool): TCP pool#497
binarybaron merged 13 commits intomasterfrom
feat/tcp-pool

Conversation

@binarybaron
Copy link
Copy Markdown

@binarybaron binarybaron commented Aug 3, 2025

  • Responses are now streamed to the caller (after the first 1kb)
  • TCP and Tor connections are cached
  • "Time left till synced" improved

Summary by CodeRabbit

  • New Features

    • Added a stress test tool for the Monero RPC Pool server, supporting configurable concurrency, duration, network selection, and optional Tor routing.
    • Introduced connection pooling for HTTP and Tor streams, enabling more efficient and persistent proxying.
  • Enhancements

    • Improved bandwidth tracking with a lock-free, concurrent approach for more accurate and efficient monitoring.
    • Refined Monero network configuration handling across components for stronger typing and consistency.
    • Enhanced Monero wallet UI with improved sync time estimation and progress display.
    • Added ability to fetch Monero wallet seed phrase from the GUI.
  • Bug Fixes

    • Fixed conditional display of completion messages in the swap UI based on refund status.
  • Chores

    • Updated and reorganized dependencies for improved maintainability.
    • Added changelog entries documenting new connection caching and pooling behavior.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 3, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Caution

Review failed

The pull request is closed.

Walkthrough

This update introduces a new HTTP/1 connection pool for persistent TCP and Tor streams in the Monero RPC Pool, refactors bandwidth tracking to be lock-free, and centralizes network configuration using the Network enum. It adds a stress test binary, updates dependency management, and enhances GUI sync estimation, wallet state, and Redux integration.

Changes

Cohort / File(s) Change Summary
Connection Pool Feature
monero-rpc-pool/src/connection_pool.rs, monero-rpc-pool/src/lib.rs, monero-rpc-pool/src/proxy.rs
Adds a concurrency-safe HTTP/1 connection pool supporting TCP and Tor streams, integrates it into app state, and refactors proxy logic to use streaming responses with bandwidth tracking and connection reuse.
Bandwidth Tracker Refactor
monero-rpc-pool/src/pool.rs
Refactors bandwidth tracking to use a lock-free concurrent queue, updates related fields and methods, and switches NodePool network field to use the strongly-typed Network enum.
Network Configuration Centralization
monero-rpc-pool/src/config.rs, monero-rpc-pool/src/database.rs, monero-rpc-pool/src/types.rs, monero-rpc-pool/src/main.rs, swap/src/bin/asb.rs, swap/src/cli/api.rs
Changes all relevant structs and functions to use the Network enum for network configuration, updates constructors and database helpers, and propagates this change through main entry points and swap/CLI integration.
Dependency and Binary Management
monero-rpc-pool/Cargo.toml
Adds a new feature-gated "stress-test" binary, reorganizes dependencies by category, updates versions, and introduces new crates for tracing, concurrency, and serialization.
Stress Test Binary
monero-rpc-pool/src/bin/stress_test.rs
Introduces a new async binary for stress testing the Monero RPC Pool server with configurable duration, concurrency, network, Tor support, and verbose logging.
GUI Sync Estimation Refactor
src-gui/src/renderer/components/pages/monero/components/WalletOverview.tsx
Extracts sync time estimation logic into a hook, improves block/bandwidth/time calculations, and updates UI to use the new hook.
Redux Wallet State Enhancements
src-gui/src/renderer/rpc.ts, src-gui/src/store/features/walletSlice.ts
Adds support for fetching and storing the wallet restore height, introduces a new action and state property, and adds a function to fetch the Monero seed.
Swap GUI Text Update
src-gui/src/renderer/components/pages/swap/swap/done/BitcoinRefundedPage.tsx
Makes the completion message conditional on the btc_refund_finalized prop.
Changelog
CHANGELOG.md
Adds an entry noting that the Monero RPC pool now caches TCP and Tor streams for GUI, CLI, and ASB.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Proxy (AppState)
    participant ConnectionPool
    participant Node
    participant BandwidthTracker

    Client->>Proxy: Send HTTP request (e.g., /get_info)
    Proxy->>ConnectionPool: try_get(key)
    alt Connection exists
        ConnectionPool-->>Proxy: GuardedSender (reuse connection)
    else No connection
        Proxy->>ConnectionPool: insert_and_lock(key, new_sender)
        ConnectionPool-->>Proxy: GuardedSender (new connection)
    end
    Proxy->>Node: Forward request via GuardedSender
    Node-->>Proxy: Streaming HTTP response
    Proxy->>BandwidthTracker: record_bytes (as data streams)
    Proxy-->>Client: Stream response (buffer first chunk for error detection)
Loading
sequenceDiagram
    participant StressTest
    participant PoolServer
    participant ReqwestClient

    loop For duration, concurrency N
        StressTest->>PoolServer: GET /get_info (via ReqwestClient)
        PoolServer-->>StressTest: HTTP response
        StressTest->>StressTest: Record success/failure, response time
    end
    StressTest->>StressTest: Print statistics (success, fail, avg time, RPS)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

In tunnels of TCP and Tor I leap,
My paws on the streams that the pool now keeps.
Bandwidth flows freely, no locks in my den,
Network enums guide me again and again.
With stress tests and hooks, the GUI feels bright—
A rabbit’s delight in code running right!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 886dbcb and 6adf216.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (17)
  • CHANGELOG.md (1 hunks)
  • monero-rpc-pool/Cargo.toml (1 hunks)
  • monero-rpc-pool/src/bin/stress_test.rs (1 hunks)
  • monero-rpc-pool/src/config.rs (3 hunks)
  • monero-rpc-pool/src/connection_pool.rs (1 hunks)
  • monero-rpc-pool/src/database.rs (2 hunks)
  • monero-rpc-pool/src/lib.rs (8 hunks)
  • monero-rpc-pool/src/main.rs (2 hunks)
  • monero-rpc-pool/src/pool.rs (6 hunks)
  • monero-rpc-pool/src/proxy.rs (8 hunks)
  • monero-rpc-pool/src/types.rs (2 hunks)
  • src-gui/src/renderer/components/pages/monero/components/WalletOverview.tsx (5 hunks)
  • src-gui/src/renderer/components/pages/swap/swap/done/BitcoinRefundedPage.tsx (1 hunks)
  • src-gui/src/renderer/rpc.ts (4 hunks)
  • src-gui/src/store/features/walletSlice.ts (4 hunks)
  • swap/src/bin/asb.rs (1 hunks)
  • swap/src/cli/api.rs (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/tcp-pool

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

Support

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

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 generate unit tests to generate unit tests for 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.

@binarybaron
Copy link
Copy Markdown
Author

bugbot run

cursor[bot]

This comment was marked as outdated.

@binarybaron binarybaron marked this pull request as ready for review August 4, 2025 12:17
let oldest_time = self.entries.front().unwrap().timestamp;
let duration_secs = (now - oldest_time).as_secs_f64();
let oldest_time = valid_entries.iter().map(|e| e.timestamp).min().unwrap();
let duration_secs = now.duration_since(oldest_time).as_secs_f64();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Race Condition in BandwidthTracker Causes Data Loss

The BandwidthTracker::get_kb_per_sec() method contains a race condition and data loss. It misuses crossbeam::deque::Injector by attempting a "drain-filter-reinsert" pattern. Since Injector::steal() is a destructive operation, concurrent calls to get_kb_per_sec() or record_bytes() can lead to permanent loss or duplication of bandwidth entries, resulting in inaccurate calculations. Additionally, the Steal::Retry case is incorrectly handled as Empty instead of being retried.

Fix in Cursor Fix in Web

@binarybaron binarybaron merged commit b0b8df8 into master Aug 4, 2025
8 checks passed
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.

1 participant