Robust Provider
Robust, retrying wrapper around Alloy providers.
⚠️ WARNING: ACTIVE DEVELOPMENT ⚠️
This project is under active development and likely contains bugs. APIs and behaviour may change without notice. Use at your own risk.
About
Robust Provider is a Rust library that wraps Alloy providers with production-ready resilience features. It adds automatic retries, timeouts, and transparent failover between multiple RPC endpoints - making it ideal for applications that need reliable blockchain connectivity.
Table of Contents
Features
- Bounded timeouts - per-call timeouts prevent indefinite hangs on unresponsive RPC endpoints.
- Exponential backoff retries - automatic retry with configurable backoff for transient failures.
- Transparent failover - seamlessly switch from a primary provider to one or more fallback providers.
- Resilient subscriptions - WebSocket block subscriptions with automatic reconnection and lag detection.
Quick Start
Add robust-provider to your Cargo.toml:
[]
= "0.2.0"
Create a robust provider with automatic retries and fallback:
use ;
use RobustProviderBuilder;
use Duration;
use StreamExt;
async
Usage
Building a Provider
RobustProviderBuilder provides a fluent API for constructing a RobustProvider with custom settings:
use ProviderBuilder;
use RobustProviderBuilder;
use Duration;
// Standard configuration with retries
let provider = new.connect.await?;
let robust = new
.call_timeout
.max_retries
.build
.await?;
// With multiple fallback providers
let primary = new.connect.await?;
let fallback_1 = new.connect.await?;
let fallback_2 = new.connect_http;
let robust = new
.fallback
.fallback
.build
.await?;
Configuration Options
| Option | Default | Description |
|---|---|---|
call_timeout |
60s | Maximum time for RPC operations before timing out |
subscription_timeout |
120s | Maximum time to wait for subscription messages |
max_retries |
3 | Number of retry attempts before failing over |
min_delay |
1s | Base delay for exponential backoff between retries |
reconnect_interval |
30s | Interval between primary provider reconnection attempts (for subscription) |
subscription_buffer_capacity |
128 | Buffer size for subscription streams |
Subscriptions
RobustSubscription wraps Alloy's block subscriptions with automatic failover and reconnection:
let robust = new
.fallback
.subscription_timeout
.reconnect_interval
.build
.await?;
let subscription = robust.subscribe_blocks.await?;
let mut stream = subscription.into_stream;
while let Some = stream.next.await
Subscription behaviour:
- If no block arrives within
subscription_timeout, the provider automatically fails over to fallbacks. - While on a fallback, the subscription periodically attempts to reconnect to the primary provider (every
reconnect_interval). - When a fallback fails, the primary is tried first before moving to the next fallback.
- The
Laggederror indicates the consumer is not keeping pace with incoming blocks.
Provider Conversion
The library provides two conversion traits for flexible provider handling:
IntoRootProvider
Converts various types into an Alloy RootProvider. Implementations are provided for:
RobustProviderRootProvider&str(connection URL)UrlFillProviderCacheProviderDynProviderCallBatchProvider
IntoRobustProvider
Converts any IntoRootProvider type directly into a RobustProvider with default settings:
use IntoRobustProvider;
// Convert a URL directly to a RobustProvider
let robust: = "ws://localhost:8545".into.await?;
// Or convert an existing provider
let provider = new.connect.await?;
let robust: = provider.into.await?;
Testing
Run the test suite:
The tests use local Anvil instances to verify retry logic, failover behaviour, and subscription resilience.
RPC Endpoint Coverage
⚠️ Work In Progress ⚠️
This library is under active development and many RPC endpoints have not been implemented yet. If you encounter a missing endpoint, see the Extensibility section below for how to make raw RPC calls.
Extensibility
The library exposes try_operation_with_failover, allowing you to wrap any RPC call with the full retry and failover logic, even for endpoints that haven't been explicitly implemented:
use Provider;
// Use try_operation_with_failover to call any RPC method with full resilience
let block = robust
.try_operation_with_failover
.await?;
This gives you the same automatic retries, timeouts, and failover behaviour for any RPC method supported by your node.