Repository navigation
Description
Problem
Every chain touchpoint reads one blockchain.rpc_url (or --rpc-url). When that provider goes down, rate-limits, or wedges:
- the daemon fails its startup preflight (
check_rpc_reachability,crates/node/src/runtime/mod.rs); - the multiplexed chain-event poller backs off, so blacklist, slash, capacity-bond and fee-share observations stall;
- voucher redemption and settlement stop, and redeemable value can run past pool/channel deadlines;
- CLI
fetch/bundle pullcannot discover nodes or open a channel.
An operator with a paid backup provider has no way to use it. The fix: accept an ordered list of RPC URLs and fail over to the next one when the active one fails.
Current shape
- Config:
BlockchainConfig::rpc_url: Option<String>(crates/common/src/config/types.rs) resolves toResolvedConfig.blockchain.rpc_url: String(crates/common/src/config/resolved.rs, validated incrates/common/src/config/mod.rs, including env expansion and redaction). - Daemon:
ProviderFactory(crates/node/src/runtime/mod.rs) builds every node provider role (read_only,shared_head, seller/buyerwallet) withProviderBuilder::new().connect_http(url). That makes it the single place to swap the transport. - Client/CLI:
decdn_client::provider::build_provider(crates/client/src/provider.rs),decdn_client::discovery::active_nodes(crates/client/src/discovery.rs), and directconnect_httpcalls incli/src/commands/{publish,setup,doctor/chain}.rs.chain_ctx::resolve_commonresolves--rpc-urlfor about 15 CLI commands. - About 40 non-test source files mention
rpc_url.
Approach
1. Transport: a priority-failover tower service (write our own; don't use alloy's FallbackLayer)
alloy 2.x ships alloy::transports::layers::FallbackLayer. It does not match "priority order, continue with the next":
- It ranks endpoints by a latency/stability score, not by configured order, so traffic drifts to whichever endpoint scores best. A cheap public RPC can end up ahead of the operator's primary.
- By default it sends each request to the top N endpoints in parallel. That multiplies RPC bills and sends
eth_sendRawTransactionto several providers at once. - A JSON-RPC error packet (for example a provider-specific "block range too large") wins the race. Failover happens only on transport errors.
What to build instead is a small Service<RequestPacket> (about 100 lines plus tests) wrapping Vec<Http<Client>>:
- Try endpoints in configured order. Send each request to one endpoint at a time.
- Fail over on transport-level failures: connect error, timeout, HTTP 5xx, HTTP 429. Do not fail over on JSON-RPC error responses. Those are deterministic answers, and
multiplexed_poller::is_range_rejectionalready handles range caps (fix(node): shrink the eth_getLogs window on provider range caps; alert on never-ticked watchers #2152). - Sticky with cooldown: after a failure, mark the endpoint down for a cooldown and keep using the next healthy one. Each request then pays the dead endpoint's timeout at most once per cooldown, instead of on every call. After the cooldown, probe the higher-priority endpoint again and return to it when it recovers.
- Expose an endpoint epoch: a counter that increments every time the active endpoint changes. See §2.
Put it in decdn-client next to build_provider (both node and cli already depend on it). Build it through ClientBuilder::default().transport(svc, is_local) and ProviderBuilder::connect_client. The feature needs no new alloy features: tower is already a workspace dep, pinned to alloy's major.
2. Correctness hazard: head and logs from different endpoints (must fix)
SharedHead (crates/node/src/chain_events/shared_head.rs) is safe because the head it returns is never ahead of the chain that the next get_logs reads. multiplexed_poller reads head, runs get_logs [start, end], then advances every route's checkpoint to end.
Failover breaks that safety. Say the head comes from endpoint A at block 1000. Endpoint A then fails, and get_logs [990, 1000] is served by endpoint B, which is synced to block 995. Many providers return an empty result (not an error) for blocks past their tip. The checkpoint moves to 1000, and events in 996-1000 are lost for good: blacklist entries, slashes, bond changes. This is the same class as the #751/#762 hazard.
Recommended fix: the poller reads the transport epoch before the head read and again after get_logs. If the epoch changed, the tick fails into backoff without advancing any checkpoint, and SharedHead drops its cached value. The next tick reads head and logs from the same endpoint. Add a unit test with a two-endpoint fake transport that fails over mid-tick.
Other cross-endpoint effects are benign, and each is worth one test:
- Pinned-block reads (
blacklist_watcher.block(BlockId::Number(at))): a lagging endpoint returns "header not found", which is an error and gets retried. - Nonce (
with_simple_nonce_managementinProviderFactory::wallet): the nonce is fetched per tx. A lagging endpoint can return a stale nonce, which gives "nonce too low", an error that gets retried. - Receipt polling after a mid-flight failover: the new endpoint may not have the tx yet, so polling runs longer. That is fine, because re-broadcasting the same signed raw tx is idempotent by hash.
- Filters and subscriptions: none are used; everything is
eth_getLogspolling. Keep it that way. Filter IDs are endpoint-local.
3. Config and CLI
Pre-launch, so replace the field; no compat shim:
blockchain.rpc_urls: Vec<String>(non-empty, priority order), replacingrpc_url. Each entry gets today's validation (http/https scheme, env expansion,<redacted> (N chars)redaction).--rpc-urlbecomes repeatable (ArgAction::Append). A flag list replaces the config list; the two are not merged.- Optional
blockchain.rpc_failover_cooldown_ms, with a default. [your call] whether this ships as a knob or a constant. Per spec discipline, prefer a constant until an operator needs to tune it.
4. Everything that consumes the URL
ProviderFactory(all four roles) plus theblacklist_rpc_url/ChainHandlers.rpc_urlplumbing.check_rpc_reachabilitypreflight: pass when at least one endpoint is healthy, and log each unreachable one by index.decdn doctorchain check: probe every endpoint and report each one's health and chain-id. Also check that all endpoints report the sameeth_chainId, and refuse to start on a mismatch. A backup on the wrong chain is worse than no backup.build_provider,discovery::active_nodes,publish,setup, andchain_ctx::resolve_commonand their callers.decdn config init/ example configs,config validate, the SIGHUP reload path (check whetherrpc_urlis reloadable today; keep the same semantics), and redaction incrates/common/src/redact.rsandmain.rserror rendering.- e2e fixtures (
crates/e2e/src/{chain,node}.rs): add one e2e test with a dead primary and a live anvil secondary, where the node settles through the secondary.
5. Observability
decdn_chain_rpc_failover_total{from,to}counter anddecdn_chain_rpc_active_endpointgauge. Label by index, never by URL, because URLs carry API keys.- A log line on each switch and on each recovery, with the index and the redacted host.
- Update
appendix-observability.mdand the monitoring↔exporter CI gate.
Downstream (separate PRs)
sponsord/path-depends on these crates and reads its ownSPONSOR_*RPC config. Move it to the same list.devops/Ansible templates renderrpc_url.website/docs/config reference.
Acceptance criteria
-
blockchain.rpc_urls(non-empty, ordered) and a repeatable--rpc-urlreplace the single-URL field everywhere. - One priority-failover transport in
decdn-clientis used by every daemon provider role and every CLI chain path. - Failover happens on transport errors, 5xx, and 429, and never on JSON-RPC error responses. A failed endpoint sits out a cooldown; the primary is re-probed and restored after recovery.
- A mid-tick failover never advances a chain-event checkpoint (unit test with a two-endpoint fake).
- Preflight passes when any endpoint is healthy. Startup refuses endpoints that disagree on
eth_chainId. -
decdn doctorreports health per endpoint. - Failover metrics are labelled by index. No URL appears in any log, metric, or error.
- e2e test: dead primary plus live secondary, and the node settles.
Open decisions
- [your call] Build this vs. document an external proxy. Operators could put an RPC proxy (eRPC, dshackle) in front of one
rpc_urltoday at zero code cost. Reasons to build it in anyway: CLI/SDK clients will not run a proxy, and a proxy has the same head/logs hazard from §2 that only our poller can close. Recommendation: build it in. - [your call] Cooldown as a config knob or a constant.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Projects
- StatusShow more project fieldsDone
Activity
Metavcl commentedon Oct 10, 2026
Configured priority plus sticky cooldown makes sense here. Two cases seem worth adding to the tests:
Which chain(s) are you targeting? BlockPI could be evaluated as a keyed backup in the ordered list: https://blockpi.io/chains/
The useful acceptance test is settlement and uninterrupted event coverage with the primary disabled—not just a successful
eth_chainId.For RPC package purchases, use discount code
buildwithblockpi.alpergundogdu commentedon Nov 26, 2026
RPC providers can handle failovers as @Metavcl mentioned, instead of us building a whole stack for it, I'll close this one.