RobustProvider

Struct RobustProvider 

Source
pub struct RobustProvider<N: Network = Ethereum> { /* private fields */ }
Expand description

Provider wrapper with built-in retry and timeout mechanisms.

This wrapper around Alloy providers automatically handles retries, timeouts, and error logging for RPC calls.

Implementations§

Source§

impl<N: Network> RobustProvider<N>

Source

pub fn primary(&self) -> &RootProvider<N>

Get a reference to the primary provider

Source

pub async fn get_block_by_number( &self, number: BlockNumberOrTag, ) -> Result<N::BlockResponse, Error>

Fetch a block by BlockNumberOrTag with retry and timeout.

This is a wrapper function for Provider::get_block_by_number.

§Errors
  • Error::RpcError - if no fallback providers succeeded; contains the last error returned by the last provider attempted on the last retry.
  • Error::Timeout - if the overall operation timeout elapses (i.e. exceeds call_timeout).
  • Error::BlockNotFound - if the block with the specified number/tag is not available. This is verified on Anvil, Reth, and Geth; other clients may surface this condition as Error::RpcError.
Source

pub async fn get_block(&self, id: BlockId) -> Result<N::BlockResponse, Error>

Fetch a block number by BlockId with retry and timeout.

This is a wrapper function for Provider::get_block.

§Errors
  • Error::RpcError - if no fallback providers succeeded; contains the last error returned by the last provider attempted on the last retry.
  • Error::Timeout - if the overall operation timeout elapses (i.e. exceeds call_timeout).
  • Error::BlockNotFound - if the block for the specified identifier is not available. This is verified on Anvil, Reth, and Geth; other clients may surface this condition as Error::RpcError.
Source

pub async fn get_block_number(&self) -> Result<BlockNumber, Error>

Fetch the latest block number with retry and timeout.

This is a wrapper function for Provider::get_block_number.

§Errors
  • Error::RpcError - if no fallback providers succeeded; contains the last error returned by the last provider attempted on the last retry.
  • Error::Timeout - if the overall operation timeout elapses (i.e. exceeds call_timeout).
Source

pub async fn get_block_number_by_id( &self, block_id: BlockId, ) -> Result<BlockNumber, Error>

Get the block number for a given block identifier.

This is a wrapper function for Provider::get_block_number_by_id.

§Arguments
  • block_id - The block identifier to fetch the block number for.
§Errors
  • Error::RpcError - if no fallback providers succeeded; contains the last error returned by the last provider attempted on the last retry.
  • Error::Timeout - if the overall operation timeout elapses (i.e. exceeds call_timeout).
  • Error::BlockNotFound - if the block for the specified identifier is not available. This is verified on Anvil, Reth, and Geth; other clients may surface this condition as Error::RpcError.
Source

pub async fn get_latest_confirmed( &self, confirmations: u64, ) -> Result<u64, Error>

Fetch the latest confirmed block number with retry and timeout.

This method fetches the latest block number and subtracts the specified number of confirmations to get a “confirmed” block number.

§Arguments
  • confirmations - The number of block confirmations to wait for. The returned block number will be latest_block - confirmations.
§Errors
  • Error::RpcError - if no fallback providers succeeded; contains the last error returned by the last provider attempted on the last retry.
  • Error::Timeout - if the overall operation timeout elapses (i.e. exceeds call_timeout).
Source

pub async fn get_block_by_hash( &self, hash: BlockHash, ) -> Result<N::BlockResponse, Error>

Fetch a block by BlockHash with retry and timeout.

This is a wrapper function for Provider::get_block_by_hash.

§Errors
  • Error::RpcError - if no fallback providers succeeded; contains the last error returned by the last provider attempted on the last retry.
  • Error::Timeout - if the overall operation timeout elapses (i.e. exceeds call_timeout).
  • Error::BlockNotFound - if the block with the specified hash is not available. This is verified on Anvil, Reth, and Geth; other clients may surface this condition as Error::RpcError.
Source

pub async fn get_logs(&self, filter: &Filter) -> Result<Vec<Log>, Error>

Fetch logs for the given Filter with retry and timeout.

This is a wrapper function for Provider::get_logs.

§Errors
  • Error::RpcError - if no fallback providers succeeded; contains the last error returned by the last provider attempted on the last retry.
  • Error::Timeout - if the overall operation timeout elapses (i.e. exceeds call_timeout).
Source

pub async fn subscribe_blocks(&self) -> Result<RobustSubscription<N>, Error>

Subscribe to new block headers with automatic failover and reconnection.

Returns a RobustSubscription that automatically:

  • Handles connection errors by switching to fallback providers
  • Detects and recovers from lagged subscriptions
  • Periodically attempts to reconnect to the primary provider

This is a wrapper function for Provider::subscribe_blocks.

§Errors
  • Error::RpcError - if no fallback providers succeeded; contains the last error returned by the last provider attempted on the last retry.
  • Error::Timeout - if the overall operation timeout elapses (i.e. exceeds call_timeout).
Source

pub async fn try_operation_with_failover<T: Debug, F, Fut>( &self, operation: F, require_pubsub: bool, ) -> Result<T, CoreError>
where F: Fn(RootProvider<N>) -> Fut, Fut: Future<Output = Result<T, RpcError<TransportErrorKind>>>,

Execute operation with exponential backoff and a total timeout.

Wraps the retry logic with tokio::time::timeout so the entire operation (including time spent inside the RPC call) cannot exceed call_timeout.

If the timeout is exceeded and fallback providers are available, it will attempt to use each fallback provider in sequence.

If require_pubsub is true, providers that don’t support pubsub will be skipped.

§Errors
  • CoreError::RpcError - if no fallback providers succeeded; contains the last error returned by the last provider attempted on the last retry.
  • CoreError::Timeout - if the overall operation timeout elapses (i.e. exceeds call_timeout).

Trait Implementations§

Source§

impl<N: Clone + Network> Clone for RobustProvider<N>

Source§

fn clone(&self) -> RobustProvider<N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<N: Debug + Network> Debug for RobustProvider<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<N: Network> IntoRootProvider<N> for RobustProvider<N>

Source§

async fn into_root_provider(self) -> Result<RootProvider<N>, Error>

Convert self into a RootProvider. Read more

Auto Trait Implementations§

§

impl<N> Freeze for RobustProvider<N>

§

impl<N = Ethereum> !RefUnwindSafe for RobustProvider<N>

§

impl<N> Send for RobustProvider<N>

§

impl<N> Sync for RobustProvider<N>

§

impl<N> Unpin for RobustProvider<N>

§

impl<N = Ethereum> !UnwindSafe for RobustProvider<N>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<N, P> IntoRobustProvider<N> for P
where N: Network, P: IntoRootProvider<N> + Send + 'static,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> TryClone for T
where T: Clone,

Source§

fn try_clone(&self) -> Result<T, Error>

Clones self, possibly returning an error.
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