Skip to content

Commit

Permalink
refactor(common): use alloy retry layer (#8368)
Browse files Browse the repository at this point in the history
* use alloy retry layer in RetryProvider

* nits

* rm built-in retry layer

* rm `timeout_retry`

* bump alloy

---------

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
yash-atreya and mattsse authored Jul 9, 2024
1 parent 7c4482f commit b1b8151
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 396 deletions.
44 changes: 22 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -172,28 +172,28 @@ revm-inspectors = { version = "0.3", features = ["serde"] }
ethers-contract-abigen = { version = "2.0.14", default-features = false }

## alloy
alloy-consensus = { version = "0.1.2", default-features = false }
alloy-contract = { version = "0.1.2", default-features = false }
alloy-eips = { version = "0.1.2", default-features = false }
alloy-genesis = { version = "0.1.2", default-features = false }
alloy-json-rpc = { version = "0.1.2", default-features = false }
alloy-network = { version = "0.1.2", default-features = false }
alloy-node-bindings = { version = "0.1.2", default-features = false }
alloy-provider = { version = "0.1.2", default-features = false }
alloy-pubsub = { version = "0.1.2", default-features = false }
alloy-rpc-client = { version = "0.1.2", default-features = false }
alloy-rpc-types = { version = "0.1.2", default-features = false }
alloy-serde = { version = "0.1.2", default-features = false }
alloy-signer = { version = "0.1.2", default-features = false }
alloy-signer-aws = { version = "0.1.2", default-features = false }
alloy-signer-gcp = { version = "0.1.2", default-features = false }
alloy-signer-ledger = { version = "0.1.2", default-features = false }
alloy-signer-local = { version = "0.1.2", default-features = false }
alloy-signer-trezor = { version = "0.1.2", default-features = false }
alloy-transport = { version = "0.1.2", default-features = false }
alloy-transport-http = { version = "0.1.2", default-features = false }
alloy-transport-ipc = { version = "0.1.2", default-features = false }
alloy-transport-ws = { version = "0.1.2", default-features = false }
alloy-consensus = { version = "0.1.4", default-features = false }
alloy-contract = { version = "0.1.4", default-features = false }
alloy-eips = { version = "0.1.4", default-features = false }
alloy-genesis = { version = "0.1.4", default-features = false }
alloy-json-rpc = { version = "0.1.4", default-features = false }
alloy-network = { version = "0.1.4", default-features = false }
alloy-node-bindings = { version = "0.1.4", default-features = false }
alloy-provider = { version = "0.1.4", default-features = false }
alloy-pubsub = { version = "0.1.4", default-features = false }
alloy-rpc-client = { version = "0.1.4", default-features = false }
alloy-rpc-types = { version = "0.1.4", default-features = false }
alloy-serde = { version = "0.1.4", default-features = false }
alloy-signer = { version = "0.1.4", default-features = false }
alloy-signer-aws = { version = "0.1.4", default-features = false }
alloy-signer-gcp = { version = "0.1.4", default-features = false }
alloy-signer-ledger = { version = "0.1.4", default-features = false }
alloy-signer-local = { version = "0.1.4", default-features = false }
alloy-signer-trezor = { version = "0.1.4", default-features = false }
alloy-transport = { version = "0.1.4", default-features = false }
alloy-transport-http = { version = "0.1.4", default-features = false }
alloy-transport-ipc = { version = "0.1.4", default-features = false }
alloy-transport-ws = { version = "0.1.4", default-features = false }

alloy-dyn-abi = "0.7.3"
alloy-json-abi = "0.7.3"
Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,10 +1020,10 @@ impl NodeConfig {
let provider = Arc::new(
ProviderBuilder::new(&eth_rpc_url)
.timeout(self.fork_request_timeout)
.timeout_retry(self.fork_request_retries)
// .timeout_retry(self.fork_request_retries)
.initial_backoff(self.fork_retry_backoff.as_millis() as u64)
.compute_units_per_second(self.compute_units_per_second)
.max_retry(10)
.max_retry(self.fork_request_retries)
.initial_backoff(1000)
.headers(self.fork_headers.clone())
.build()
Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/src/eth/backend/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,8 @@ impl ClientForkConfig {
self.provider = Arc::new(
ProviderBuilder::new(url.as_str())
.timeout(self.timeout)
.timeout_retry(self.retries)
.max_retry(10)
// .timeout_retry(self.retries)
.max_retry(self.retries)
.initial_backoff(self.backoff.as_millis() as u64)
.compute_units_per_second(self.compute_units_per_second)
.build()
Expand Down
35 changes: 9 additions & 26 deletions crates/common/src/provider/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! Provider-related instantiation and usage utilities.
pub mod retry;
pub mod runtime_transport;
pub mod tower;

use crate::{
provider::runtime_transport::RuntimeTransportBuilder, ALCHEMY_FREE_TIER_CUPS, REQUEST_TIMEOUT,
Expand All @@ -13,7 +11,10 @@ use alloy_provider::{
Identity, ProviderBuilder as AlloyProviderBuilder, RootProvider,
};
use alloy_rpc_client::ClientBuilder;
use alloy_transport::utils::guess_local_url;
use alloy_transport::{
layers::{RetryBackoffLayer, RetryBackoffService},
utils::guess_local_url,
};
use eyre::{Result, WrapErr};
use foundry_config::NamedChain;
use reqwest::Url;
Expand All @@ -24,7 +25,6 @@ use std::{
str::FromStr,
time::Duration,
};
use tower::{RetryBackoffLayer, RetryBackoffService};
use url::ParseError;

/// Helper type alias for a retry provider
Expand Down Expand Up @@ -77,7 +77,6 @@ pub struct ProviderBuilder {
url: Result<Url>,
chain: NamedChain,
max_retry: u32,
timeout_retry: u32,
initial_backoff: u64,
timeout: Duration,
/// available CUPS
Expand Down Expand Up @@ -128,7 +127,6 @@ impl ProviderBuilder {
url,
chain: NamedChain::Mainnet,
max_retry: 8,
timeout_retry: 8,
initial_backoff: 800,
timeout: REQUEST_TIMEOUT,
// alchemy max cpus <https://docs.alchemy.com/reference/compute-units#what-are-cups-compute-units-per-second>
Expand Down Expand Up @@ -175,12 +173,6 @@ impl ProviderBuilder {
self
}

/// How often to retry a failed request due to connection issues
pub fn timeout_retry(mut self, timeout_retry: u32) -> Self {
self.timeout_retry = timeout_retry;
self
}

/// The starting backoff delay to use after the first failed request
pub fn initial_backoff(mut self, initial_backoff: u64) -> Self {
self.initial_backoff = initial_backoff;
Expand Down Expand Up @@ -239,7 +231,6 @@ impl ProviderBuilder {
url,
chain: _,
max_retry,
timeout_retry,
initial_backoff,
timeout,
compute_units_per_second,
Expand All @@ -249,12 +240,9 @@ impl ProviderBuilder {
} = self;
let url = url?;

let retry_layer = RetryBackoffLayer::new(
max_retry,
timeout_retry,
initial_backoff,
compute_units_per_second,
);
let retry_layer =
RetryBackoffLayer::new(max_retry, initial_backoff, compute_units_per_second);

let transport = RuntimeTransportBuilder::new(url)
.with_timeout(timeout)
.with_headers(headers)
Expand All @@ -274,7 +262,6 @@ impl ProviderBuilder {
url,
chain: _,
max_retry,
timeout_retry,
initial_backoff,
timeout,
compute_units_per_second,
Expand All @@ -284,12 +271,8 @@ impl ProviderBuilder {
} = self;
let url = url?;

let retry_layer = RetryBackoffLayer::new(
max_retry,
timeout_retry,
initial_backoff,
compute_units_per_second,
);
let retry_layer =
RetryBackoffLayer::new(max_retry, initial_backoff, compute_units_per_second);

let transport = RuntimeTransportBuilder::new(url)
.with_timeout(timeout)
Expand Down
152 changes: 0 additions & 152 deletions crates/common/src/provider/retry.rs

This file was deleted.

Loading

0 comments on commit b1b8151

Please sign in to comment.