Struct DefaultRetryPolicy

Source
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 milliseconds
  • compute_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

Source§

fn clone(&self) -> DefaultRetryPolicy

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 Debug for DefaultRetryPolicy

Source§

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

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

impl Default for DefaultRetryPolicy

Source§

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

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for DefaultRetryPolicy

Source§

fn eq(&self, other: &DefaultRetryPolicy) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl RetryPolicy for DefaultRetryPolicy

Source§

fn should_retry(&self, err: &TransportError) -> bool

Whether to retry the request based on the given error
Source§

fn backoff_hint(&self, _error: &TransportError) -> Option<Duration>

Providers may include the backoff in the error response directly
Source§

impl Serialize for DefaultRetryPolicy

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Validate for DefaultRetryPolicy

Source§

fn validate(&self) -> Result<(), ValidationErrors>

Source§

impl<'v_a> ValidateArgs<'v_a> for DefaultRetryPolicy

Source§

type Args = ()

Source§

fn validate_with_args(&self, args: Self::Args) -> Result<(), ValidationErrors>

Source§

impl StructuralPartialEq for DefaultRetryPolicy

Auto Trait Implementations§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

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
§

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, 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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
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
§

impl<'de, T> BorrowedRpcObject<'de> for T
where T: RpcBorrow<'de> + RpcSend,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<'de, T> RpcBorrow<'de> for T
where T: Deserialize<'de> + Debug + Send + Sync + Unpin,

§

impl<T> RpcObject for T
where T: RpcSend + RpcRecv,

§

impl<T> RpcRecv for T
where T: DeserializeOwned + Debug + Send + Sync + Unpin + 'static,

§

impl<T> RpcSend for T
where T: Serialize + Clone + Debug + Send + Sync + Unpin,