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

rpc: Export Client trait unconditionally #1305

Merged
merged 1 commit into from
Apr 27, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- [`tendermint-rpc`]: Export `Client` trait unconditionally, without
having to specify either the `http-client` or `websocket-client`
([\#1235](https://github.com/informalsystems/tendermint-rs/issues/1235))
8 changes: 2 additions & 6 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,20 @@ cli = [
"websocket-client"
]
http-client = [
"async-trait",
"futures",
"http",
"hyper",
"hyper-proxy",
"hyper-rustls",
"semver",
"tokio/fs",
"tokio/macros",
"tracing"
]
secp256k1 = [ "tendermint/secp256k1" ]
websocket-client = [
"async-trait",
"async-tungstenite",
"futures",
"http",
"semver",
"tokio/rt-multi-thread",
"tokio/fs",
"tokio/macros",
Expand All @@ -64,6 +60,7 @@ websocket-client = [
]

[dependencies]
async-trait = { version = "0.1", default-features = false }
bytes = { version = "1.0", default-features = false }
getrandom = { version = "0.2", default-features = false, features = ["js"] }
peg = { version = "0.7.0", default-features = false }
Expand All @@ -81,16 +78,15 @@ url = { version = "2.2", default-features = false }
walkdir = { version = "2.3", default-features = false }
flex-error = { version = "0.4.4", default-features = false }
subtle = { version = "2", default-features = false }
semver = { version = "1.0", default-features = false }

# Optional dependencies
async-trait = { version = "0.1", optional = true, default-features = false }
async-tungstenite = { version = "0.20", default-features = false, features = ["tokio-runtime", "tokio-rustls-native-certs"], optional = true }
futures = { version = "0.3", optional = true, default-features = false }
http = { version = "0.2", optional = true, default-features = false }
hyper = { version = "0.14", optional = true, default-features = false, features = ["client", "http1", "http2"] }
hyper-proxy = { version = "0.9.1", optional = true, default-features = false, features = ["rustls"] }
hyper-rustls = { version = "0.22.1", optional = true, default-features = false, features = ["rustls-native-certs", "webpki-roots", "tokio-runtime"] }
semver = { version = "1.0", optional = true, default-features = false }
structopt = { version = "0.3", optional = true, default-features = false }
tokio = { version = "1.0", optional = true, default-features = false, features = ["rt-multi-thread"] }
tracing = { version = "0.1", optional = true, default-features = false }
Expand Down
20 changes: 14 additions & 6 deletions rpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,33 @@

mod compat;
pub use compat::CompatMode;

#[cfg(any(feature = "http-client", feature = "websocket-client"))]
mod subscription;
#[cfg(any(feature = "http-client", feature = "websocket-client"))]
pub use subscription::{Subscription, SubscriptionClient};

#[cfg(any(feature = "http-client", feature = "websocket-client"))]
pub mod sync;

#[cfg(any(feature = "http-client", feature = "websocket-client"))]
mod transport;

#[cfg(feature = "http-client")]
pub use transport::http::{HttpClient, HttpClientUrl};
pub use transport::mock::{MockClient, MockRequestMatcher, MockRequestMethodMatcher};
#[cfg(feature = "websocket-client")]
pub use transport::websocket::{
WebSocketClient, WebSocketClientDriver, WebSocketClientUrl, WebSocketConfig,
};

use core::{fmt, time::Duration};
#[cfg(any(feature = "http-client", feature = "websocket-client"))]
pub use transport::mock::{MockClient, MockRequestMatcher, MockRequestMethodMatcher};

use core::fmt;

use async_trait::async_trait;
use serde::{de::DeserializeOwned, Serialize};
use tendermint::{abci, block::Height, evidence::Evidence, Genesis, Hash};
use tokio::time;

use crate::{
endpoint::{validators::DEFAULT_VALIDATORS_PER_PAGE, *},
Expand Down Expand Up @@ -297,14 +304,15 @@ pub trait Client {
.await
}

#[cfg(any(feature = "http-client", feature = "websocket-client"))]
/// Poll the `/health` endpoint until it returns a successful result or
/// the given `timeout` has elapsed.
async fn wait_until_healthy<T>(&self, timeout: T) -> Result<(), Error>
where
T: Into<Duration> + Send,
T: Into<core::time::Duration> + Send,
{
let timeout = timeout.into();
let poll_interval = Duration::from_millis(200);
let poll_interval = core::time::Duration::from_millis(200);
let mut attempts_remaining = timeout.as_millis() / poll_interval.as_millis();

while self.health().await.is_err() {
Expand All @@ -313,7 +321,7 @@ pub trait Client {
}

attempts_remaining -= 1;
time::sleep(poll_interval).await;
tokio::time::sleep(poll_interval).await;
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ extern crate std;

mod prelude;

#[cfg(any(feature = "http-client", feature = "websocket-client"))]
pub mod client;

#[cfg(any(feature = "http-client", feature = "websocket-client"))]
pub use client::{
Client, MockClient, MockRequestMatcher, MockRequestMethodMatcher, Subscription,
Expand Down