pub struct RetryClient<T>where
    T: JsonRpcClient,
    T::Error: Sync + Send + 'static,
{ /* private fields */ }
Expand description

RetryClient presents as a wrapper around JsonRpcClient that will retry requests based with an exponential backoff and filtering based on RetryPolicy.

The RetryPolicy, mainly for rate-limiting errors, can be adjusted for specific applications, endpoints. In addition to the RetryPolicy errors due to connectivity issues, like timed out connections or responses in range 5xx can be retried separately.

Example

use ethers_providers::{Http, RetryClient, RetryClientBuilder, HttpRateLimitRetryPolicy};
use std::time::Duration;
use url::Url;

let http = Http::new(Url::parse("http://localhost:8545").unwrap());
let client = RetryClientBuilder::default()
    .rate_limit_retries(10)
    .timeout_retries(3)
    .initial_backoff(Duration::from_millis(500))
    .build(http, Box::new(HttpRateLimitRetryPolicy::default()));

Implementations§

Creates a new RetryClient that wraps a client and adds retry and backoff support

Example
 
use ethers_providers::{Http, RetryClient, HttpRateLimitRetryPolicy};
use std::time::Duration;
use url::Url;

let http = Http::new(Url::parse("http://localhost:8545").unwrap());
let backoff_timeout = 3000; // in ms
let max_retries = 10;
let client = RetryClient::new(http, Box::new(HttpRateLimitRetryPolicy::default()), max_retries, backoff_timeout);

Sets the free compute units per second limit.

This is the maximum number of weighted request that can be handled per second by the endpoint before rate limit kicks in.

This is used to guesstimate how long to wait until to retry again

Trait Implementations§

Formats the value using the given formatter. Read more
A JSON-RPC Error
Sends a request with the provided JSON-RPC and parameters serialized as JSON

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Calls U::from(self).

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

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more