Function retry_rpc_call

Source
pub async fn retry_rpc_call<P, T, E, F, Fut, I>(
    selector: &RpcSelector,
    operation_name: &str,
    is_retriable_error: impl Fn(&E) -> bool,
    should_mark_provider_failed: impl Fn(&E) -> bool,
    provider_initializer: I,
    operation: F,
    config: Option<RetryConfig>,
) -> Result<T, E>
where P: Clone, E: Display + From<String>, F: Fn(P) -> Fut, Fut: Future<Output = Result<T, E>>, I: Fn(&str) -> Result<P, E>,
Expand description

Generic RPC call retry function that handles retrying operations with exponential backoff and provider failover.

This function will:

  1. Get a provider using the provider_initializer
  2. Try the operation up to provider_max_retries times with that provider (retrying only on retriable errors)
  3. If all retries fail or a non-retriable error occurs, mark the provider as failed and get a new provider
  4. Continue up to provider_max_failovers times (capped by total available providers)

§Type Parameters

  • P - The provider type
  • T - The result type of the operation
  • E - The error type that implements From
  • F - The function type that takes a provider and returns a future
  • Fut - The future type returned by the operation
  • I - The provider initializer function type

§Arguments

  • selector - RPC selector for managing and selecting providers
  • operation_name - Name of the operation for logging
  • is_retriable_error - Function that determines if an error is retriable
  • should_mark_provider_failed - Function that determines if an error should mark the provider as failed
  • provider_initializer - Function that initializes a provider from a URL
  • operation - A future-returning closure that makes the RPC call
  • config - Optional configuration parameters for retry behavior

§Returns

  • The result of the operation if successful, or an error