Skip to content

feat(indexer): redundant RPC provider switching with cool-down (#151)#190

Merged
ayomideadeniran merged 1 commit intoSoroLabs:mainfrom
magaret457:feat/redundant-rpc-provider-switching
Mar 30, 2026
Merged

feat(indexer): redundant RPC provider switching with cool-down (#151)#190
ayomideadeniran merged 1 commit intoSoroLabs:mainfrom
magaret457:feat/redundant-rpc-provider-switching

Conversation

@magaret457
Copy link
Copy Markdown
Contributor

Summary

Closes #151

Implements redundant RPC provider failover for the indexer, resolving #151.

Changes

rpc.rs

  • Introduces ProviderManager — 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 current Instant; it stays out of rotation for RPC_COOLDOWN_SECS (default 60 s).
  • fetch_events now accepts &ProviderManager instead of a bare &str. On a 5xx, 429, or connection error it calls mark_failed and loops immediately to the next provider — zero added latency on the happy path.
  • When all providers are unhealthy, exponential back-off (2 s → 60 s) kicks in and a error! log is emitted.

config.rs

  • New fields: rpc_fallback_urls: Vec<String> (from RPC_FALLBACK_URLS, comma-separated) and rpc_cooldown_secs: u64 (from RPC_COOLDOWN_SECS, default 60).

indexer.rs

  • IndexerState gains a providers: ProviderManager field.
  • poll_once receives &ProviderManager and passes it to fetch_events.

main.rs

  • Constructs ProviderManager from config and injects it into IndexerState.

backend/indexer/.env.example (new)

  • Documents all environment variables including the new RPC failover ones.

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

  • Existing unit tests in rpc.rs are unaffected (they test decode/parse logic, not the HTTP layer).
  • To manually test failover: set RPC_URL to an invalid endpoint and RPC_FALLBACK_URLS to a valid one — the indexer should switch within one poll cycle.

…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
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 30, 2026

@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! 🚀

Learn more about application limits

@ayomideadeniran
Copy link
Copy Markdown
Contributor

Thanks for the PR! This is currently under review and I will get back to you shortly.

@ayomideadeniran ayomideadeniran merged commit 32adceb into SoroLabs:main Mar 30, 2026
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.

[BACKEND] Implement Redundant RPC Provider Switching in Indexer

2 participants