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

RRR: Reconnection & Request Reissuance #2181

Merged
merged 17 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from 14 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@

### Unreleased

- Breaking: WS now includes reconnection logic and a changed `connect`
interface. Old behavior can be accessed via the `legacy_ws` feature
[#2181](https://github.com/gakonst/ethers-rs/pull/2181)
- Re-organize the crate. #[2150](https://github.com/gakonst/ethers-rs/pull/2159)
- Convert provider errors to arbitrary middleware errors
[#1920](https://github.com/gakonst/ethers-rs/pull/1920)
Expand Down
61 changes: 61 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion ethers-providers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pin-project = { version = "1.0.11", default-features = false }
enr = { version = "0.7.0", default-features = false, features = ["k256", "serde"] }

# tracing
tracing = { version = "0.1.37", default-features = false }
tracing = { version = "0.1.37", default-features = false, features = ["attributes"] }
tracing-futures = { version = "0.2.5", default-features = false, features = ["std-future"] }

bytes = { version = "1.4.0", default-features = false, optional = true }
Expand Down Expand Up @@ -76,10 +76,14 @@ default = ["ws", "rustls"]
celo = ["ethers-core/celo"]

ws = ["tokio-tungstenite", "futures-channel"]
legacy_ws = ["ws"]
ipc = ["tokio/io-util", "bytes", "futures-channel", "winapi"]

openssl = ["tokio-tungstenite/native-tls", "reqwest/native-tls"]
# we use the webpki roots so we can build static binaries w/o any root cert dependencies
# on the host
rustls = ["tokio-tungstenite/rustls-tls-webpki-roots", "reqwest/rustls-tls"]
dev-rpc = []

[dev-dependencies]
tracing-test = { version = "0.2.4", features = ["no-env-filter"] }
31 changes: 0 additions & 31 deletions ethers-providers/src/rpc/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use crate::{
MockProvider, NodeInfo, PeerInfo, PendingTransaction, QuorumProvider, RwClient,
};

#[cfg(all(not(target_arch = "wasm32"), feature = "ws"))]
use crate::Authorization;
#[cfg(not(target_arch = "wasm32"))]
use crate::{HttpRateLimitRetryPolicy, RetryClient};

Expand Down Expand Up @@ -1217,35 +1215,6 @@ impl<P: JsonRpcClient> Provider<P> {
}
}

#[cfg(feature = "ws")]
impl Provider<crate::Ws> {
/// Direct connection to a websocket endpoint
#[cfg(not(target_arch = "wasm32"))]
pub async fn connect(
url: impl tokio_tungstenite::tungstenite::client::IntoClientRequest + Unpin,
) -> Result<Self, ProviderError> {
let ws = crate::Ws::connect(url).await?;
Ok(Self::new(ws))
}

/// Direct connection to a websocket endpoint
#[cfg(target_arch = "wasm32")]
pub async fn connect(url: &str) -> Result<Self, ProviderError> {
let ws = crate::Ws::connect(url).await?;
Ok(Self::new(ws))
}

/// Connect to a WS RPC provider with authentication details
#[cfg(not(target_arch = "wasm32"))]
pub async fn connect_with_auth(
url: impl tokio_tungstenite::tungstenite::client::IntoClientRequest + Unpin,
auth: Authorization,
) -> Result<Self, ProviderError> {
let ws = crate::Ws::connect_with_auth(url, auth).await?;
Ok(Self::new(ws))
}
}

#[cfg(all(feature = "ipc", any(unix, windows)))]
impl Provider<crate::Ipc> {
#[cfg_attr(unix, doc = "Connects to the Unix socket at the provided path.")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,31 @@ mod tests {
resp.unwrap_err();
}
}

impl crate::Provider<Ws> {
/// Direct connection to a websocket endpoint
#[cfg(not(target_arch = "wasm32"))]
pub async fn connect(
url: impl tokio_tungstenite::tungstenite::client::IntoClientRequest + Unpin,
) -> Result<Self, ProviderError> {
let ws = crate::Ws::connect(url).await?;
Ok(Self::new(ws))
}

/// Direct connection to a websocket endpoint
#[cfg(target_arch = "wasm32")]
pub async fn connect(url: &str) -> Result<Self, ProviderError> {
let ws = crate::Ws::connect(url).await?;
Ok(Self::new(ws))
}

/// Connect to a WS RPC provider with authentication details
#[cfg(not(target_arch = "wasm32"))]
pub async fn connect_with_auth(
url: impl tokio_tungstenite::tungstenite::client::IntoClientRequest + Unpin,
auth: Authorization,
) -> Result<Self, ProviderError> {
let ws = crate::Ws::connect_with_auth(url, auth).await?;
Ok(Self::new(ws))
}
}
16 changes: 11 additions & 5 deletions ethers-providers/src/rpc/transports/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ mod ipc;
#[cfg(all(feature = "ipc", any(unix, windows)))]
pub use ipc::{Ipc, IpcError};

#[cfg(feature = "ws")]
mod ws;
#[cfg(feature = "ws")]
pub use ws::{ClientError as WsClientError, Ws};

mod quorum;
pub use quorum::{JsonRpcClientWrapper, Quorum, QuorumError, QuorumProvider, WeightedProvider};

Expand All @@ -23,5 +18,16 @@ pub use rw::{RwClient, RwClientError};
mod retry;
pub use retry::*;

#[cfg(all(feature = "ws", not(feature = "legacy_ws")))]
mod ws;
#[cfg(all(feature = "ws", not(feature = "legacy_ws")))]
pub use ws::{ConnectionDetails, WsClient as Ws, WsClientError};

/// archival websocket
#[cfg(feature = "legacy_ws")]
pub mod legacy_ws;
#[cfg(feature = "legacy_ws")]
pub use legacy_ws::Ws;

mod mock;
pub use mock::{MockError, MockProvider};
Loading