Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
use typed builder
Browse files Browse the repository at this point in the history
  • Loading branch information
salman01zp committed Sep 26, 2023
1 parent 02186c7 commit 7b604f6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ arbitrary = { git = "https://github.com/michaelsproul/arbitrary", rev="a572fd874
ethereum-types = { version = "0.14.1", default-features = false }
funty = "2.0.0"
anyhow = "1.0"
typed-builder = "0.16.0"
log = { version = "0.4", default-features = false }
serde_json = { version = "1.0.74", default-features = false }
serde = { version = "1.0", features = ["derive"], default-features = false }
Expand Down
12 changes: 10 additions & 2 deletions crates/eth-rpc-client/src/beacon_rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,22 @@ impl BeaconRPCClient {
.build()
.expect("Error on building non-blocking client for regular rpc requests.");

let retry_client = WebbRetryClient::new(client, u32::MAX, 3000);
let retry_client = WebbRetryClient::builder()
.inner(client)
.timeout_retries(u32::MAX)
.initial_backoff(3000_u64)
.build();

let state_client = reqwest::Client::builder()
.timeout(Duration::from_secs(timeout_state_seconds))
.build()
.expect("Error on building non-blocking client for regular rpc requests.");

let retry_state_client = WebbRetryClient::new(state_client, u32::MAX, 3000);
let retry_state_client = WebbRetryClient::builder()
.inner(state_client)
.timeout_retries(u32::MAX)
.initial_backoff(3000_u64)
.build();

Self {
endpoint_url: endpoint_url.to_string(),
Expand Down
3 changes: 2 additions & 1 deletion crates/lc-relay-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ anyhow = { workspace = true }
webb = { workspace = true}
tracing = { workspace = true }
backoff = { workspace = true }
tokio = { workspace = true }
tokio = { workspace = true }
typed-builder = { workspace = true }
39 changes: 21 additions & 18 deletions crates/lc-relay-types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
use reqwest::Client;
use std::time::Duration;

#[derive(Debug)]
#[derive(Debug, Clone, typed_builder::TypedBuilder)]
pub struct WebbRetryClient {
/// The inner client
#[builder(setter(into))]
inner: Client,
/// How many connection `TimedOut` should be retried.
#[builder(setter(into))]
timeout_retries: u32,
/// How long to wait initially
#[builder(setter(into))]
initial_backoff: u64,
}

impl WebbRetryClient {
pub fn new(inner: Client, timeout_retries: u32, initial_backoff: u64) -> Self {
Self { inner, timeout_retries, initial_backoff }
}
/// Sets the number of retries after a connection times out
///
/// **Note:** this will only be used for `request::Error::TimedOut`
pub fn timeout_retries(mut self, timeout_retries: u32) -> Self {
self.timeout_retries = timeout_retries;
self
}
// impl WebbRetryClient {
// pub fn new(inner: Client, timeout_retries: u32, initial_backoff: u64) -> Self {
// Self { inner, timeout_retries, initial_backoff }
// }
// /// Sets the number of retries after a connection times out
// ///
// /// **Note:** this will only be used for `request::Error::TimedOut`
// pub fn timeout_retries(mut self, timeout_retries: u32) -> Self {
// self.timeout_retries = timeout_retries;
// self
// }

/// Sets the duration to wait initially before retrying
pub fn initial_backoff(mut self, initial_backoff: u64) -> Self {
self.initial_backoff = initial_backoff;
self
}
}
// /// Sets the duration to wait initially before retrying
// pub fn initial_backoff(mut self, initial_backoff: u64) -> Self {
// self.initial_backoff = initial_backoff;
// self
// }
// }

impl WebbRetryClient {
pub async fn get(&self, url: &str) -> anyhow::Result<String> {
Expand Down

0 comments on commit 7b604f6

Please sign in to comment.