Skip to main content

RobustProviderBuilder

Struct RobustProviderBuilder 

Source
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>

Source

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.

Source

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.

Source

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.

Source

pub fn call_timeout(self, timeout: Duration) -> Self

Set the maximum timeout for RPC operations.

Source

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.

Source

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.

Source

pub fn max_retries(self, max_retries: usize) -> Self

Set the maximum number of retry attempts.

Source

pub fn min_delay(self, min_delay: Duration) -> Self

Set the base delay for exponential backoff retries.

Source

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.

Source

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?;
Source

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_interval delay
  • 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_interval is 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?;
Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more