From 4c6a74f3831beedf65b5b573b8a0645f680fb099 Mon Sep 17 00:00:00 2001 From: Wolfgang Welz Date: Thu, 12 Dec 2024 19:52:11 +0100 Subject: [PATCH] chore: Add backoff/retry for HTTP Provider cache collect (#129) * Added backoff/retry for HTTP Provider cache collect (#125) * less conservative config --------- Co-authored-by: Parker Thompson Co-authored-by: Rami <2418646+hashcashier@users.noreply.github.com> --- crates/preflight/src/provider/rpc_provider.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/preflight/src/provider/rpc_provider.rs b/crates/preflight/src/provider/rpc_provider.rs index f10cf295..9c91d694 100644 --- a/crates/preflight/src/provider/rpc_provider.rs +++ b/crates/preflight/src/provider/rpc_provider.rs @@ -15,20 +15,31 @@ use crate::provider::query::{AccountRangeQueryResponse, StorageRangeQueryResponse}; use crate::provider::*; use alloy::network::{BlockResponse, HeaderResponse, Network}; -use alloy::providers::{Provider as AlloyProvider, ReqwestProvider}; +use alloy::providers::{Provider as AlloyProvider, ProviderBuilder, RootProvider}; +use alloy::rpc::client::RpcClient; +use alloy::transports::{ + http::{Client, Http}, + layers::{RetryBackoffLayer, RetryBackoffService}, +}; use anyhow::anyhow; use log::{debug, error}; use std::future::IntoFuture; #[derive(Clone, Debug)] pub struct RpcProvider { - http_client: ReqwestProvider, + http_client: RootProvider>, N>, tokio_handle: tokio::runtime::Handle, } impl RpcProvider { pub fn new(rpc_url: String) -> anyhow::Result { - let http_client = ReqwestProvider::new_http(rpc_url.parse()?); + let retry_layer = RetryBackoffLayer::new(10, 100, 330); + + let client = RpcClient::builder() + .layer(retry_layer) + .http(rpc_url.parse()?); + let http_client = ProviderBuilder::new().network().on_client(client); + let tokio_handle = tokio::runtime::Handle::current(); Ok(RpcProvider {