Skip to content

Bump alloy-ethers-typecast and refactor ReadableClient constructors#1902

Merged
hardyjosh merged 12 commits intomainfrom
2025-05-27-multiple-rpc-read
Jun 11, 2025
Merged

Bump alloy-ethers-typecast and refactor ReadableClient constructors#1902
hardyjosh merged 12 commits intomainfrom
2025-05-27-multiple-rpc-read

Conversation

@findolor
Copy link
Copy Markdown
Collaborator

@findolor findolor commented May 29, 2025

Caution

Do not merge before this PR merges rainlanguage/rainlang#330

Motivation

See issue: #1674

Solution

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

fix #1674

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced error handling for RPC provider failures with more consistent, detailed error messages across multiple features.
    • Updated tests to align with new error formats, improving reliability in error detection and reporting.
    • Optimized RPC client usage by consolidating repeated calls and supporting multiple RPC URLs, boosting performance.
  • Chores

    • Updated internal dependencies to newer git revisions for improved stability and compatibility.

@findolor findolor added this to the Raindex SDK v1 milestone May 29, 2025
@findolor findolor self-assigned this May 29, 2025
@findolor findolor added the rust Related to rust crates label May 29, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 29, 2025

Warning

Rate limit exceeded

@findolor has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 51 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 38067ab and ed52410.

📒 Files selected for processing (1)
  • crates/common/src/add_order.rs (9 hunks)

"""

Walkthrough

This change updates all instantiations of ReadableClientHttp and related types from single-URL constructors to multi-URL constructors using vectors, even when only one URL is provided. Corresponding error handling and test assertions are updated to expect new error variants reflecting multi-provider failure aggregation. Dependency revisions are also updated in configuration files.

Changes

File(s) Change Summary
Cargo.toml, tauri-app/src-tauri/Cargo.toml, lib/rain.interpreter Updated git revision hashes for alloy-ethers-typecast, rain-error-decoding, and rain.interpreter subproject.
crates/common/src/add_order.rs, deposit.rs, dotrain_order/mod.rs, erc20.rs, fuzz/impls.rs, Replaced new_from_url with new_from_urls([url]) for client initialization. Updated error handling and assertions.
rainlang.rs, transaction.rs, unit_tests/mod.rs, quote/src/order_quotes.rs, quote/src/rpc.rs
crates/cli/src/commands/order/calldata.rs, quote/src/quote.rs, packages/orderbook/test/quote/test.test.ts Updated test assertions to match new error messages and error variant structures.
tauri-app/src-tauri/src/commands/chain.rs, charts.rs Switched to multi-URL client initialization and updated error assertions to match new error structures in tests.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant ReadableClientHttp

    Caller->>ReadableClientHttp: new_from_urls([rpc_url])
    ReadableClientHttp-->>Caller: Client instance (supports multiple URLs)

    Caller->>ReadableClientHttp: Perform RPC call
    alt All providers fail
        ReadableClientHttp-->>Caller: Error: AllProvidersFailed { url -> error }
    else Success
        ReadableClientHttp-->>Caller: Result
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Implement multi-URL support for RPC read operations using vector-based client constructors (1674)
Update error handling to reflect aggregated errors from multiple RPC providers (1674)
Modify tests to expect new error variants and messages related to multi-provider failures (1674)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.
"""

Possibly related PRs

Suggested reviewers

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

@findolor findolor requested review from 0xgleb and hardyjosh June 11, 2025 08:54
Copy link
Copy Markdown
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: 9

🔭 Outside diff range comments (2)
crates/common/src/add_order.rs (2)

101-110: 🛠️ Refactor suggestion

Avoid per-token HTTP client re-construction – cache by RPC URL.

Inside the input loop a brand-new ReadableClientHttp instance is built for every token missing decimals.
On a deployment containing n tokens sharing the same network this spawns n identical hyper clients, TLS hand-shakes, etc. – unnecessary CPU and connection overhead.

Consider re-using one client per RPC URL:

-                let client =
-                    ReadableClientHttp::new_from_urls(vec![input_token.network.rpc.to_string()])?;
+                let rpc = input_token.network.rpc.to_string();
+                // Lazily cache clients per RPC in a local HashMap.
+                let client = rpc_clients
+                    .entry(rpc.clone())
+                    .or_insert_with(|| {
+                        // safe: unwrap bubbled up later through `?`
+                        ReadableClientHttp::new_from_urls(vec![rpc]).expect("valid rpc url")
+                    })
+                    .clone();

(A similar optimisation applies to the outputs loop below.)
This keeps the change local and preserves the public API.


132-140: 🧹 Nitpick (assertive)

Duplicate pattern from input loop – centralise logic

The output loop repeats the same fetch-decimals pattern. After introducing the cache above, extract the body into a small helper (async fn fetch_decimals(token_cfg, rpc_clients) -> Result<u8, …>).
Reduces ~20 lines of duplication, makes the intent explicit, and eases future maintenance.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e19c2db and c4921d7.

