fix(simulator): rewrite wss/ws RPC URL to https/http for fork backend#129
Merged
Conversation
The revm-backed fork backend issues one-shot `eth_getStorageAt` / `eth_getBalance` requests via AlloyDB's HTTP transport. `ETH_RPC_URL`, however, is shared with the streaming subscription path (newHeads, logs, pending tx) which requires a `wss://` / `ws://` scheme for the persistent connection. Without normalisation, `connect_http` on a wss URL fails every detected cycle with `Transport error: builder error for url (wss://...)` and floods the log on each block. Mempool tracking (analytical predictors) is unaffected, but the regular block-by-block arb validation path is silently broken. Fix: add `normalize_to_http_scheme` which rewrites `wss://` -> `https://` and `ws://` -> `http://` literally, leaving host / path / query intact. Apply at the boundary between `config.rpc_url` and the `ProviderBuilder::connect_http` call. Major providers (Alchemy, Infura, QuickNode) expose both transports on the same hostname so the rewritten URL routes to the correct endpoint. Operators keep a single env var. Unknown schemes (`ipc://`, `file://`, etc.) pass through unchanged so downstream parser surfaces a clear error rather than a silent miscast. Also dedents `sim_evm_fallback_total` doc-list continuation lines from 24 spaces to 4 to satisfy `-D clippy::doc_overindented_list_items` -- required to keep `cargo clippy --workspace -- -D warnings` green on rust 1.94. Tests: 6 unit tests covering wss, ws, https, http, unknown-scheme, and query-string preservation. 488 workspace tests, clippy clean.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The revm-backed fork backend issues one-shot
eth_getStorageAt/eth_getBalancerequests via AlloyDB's HTTP transport.ETH_RPC_URL, however, is shared with the streaming subscription path (newHeads, logs, pending tx) which requires awss:///ws://scheme for the persistent connection.Without normalisation,
ProviderBuilder::new().connect_http(parsed)on a wss URL fails every detected cycle with:Floods the log on every block (10-50 errors/sec when detection is active). Mempool tracking (analytical predictors) is unaffected, but the regular block-by-block arb validation path is silently broken.
This surfaced after
ETH_RPC_URLwas flipped from https to wss to engage Alchemyalchemy_pendingTransactions+newHeadsover WebSocket for the PR #118 mempool work. Pre-existing bug — was lurking the whole time, only visible once the env var changed scheme.Fix
Add
normalize_to_http_scheme(url: &str) -> Stringwhich rewriteswss://->https://andws://->http://literally, leaving host / path / query intact. Apply at the boundary betweenconfig.rpc_urland theProviderBuilder::connect_httpcall inAetherEngine::new.Why HTTP, not WS-backed fork
revm itself is transport-agnostic — it consumes a
Databasetrait and AlloyDB wraps any alloyProvider. WS-backed fork works, but isn't preferred:Scheme rewrite gives operators a single
ETH_RPC_URLenv var while routing each consumer to the transport it actually wants.Why a literal rewrite
Alchemy, Infura, and QuickNode all expose both transports on the same hostname + path differing only in scheme:
wss://eth-mainnet.g.alchemy.com/v2/<key>https://eth-mainnet.g.alchemy.com/v2/<key>No new env var, no config-file changes, no operator coordination required.
Unknown schemes
IPC paths (
ipc:///tmp/reth.ipc), file URLs, anything notws(s)— pass through unchanged. Downstream parser surfaces a clear error rather than silently miscast.Side-effect: clippy fix
Develop's
crates/grpc-server/src/metrics.rsdoc-list continuation lines undersim_evm_fallback_totalwere indented to 24 spaces. Rust 1.94'sclippy::doc_overindented_list_itemslint rejects them under-D warnings. Dedented to 4 spaces — required to keepcargo clippy --workspace -- -D warningsgreen for the new tests.Tests
6 unit tests covering all scheme cases:
wss://->https://ws://->http://https://unchangedhttp://unchangedipc://(unknown scheme) unchanged488 workspace tests pass.
cargo clippy --workspace -- -D warningsclean.Impact
ETH_RPC_URL=wss://...ETH_RPC_URLis alreadyhttps://...Verification
Before (capture log on PR #118 branch):
... repeated 10-50 times/sec.
After (with this fix on
ETH_RPC_URL=wss://...):No
Transport errorlines.