pub struct RobustProviderBuilder<N: Network, P: IntoRootProvider<N>> { /* private fields */ }Expand description
Builder for constructing a RobustProvider.
Use this to configure timeouts, retry/backoff, and one or more fallback providers.
Implementations§
Source§impl<N: Network, P: IntoRootProvider<N>> RobustProviderBuilder<N, P>
impl<N: Network, P: IntoRootProvider<N>> RobustProviderBuilder<N, P>
Sourcepub fn new(provider: P) -> Self
pub fn new(provider: P) -> Self
Create a new RobustProvider with default settings.
The provided provider is treated as the primary provider.
Any type implementing IntoRootProvider can be used.
Sourcepub fn fragile(provider: P) -> Self
pub fn fragile(provider: P) -> Self
Create a new RobustProvider with no retry attempts and only timeout set.
The provided provider is treated as the primary provider.
Sourcepub fn fallback<F: IntoRootProvider<N> + Send + 'static>(
self,
provider: F,
) -> Self
pub fn fallback<F: IntoRootProvider<N> + Send + 'static>( self, provider: F, ) -> Self
Add a fallback provider to the list.
Fallback providers are used when the primary provider times out or fails.
Sourcepub fn call_timeout(self, timeout: Duration) -> Self
pub fn call_timeout(self, timeout: Duration) -> Self
Set the maximum timeout for RPC operations.
Sourcepub fn subscription_timeout(self, timeout: Duration) -> Self
pub fn subscription_timeout(self, timeout: Duration) -> Self
Set the timeout for subscription operations.
This should be set higher than call_timeout to accommodate chains
with slow block times. Default is DEFAULT_SUBSCRIPTION_TIMEOUT.
Sourcepub fn subscription_buffer_capacity(self, buffer_capacity: usize) -> Self
pub fn subscription_buffer_capacity(self, buffer_capacity: usize) -> Self
Set the subscription stream buffer capacity.
Controls the buffer capacity for subscription streams. If new blocks arrive while the stream buffer is full, a lagged error will be emitted, indicating that stream items were dropped due to the consumer not keeping pace with the stream.
Internally calls alloy::providers::GetSubscription::channel_size.
Default is DEFAULT_SUBSCRIPTION_BUFFER_CAPACITY.
Sourcepub fn max_retries(self, max_retries: usize) -> Self
pub fn max_retries(self, max_retries: usize) -> Self
Set the maximum number of retry attempts.
Sourcepub fn min_delay(self, min_delay: Duration) -> Self
pub fn min_delay(self, min_delay: Duration) -> Self
Set the base delay for exponential backoff retries.
Sourcepub fn reconnect_interval(self, reconnect_interval: Duration) -> Self
pub fn reconnect_interval(self, reconnect_interval: Duration) -> Self
Set the interval for attempting to reconnect to the primary provider.
After a failover to a fallback provider, the subscription will periodically
attempt to reconnect to the primary provider at this interval.
Default is DEFAULT_RECONNECT_INTERVAL.
Sourcepub fn poll_interval(self, interval: Duration) -> Self
pub fn poll_interval(self, interval: Duration) -> Self
Set the polling interval for HTTP-based subscriptions.
This controls how frequently HTTP providers poll for new blocks
when used as subscription sources. Only relevant when
allow_http_subscriptions is enabled.
Default is DEFAULT_POLL_INTERVAL.
Adjust based on your target chain’s block time.
§Feature Flag
This method requires the http-subscription feature.
§Example
let robust = RobustProviderBuilder::new(http_provider)
.allow_http_subscriptions(true)
.poll_interval(Duration::from_secs(6)) // For faster chains
.build()
.await?;Sourcepub fn allow_http_subscriptions(self, allow: bool) -> Self
pub fn allow_http_subscriptions(self, allow: bool) -> Self
Enable HTTP providers for subscriptions via polling.
When enabled, HTTP providers can participate in subscriptions
by polling for new blocks at the configured poll_interval.
§Trade-offs
- Latency: New blocks detected with up to
poll_intervaldelay - RPC Load: Generates one RPC call per
poll_interval - Intermediate Blocks: Depending on the node/provider semantics, you may not observe
every intermediate block when
poll_intervalis larger than the chain’s block time (e.g. if only the latest head is exposed).
§Feature Flag
This method requires the http-subscription feature.
§Example
let robust = RobustProviderBuilder::new(http_provider)
.allow_http_subscriptions(true)
.build()
.await?;Sourcepub async fn build(self) -> Result<RobustProvider<N>, Error>
pub async fn build(self) -> Result<RobustProvider<N>, Error>
Build the RobustProvider.
Final builder method: consumes the builder and returns the built RobustProvider.
§Errors
Returns an error if any of the providers fail to connect.
Auto Trait Implementations§
impl<N, P> Freeze for RobustProviderBuilder<N, P>where
P: Freeze,
impl<N, P> !RefUnwindSafe for RobustProviderBuilder<N, P>
impl<N, P> Send for RobustProviderBuilder<N, P>where
P: Send,
impl<N, P> !Sync for RobustProviderBuilder<N, P>
impl<N, P> Unpin for RobustProviderBuilder<N, P>where
P: Unpin,
impl<N, P> UnsafeUnpin for RobustProviderBuilder<N, P>where
P: UnsafeUnpin,
impl<N, P> !UnwindSafe for RobustProviderBuilder<N, P>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more