⛔ Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • tauri-app/src-tauri/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (9)
  • Cargo.toml (2 hunks)
  • crates/cli/src/commands/order/calldata.rs (1 hunks)
  • crates/common/src/add_order.rs (7 hunks)
  • crates/common/src/dotrain_order/mod.rs (1 hunks)
  • crates/common/src/fuzz/impls.rs (2 hunks)
  • crates/common/src/unit_tests/mod.rs (1 hunks)
  • crates/quote/src/order_quotes.rs (1 hunks)
  • tauri-app/src-tauri/Cargo.toml (2 hunks)
  • tauri-app/src-tauri/src/commands/charts.rs (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tauri-app/src-tauri/src/commands/charts.rs (1)
crates/cli/src/commands/chart/mod.rs (1)
  • get_settings (73-98)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: git-clean
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: Deploy-Preview
  • GitHub Check: test
🔇 Additional comments (5)
tauri-app/src-tauri/Cargo.toml (1)

41-41: Confirm transitive compatibility after git-rev bumps

Both alloy-ethers-typecast and rain-error-decoding now point to newer commits.
Please run cargo update -p alloy-ethers-typecast --precise adda117b1f43e1a4dfa012299e71f2b0e73f46f4 (and the same for rain-error-decoding) and execute the full test suite to ensure there are no semver-breaking changes or feature-flag mismatches.

Also applies to: 64-64

Cargo.toml (1)

15-15: Workspace lockfile needs regeneration

Updating the git revisions at workspace level requires committing the refreshed Cargo.lock to keep downstream CI reproducible.
Run cargo generate-lockfile in the workspace root and include the diff.

Also applies to: 54-54

tauri-app/src-tauri/src/commands/charts.rs (1)

31-32: Import correctly scoped & necessary

The added ReadableClientError import is scoped inside the test module and is required for pattern-matching the new aggregated error variant. Looks good.

crates/common/src/add_order.rs (2)

1166-1202: 👍 Updated test correctly targets aggregated provider error

The new assertion accurately reflects the AllProvidersFailed variant introduced by alloy-ethers-typecast.


1541-1562: 👍 Consistent error‐variant expectation in calldata test

Mirrors the previous adjustment; looks good.

Comment thread crates/cli/src/commands/order/calldata.rs
Comment thread crates/quote/src/order_quotes.rs Outdated
Comment thread crates/common/src/dotrain_order/mod.rs Outdated
Comment thread crates/common/src/unit_tests/mod.rs
Comment thread crates/common/src/fuzz/impls.rs
Comment thread crates/common/src/fuzz/impls.rs
Comment thread tauri-app/src-tauri/src/commands/charts.rs
Comment thread crates/common/src/add_order.rs Outdated
Comment thread crates/common/src/add_order.rs
Copy link
Copy Markdown
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: 2

♻️ Duplicate comments (2)
crates/common/src/add_order.rs (2)

132-134: Same optimisation opportunity as for inputs

The output-token branch duplicates the per-iteration client creation noted above. Re-use the cached client here as well.


226-230: Redundant clone() persists

Earlier feedback pointed out that rpc_url.clone() allocates unnecessarily when the string is already owned. The same line still exists:

ReadableClientHttp::new_from_urls(vec![rpc_url.clone()])?

Drop the clone() call:

-ReadableClientHttp::new_from_urls(vec![rpc_url.clone()])?
+ReadableClientHttp::new_from_urls(vec![rpc_url.to_string()])?
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c4921d7 and aac939d.

📒 Files selected for processing (3)
  • crates/common/src/add_order.rs (7 hunks)
  • crates/common/src/dotrain_order/mod.rs (1 hunks)
  • crates/quote/src/order_quotes.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: git-clean
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
🔇 Additional comments (5)
crates/common/src/dotrain_order/mod.rs (1)

353-355: Instantiation looks good

Switching to new_from_urls is consistent with the refactor and avoids the redundant clone() allocation highlighted earlier.

crates/common/src/add_order.rs (4)

164-165: LGTM – clone removed

Constructing the client with the owned rpc_url directly is cleaner and avoids the extra allocation.


235-236: LGTM – unnecessary clone removed

Passing the owned rpc_url directly is cleaner.


1165-1201: (No actionable issues – test updates correctly reflect the new aggregated-error variant.)


1541-1560: (No actionable issues – test updates correctly reflect the new aggregated-error variant.)

Comment thread crates/quote/src/order_quotes.rs Outdated
Comment thread crates/common/src/add_order.rs Outdated
Copy link
Copy Markdown
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: 3

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bd7ffa1 and 38067ab.

📒 Files selected for processing (2)
  • crates/common/src/add_order.rs (8 hunks)
  • crates/quote/src/order_quotes.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (2)
crates/common/src/add_order.rs (2)

87-88: 👍 Cached RPC clients eliminate N× overhead

Creating rpc_clients: HashMap<String, ReadableClientHttp> up-front is a solid optimisation and directly addresses the earlier review about redundant client instantiation.


1178-1214: Tests accurately validate aggregated-error variant

The updated assertions correctly introspect ReadableClientError::AllProvidersFailed and ensure the nested per-URL error is of the expected kind. Looks great.

Also applies to: 1553-1574

Comment thread crates/quote/src/order_quotes.rs
Comment thread crates/common/src/add_order.rs Outdated
Comment thread crates/common/src/add_order.rs
Copy link
Copy Markdown
Collaborator

@0xgleb 0xgleb left a comment

Choose a reason for hiding this comment

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

Probably would have been easier to keep new_from_url alongside new_from_urls and only use new_from_urls when there is actually more than one URL available. And new_from_urls could also have taken something generic that can be converted to String. But this is all for alloy-ethers-typecast, this PR works

Comment thread crates/common/src/add_order.rs Outdated
.entry(input_token.network.rpc.to_string())
.or_insert_with(|| {
ReadableClientHttp::new_from_urls(vec![input_token.network.rpc.to_string()])
.expect("Failed to create RPC client")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We shouldn't be using .expect in non-test code

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah already updated that one no problem

@hardyjosh hardyjosh merged commit 42894f5 into main Jun 11, 2025
17 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Aug 12, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rust Related to rust crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add multiple url support for RPC read operations

3 participants