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>
impl<N: Network> RobustProvider<N>
Sourcepub fn primary(&self) -> &RootProvider<N>
pub fn primary(&self) -> &RootProvider<N>
Get a reference to the primary provider
Sourcepub async fn get_block_by_number(
&self,
number: BlockNumberOrTag,
) -> Result<N::BlockResponse, Error>
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. exceedscall_timeout).Error::BlockNotFound- if the block with the specified hash was not found on-chain.
Sourcepub async fn get_block(&self, id: BlockId) -> Result<N::BlockResponse, Error>
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. exceedscall_timeout).Error::BlockNotFound- if the block with the specified hash was not found on-chain.
Sourcepub async fn get_block_number(&self) -> Result<BlockNumber, Error>
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. exceedscall_timeout).
Sourcepub async fn get_block_number_by_id(
&self,
block_id: BlockId,
) -> Result<BlockNumber, Error>
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. exceedscall_timeout).Error::BlockNotFound- if the block with the specified hash was not found on-chain.
Sourcepub async fn get_latest_confirmed(
&self,
confirmations: u64,
) -> Result<u64, Error>
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 belatest_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. exceedscall_timeout).
Sourcepub async fn get_block_by_hash(
&self,
hash: BlockHash,
) -> Result<N::BlockResponse, Error>
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. exceedscall_timeout).Error::BlockNotFound- if the block with the specified hash was not found on-chain.
Sourcepub async fn get_logs(&self, filter: &Filter) -> Result<Vec<Log>, Error>
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. exceedscall_timeout).
Sourcepub async fn subscribe_blocks(&self) -> Result<RobustSubscription<N>, Error>
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. exceedscall_timeout).
Sourcepub async fn try_operation_with_failover<T: Debug, F, Fut>(
&self,
operation: F,
require_pubsub: bool,
) -> Result<T, CoreError>
pub async fn try_operation_with_failover<T: Debug, F, Fut>( &self, operation: F, require_pubsub: bool, ) -> Result<T, CoreError>
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. exceedscall_timeout).
Trait Implementations§
Source§impl<N: Clone + Network> Clone for RobustProvider<N>
impl<N: Clone + Network> Clone for RobustProvider<N>
Source§fn clone(&self) -> RobustProvider<N>
fn clone(&self) -> RobustProvider<N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<N: Network> IntoRootProvider<N> for RobustProvider<N>
impl<N: Network> IntoRootProvider<N> for RobustProvider<N>
Source§async fn into_root_provider(self) -> Result<RootProvider<N>, Error>
async fn into_root_provider(self) -> Result<RootProvider<N>, Error>
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> 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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