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>Expand description
Generic RPC call retry function that handles retrying operations with exponential backoff and provider failover.
This function will:
- Get a provider using the provider_initializer
- Try the operation up to provider_max_retries times with that provider (retrying only on retriable errors)
- If all retries fail or a non-retriable error occurs, mark the provider as failed and get a new provider
- Continue up to provider_max_failovers times (capped by total available providers)
§Type Parameters
P- The provider typeT- The result type of the operationE- The error type that implementsFrom<String>F- The function type that takes a provider and returns a futureFut- The future type returned by the operationI- The provider initializer function type
§Arguments
selector- RPC selector for managing and selecting providersoperation_name- Name of the operation for loggingis_retriable_error- Function that determines if an error is retriableshould_mark_provider_failed- Function that determines if an error should mark the provider as failedprovider_initializer- Function that initializes a provider from a URLoperation- A future-returning closure that makes the RPC callconfig- Optional configuration parameters for retry behavior
§Returns
- The result of the operation if successful, or an error