Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(common): doc fixes and unused fns removal #7291

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions crates/common/src/provider/alloy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,6 @@ impl ProviderBuilder {
self
}

/// Same as [`Self:build()`] but also retrieves the `chainId` in order to derive an appropriate
/// interval.
pub async fn connect(self) -> Result<RetryProvider> {
let provider = self.build()?;
// todo: port poll interval hint
/*if let Some(blocktime) = provider.get_chainid().await.ok().and_then(|id| {
}) {
provider = provider.interval(blocktime / 2);
}*/
Ok(provider)
}

/// Constructs the `RetryProvider` taking all configs into account.
pub fn build(self) -> Result<RetryProvider> {
let ProviderBuilder {
Expand Down
3 changes: 2 additions & 1 deletion crates/common/src/provider/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use alloy_json_rpc::ErrorPayload;
use alloy_transport::{TransportError, TransportErrorKind};
use serde::Deserialize;

/// [RetryPolicy] defines logic for which [JsonRpcClient::Error] instances should
/// [RetryPolicy] defines logic for which [TransportError] instances should
/// the client retry the request and try to recover from.
pub trait RetryPolicy: Send + Sync + std::fmt::Debug {
/// Whether to retry the request based on the given `error`
Expand Down Expand Up @@ -52,6 +52,7 @@ impl RetryPolicy for RateLimitRetryPolicy {
}
}

/// Provides a backoff hint if the error response contains it
fn backoff_hint(&self, error: &TransportError) -> Option<std::time::Duration> {
if let TransportError::ErrorResp(resp) = error {
let data = resp.try_data_as::<serde_json::Value>();
Expand Down
5 changes: 1 addition & 4 deletions crates/common/src/provider/runtime_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub enum InnerTransport {
Http(Http<reqwest::Client>),
/// WebSocket transport
Ws(PubSubFrontend),
// TODO: IPC
/// IPC transport
Ipc(PubSubFrontend),
}
Expand Down Expand Up @@ -177,7 +176,6 @@ impl RuntimeTransport {
let client =
client_builder.build().map_err(RuntimeTransportError::HttpConstructionError)?;

// todo: retry tower layer
Ok(InnerTransport::Http(Http::with_client(client, self.url.clone())))
}

Expand Down Expand Up @@ -271,7 +269,7 @@ impl tower::Service<RequestPacket> for RuntimeTransport {
}
}

impl Service<RequestPacket> for &RuntimeTransport {
impl tower::Service<RequestPacket> for &RuntimeTransport {
type Response = ResponsePacket;
type Error = TransportError;
type Future = TransportFut<'static>;
Expand All @@ -297,7 +295,6 @@ fn build_auth(jwt: String) -> eyre::Result<Authorization> {
let auth = JwtAuth::new(secret, None, None);
let token = auth.generate_token()?;

// Essentially unrolled ethers-rs new_with_auth to accommodate the custom timeout
let auth = Authorization::Bearer(token);

Ok(auth)
Expand Down
5 changes: 2 additions & 3 deletions crates/common/src/provider/tower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::{

use alloy_json_rpc::{RequestPacket, ResponsePacket};
use alloy_transport::{TransportError, TransportErrorKind, TransportFut};
use tower::Service;

use super::{
retry::{RateLimitRetryPolicy, RetryPolicy},
Expand Down Expand Up @@ -65,7 +64,7 @@ impl<S> tower::layer::Layer<S> for RetryBackoffLayer {
}

/// An Alloy Tower Service that is responsible for retrying requests based on the
/// error type. See [TransportError] and [RetryWithPolicyLayer].
/// error type. See [TransportError] and [RateLimitRetryPolicy].
#[derive(Debug, Clone)]
pub struct RetryBackoffService<S> {
/// The inner service
Expand All @@ -85,7 +84,7 @@ pub struct RetryBackoffService<S> {
}

// impl tower service
impl Service<RequestPacket> for RetryBackoffService<RuntimeTransport> {
impl tower::Service<RequestPacket> for RetryBackoffService<RuntimeTransport> {
type Response = ResponsePacket;
type Error = TransportError;
type Future = TransportFut<'static>;
Expand Down
Loading