feat(indexer): redundant RPC provider switching with cool-down (#151)#190
Merged
ayomideadeniran merged 1 commit intoSoroLabs:mainfrom Mar 30, 2026
Conversation
…abs#151) - Add ProviderManager to rpc.rs: holds a prioritised list of RPC URLs behind Arc<RwLock<>> for thread-safe access - On 5xx, 429, or connection error the current provider is immediately marked unhealthy and the next healthy URL is tried with zero added latency on the happy path - Failed providers re-enter the rotation after RPC_COOLDOWN_SECS (default 60s) - When all providers are unhealthy, exponential back-off kicks in and a critical error is logged - Config: add rpc_fallback_urls (RPC_FALLBACK_URLS) and rpc_cooldown_secs (RPC_COOLDOWN_SECS) fields - Add backend/indexer/.env.example documenting all env vars - Wire ProviderManager through IndexerState and poll_once
|
@magaret457 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
Thanks for the PR! This is currently under review and I will get back to you shortly. |
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.
Summary
Closes #151
Implements redundant RPC provider failover for the indexer, resolving #151.
Changes
rpc.rsProviderManager— a thread-safe (Arc<RwLock<>>) prioritised list of RPC URLs.healthy_url()walks the list and returns the first non-failed provider. If a provider's cool-down has expired it is automatically re-enabled.mark_failed(url)stamps a provider with the currentInstant; it stays out of rotation forRPC_COOLDOWN_SECS(default 60 s).fetch_eventsnow accepts&ProviderManagerinstead of a bare&str. On a 5xx, 429, or connection error it callsmark_failedand loops immediately to the next provider — zero added latency on the happy path.error!log is emitted.config.rsrpc_fallback_urls: Vec<String>(fromRPC_FALLBACK_URLS, comma-separated) andrpc_cooldown_secs: u64(fromRPC_COOLDOWN_SECS, default60).indexer.rsIndexerStategains aproviders: ProviderManagerfield.poll_oncereceives&ProviderManagerand passes it tofetch_events.main.rsProviderManagerfrom config and injects it intoIndexerState.backend/indexer/.env.example(new)Failover Strategy
Primary OK → use primary (no overhead)
Primary 5xx/429/timeout → mark_failed(primary), try fallback-1 immediately
All failed → exponential back-off + critical log, retry until one recovers
Cool-down expires → provider silently re-enters rotation on next healthy_url() call
Testing
rpc.rsare unaffected (they test decode/parse logic, not the HTTP layer).RPC_URLto an invalid endpoint andRPC_FALLBACK_URLSto a valid one — the indexer should switch within one poll cycle.