Skip to content

Commit

Permalink
chore: Add backoff/retry for HTTP Provider cache collect (#129)
Browse files Browse the repository at this point in the history
* Added backoff/retry for HTTP Provider cache collect (#125)

* less conservative config

---------

Co-authored-by: Parker Thompson <[email protected]>
Co-authored-by: Rami <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2024
1 parent a0662cf commit 4c6a74f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions crates/preflight/src/provider/rpc_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<N: Network> {
http_client: ReqwestProvider<N>,
http_client: RootProvider<RetryBackoffService<Http<Client>>, N>,
tokio_handle: tokio::runtime::Handle,
}

impl<N: Network> RpcProvider<N> {
pub fn new(rpc_url: String) -> anyhow::Result<Self> {
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 {
Expand Down

0 comments on commit 4c6a74f

Please sign in to comment.