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

fix: Fix rustls setup for jsonrpsee clients #2417

Merged
merged 1 commit into from
Jul 10, 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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ reqwest = "0.12"
rlp = "0.5"
rocksdb = "0.21.0"
rustc_version = "0.4.0"
rustls = "0.23"
secp256k1 = { version = "0.27.0", features = ["recovery", "global-context"] }
secrecy = "0.8.0"
semver = "1"
Expand Down
15 changes: 15 additions & 0 deletions core/lib/eth_client/src/clients/http/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,18 @@ where
Ok(block)
}
}

#[cfg(test)]
mod tests {
use zksync_web3_decl::client::{Client, L1};

/// This test makes sure that we can instantiate a client with an HTTPS provider.
/// The need for this test was caused by feature collisions for `rustls` in our dependency graph,
/// which caused this test to panic.
#[tokio::test]
async fn test_https_provider() {
let url = "https://rpc.flashbots.net/";
let _client = Client::<L1>::http(url.parse().unwrap()).unwrap().build();
// No need to do anything; if the client was created and we didn't panic, we're good.
}
}
1 change: 1 addition & 0 deletions core/lib/web3_decl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ serde_json.workspace = true
tokio = { workspace = true, features = ["time"] }
tracing.workspace = true
vise.workspace = true
rustls.workspace = true

[dev-dependencies]
assert_matches.workspace = true
Expand Down
5 changes: 5 additions & 0 deletions core/lib/web3_decl/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ mod boxed;
mod metrics;
mod mock;
mod network;
mod rustls;
mod shared;
#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -140,6 +141,8 @@ impl<Net: fmt::Debug, C: 'static> fmt::Debug for Client<Net, C> {
impl<Net: Network> Client<Net> {
/// Creates an HTTP-backed client.
pub fn http(url: SensitiveUrl) -> anyhow::Result<ClientBuilder<Net>> {
crate::client::rustls::set_rustls_backend_if_required();

let client = HttpClientBuilder::default().build(url.expose_str())?;
Ok(ClientBuilder::new(client, url))
}
Expand All @@ -150,6 +153,8 @@ impl<Net: Network> WsClient<Net> {
pub async fn ws(
url: SensitiveUrl,
) -> anyhow::Result<ClientBuilder<Net, Shared<ws_client::WsClient>>> {
crate::client::rustls::set_rustls_backend_if_required();

let client = ws_client::WsClientBuilder::default()
.build(url.expose_str())
.await?;
Expand Down
10 changes: 10 additions & 0 deletions core/lib/web3_decl/src/client/rustls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// Makes sure that `rustls` crypto backend is set before we instantiate
/// a `Web3` client. `jsonrpsee` doesn't explicitly set it, and when
/// multiple crypto backends are enabled, `rustls` can't choose one and panics.
/// See [this issue](https://github.com/rustls/rustls/issues/1877) for more detail.
///
/// The problem is on `jsonrpsee` side, but until it's fixed we have to patch it.
pub(super) fn set_rustls_backend_if_required() {
// Function returns an error if the provider is already installed, and we're fine with it.
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
}
48 changes: 48 additions & 0 deletions prover/Cargo.lock

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

Loading