Skip to content

feat: add backup RPC fallback support for MLS validation service#3415

Open
xmtp-coder-agent wants to merge 7 commits intoxmtp:mainfrom
xmtp-coder-agent:fix/issue-3355
Open

feat: add backup RPC fallback support for MLS validation service#3415
xmtp-coder-agent wants to merge 7 commits intoxmtp:mainfrom
xmtp-coder-agent:fix/issue-3355

Conversation

@xmtp-coder-agent
Copy link
Copy Markdown
Contributor

@xmtp-coder-agent xmtp-coder-agent commented Apr 8, 2026

Resolves #3355

Summary

  • FallbackSmartContractWalletVerifier — new verifier that wraps multiple RpcSmartContractWalletVerifier instances per chain and tries them sequentially, falling back on retryable errors (IO, Provider)
  • Backward-compatible JSON config — accepts both old format ("eip155:1": "url") and new array format ("eip155:1": ["url1", "url2"]) via serde(untagged) enum
  • Comma-separated env var supportCHAIN_RPC_X=url1,url2,url3 creates a fallback chain; single URLs continue to work as before
  • Updated chain_urls_default.json to use array format

Changes

File Change
crates/xmtp_id/src/scw_verifier/chain_rpc_verifier.rs Added FallbackSmartContractWalletVerifier + unit tests
crates/xmtp_id/src/scw_verifier/mod.rs UrlOrUrls deserializer, make_verifier() helper, updated new() to HashMap<String, Vec<Url>>, parse_chain_urls(), comma-separated env var parsing in upgrade(), unit tests
crates/xmtp_id/src/scw_verifier/chain_urls_default.json Converted to array format

Fallback Behavior

  • On retryable errors (IO, Provider), tries the next RPC endpoint
  • On non-retryable errors (bad signature format, etc.), returns immediately
  • If all endpoints fail, returns the last error
  • Single-URL chains use RpcSmartContractWalletVerifier directly (no overhead)

Test Plan

  • JSON parsing: array format, single-string format, mixed format
  • Default chain URLs parse correctly
  • make_verifier handles single, multiple, and empty URL lists
  • MultiSmartContractSignatureVerifier::new with multi-URL map
  • Fallback verifier construction
  • Mock verifier tests for retryable/non-retryable error behavior
  • Existing smart wallet integration tests (require Docker/Anvil — CI)

Note: Pre-existing xmtp_proto compilation errors (tonic codegen) prevent running tests locally. These errors exist on main as well and are unrelated to this PR.

Note

Add backup RPC fallback support for MLS validation service

  • Introduces FallbackSmartContractWalletVerifier in chain_rpc_verifier.rs that holds multiple RpcSmartContractWalletVerifier instances and tries each in order, skipping to the next on retryable errors and short-circuiting on non-retryable ones.
  • Updates MultiSmartContractSignatureVerifier to accept multiple RPC URLs per chain (via Vec<Url> instead of a single Url), using a new make_verifier helper to pick single or fallback verifier based on URL count.
  • Updates CHAIN_RPC_{eip_id} env var parsing to support comma-separated URLs, enabling fallback behavior at runtime without code changes.
  • Changes chain_urls_default.json from single URL strings to single-element arrays; adds UrlOrUrls enum so both formats remain valid in config files.
  • Behavioral Change: MultiSmartContractSignatureVerifier::new now takes HashMap<String, Vec<Url>>; callers constructing it directly must update their argument type.

Macroscope summarized a9c0298.

Support multiple RPC endpoints per chain with automatic fallback on
retryable errors. Adds FallbackSmartContractWalletVerifier that tries
RPCs sequentially, backward-compatible JSON parsing (single string or
array), and comma-separated env var support for CHAIN_RPC_X overrides.

Resolves xmtp#3355

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@xmtp-coder-agent xmtp-coder-agent requested a review from a team as a code owner April 8, 2026 20:03
std::io::Error doesn't implement RetryableError, so it can't be boxed
into VerifierError::Other. Use the Io variant which accepts io::Error
directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread crates/xmtp_id/src/scw_verifier/chain_rpc_verifier.rs
…er::new

Return an error early if an empty Vec is passed, rather than creating
a verifier that would panic at runtime.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread crates/xmtp_id/src/scw_verifier/chain_rpc_verifier.rs Outdated
XMTP Coder Agent and others added 2 commits April 8, 2026 20:14
Replace VerifierError::Io with a new VerifierError::Configuration
variant for config validation errors (empty URL lists). Io errors
should represent actual I/O failures, not invalid configuration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…_verifier

- ValidationResponse needs Debug for unwrap_err() in tests
- Replace unwrap() with remove(0) to satisfy clippy::unwrap-used

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

❌ Patch coverage is 94.01198% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.15%. Comparing base (027661c) to head (a9c0298).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
crates/xmtp_id/src/scw_verifier/mod.rs 91.66% 8 Missing ⚠️
...tes/xmtp_id/src/scw_verifier/chain_rpc_verifier.rs 97.18% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3415      +/-   ##
==========================================
- Coverage   83.21%   83.15%   -0.07%     
==========================================
  Files         378      378              
  Lines       51940    52098     +158     
==========================================
+ Hits        43224    43323      +99     
- Misses       8716     8775      +59     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

use super::*;

#[test]
fn test_parse_chain_urls_array_format() {
Copy link
Copy Markdown
Contributor

@neekolas neekolas Apr 9, 2026

Choose a reason for hiding this comment

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

Let's convert this to a table-based test. Should be easier to read

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.

MLS validation service backup RPC's

2 participants