pub struct DefaultRetryPolicy {
pub min_retries: Option<u32>,
pub initial_backoff: Duration,
pub backoff_coefficient: f64,
pub max_backoff: Duration,
pub backoff_on_transport_errors: bool,
pub retryable_json_rpc_errors: Vec<i64>,
pub retryable_http_errors: Vec<StatusCode>,
pub max_retry_queue_size: u32,
}
Expand description
Defines a default retry policy suitable for RpcClient
.
This is a reimplementation of the legacy “retry policy suitable for JsonRpcProviderClient
”
This retry policy distinguishes between 4 types of RPC request failures:
- JSON RPC error (based on error code)
- HTTP error (based on HTTP status)
- Transport error (e.g. connection timeout)
- Serde error (some of these are treated as JSON RPC error above, if an error code can be obtained).
The standard RetryBackoffLayer
defines the following properties:
max_rate_limit_retries
: (u32) The maximum number of retries for rate limit errors. Different from the legacy implementation, there is always an upper limit.initial_backoff
: (u64) The initial backoff in millisecondscompute_units_per_second
: (u64) The number of compute units per second for this service
The policy will make up to max_retries
once a JSON RPC request fails.
The minimum number of retries min_retries
can be also specified and applies to any type of error regardless.
Each retry k > 0
will be separated by a delay of initial_backoff * (1 + backoff_coefficient)^(k - 1)
,
namely all the JSON RPC error codes specified in retryable_json_rpc_errors
and all the HTTP errors
specified in retryable_http_errors
.
The total wait time will be (initial_backoff/backoff_coefficient) * ((1 + backoff_coefficient)^max_retries - 1)
.
or max_backoff
, whatever is lower.
Transport and connection errors (such as connection timeouts) are retried without backoff
at a constant delay of initial_backoff
if backoff_on_transport_errors
is not set.
No more additional retries are allowed on new requests, if the maximum number of concurrent
requests being retried has reached max_retry_queue_size
.
Fields§
§min_retries: Option<u32>
Minimum number of retries of any error, regardless the error code.
Default is 0.
initial_backoff: Duration
Initial wait before retries.
NOTE: Transport and connection errors (such as connection timeouts) are retried at
a constant rate (no backoff) with this delay if backoff_on_transport_errors
is not set.
Default is 1 second.
backoff_coefficient: f64
Backoff coefficient by which will be each retry multiplied.
Must be non-negative. If set to 0
, no backoff will be applied and the
requests will be retried at a constant rate.
Default is 0.3
max_backoff: Duration
Maximum backoff value.
Once reached, the requests will be retried at a constant rate with this timeout.
Default is 30 seconds.
backoff_on_transport_errors: bool
Indicates whether to also apply backoff to transport and connection errors (such as connection timeouts).
Default is false.
retryable_json_rpc_errors: Vec<i64>
List of JSON RPC errors that should be retried with backoff
Default is [429, -32005, -32016]
retryable_http_errors: Vec<StatusCode>
List of HTTP errors that should be retried with backoff.
Default is [429, 504, 503]
max_retry_queue_size: u32
Maximum number of different requests that are being retried at the same time.
If any additional request fails after this number is attained, it won’t be retried.
Default is 100
Trait Implementations§
Source§impl Clone for DefaultRetryPolicy
impl Clone for DefaultRetryPolicy
Source§fn clone(&self) -> DefaultRetryPolicy
fn clone(&self) -> DefaultRetryPolicy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for DefaultRetryPolicy
impl Debug for DefaultRetryPolicy
Source§impl Default for DefaultRetryPolicy
impl Default for DefaultRetryPolicy
Source§fn default() -> Self
fn default() -> Self
Return DefaultRetryPolicy { min_retries: Some(0), initial_backoff: Duration::from_secs(1), backoff_coefficient: 0.3, max_backoff: Duration::from_secs(30), backoff_on_transport_errors: Default::default(), retryable_json_rpc_errors: vec! [- 32005, - 32016, 429], retryable_http_errors: vec! [http :: StatusCode :: TOO_MANY_REQUESTS, http :: StatusCode :: GATEWAY_TIMEOUT, http :: StatusCode :: SERVICE_UNAVAILABLE], max_retry_queue_size: 100 }
Source§impl<'de> Deserialize<'de> for DefaultRetryPolicy
impl<'de> Deserialize<'de> for DefaultRetryPolicy
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for DefaultRetryPolicy
impl PartialEq for DefaultRetryPolicy
Source§impl RetryPolicy for DefaultRetryPolicy
impl RetryPolicy for DefaultRetryPolicy
Source§fn should_retry(&self, err: &TransportError) -> bool
fn should_retry(&self, err: &TransportError) -> bool
error
Source§fn backoff_hint(&self, _error: &TransportError) -> Option<Duration>
fn backoff_hint(&self, _error: &TransportError) -> Option<Duration>
backoff
in the error response directlySource§impl Serialize for DefaultRetryPolicy
impl Serialize for DefaultRetryPolicy
Source§impl Validate for DefaultRetryPolicy
impl Validate for DefaultRetryPolicy
Source§impl<'v_a> ValidateArgs<'v_a> for DefaultRetryPolicy
impl<'v_a> ValidateArgs<'v_a> for DefaultRetryPolicy
impl StructuralPartialEq for DefaultRetryPolicy
Auto Trait Implementations§
impl Freeze for DefaultRetryPolicy
impl RefUnwindSafe for DefaultRetryPolicy
impl Send for DefaultRetryPolicy
impl Sync for DefaultRetryPolicy
impl Unpin for DefaultRetryPolicy
impl UnwindSafe for DefaultRetryPolicy
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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