Skip to content

Commit

Permalink
RRR: Reconnection & Request Reissuance (#2181)
Browse files Browse the repository at this point in the history
* wip: ws2

* ws2 backend compiles

* refactor: rename PubSubItem and BackendDriver

* feature: dispatch request to end subscription

* refactor: move ws2 to ws, fix reconnection and deser on subs

* chore: improve use of tracing in manager

* refactor: feature legacy_ws to enable backwards compatibility

* nit: mod file ordering

* docs: copy PR description to ws structs

* fixes: remove unused macros file, remove err formats

* docs: add comments to struct fields

* docs: comment client struct fields

* chore: changelog

* fix: unused imports in ws_errors test

* docs: missing comment

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>

* fix: legacy-ws feature in root crate, hyphen not underscore

* fix: a couple bad imports/exports

---------

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
  • Loading branch information
prestwich and gakonst committed Mar 1, 2023
1 parent 20375e2 commit 73636a9
Show file tree
Hide file tree
Showing 13 changed files with 1,262 additions and 54 deletions.
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
62 changes: 62 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::{ClientError as WsClientError, Ws};

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

0 comments on commit 73636a9

Please sign in to comment.