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

feat(sdk): configure grpc settings #1922

Closed
wants to merge 3 commits into from
Closed
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: 2 additions & 10 deletions crates/sdk/src/network/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use tonic::{
Code,
};

use super::grpc;
use super::utils::Signable;
use crate::network::proto::artifact::{
artifact_store_client::ArtifactStoreClient, ArtifactType, CreateArtifactRequest,
Expand Down Expand Up @@ -258,16 +259,7 @@ impl NetworkClient {
}

pub(crate) async fn prover_network_client(&self) -> Result<ProverNetworkClient<Channel>> {
let rpc_url = self.rpc_url.clone();
let mut endpoint = Channel::from_shared(rpc_url.clone())?;

// Check if the URL scheme is HTTPS and configure TLS.
if rpc_url.starts_with("https://") {
let tls_config = ClientTlsConfig::new().with_enabled_roots();
endpoint = endpoint.tls_config(tls_config)?;
}

let channel = endpoint.connect().await?;
let channel = grpc::configure_endpoint(&self.rpc_url)?.connect().await?;
Ok(ProverNetworkClient::new(channel))
}

Expand Down
24 changes: 24 additions & 0 deletions crates/sdk/src/network/grpc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::time::Duration;
use tonic::transport::{ClientTlsConfig, Endpoint, Error};

/// Configures the endpoint for the gRPC client.
///
/// Sets reasonable settings to handle timeouts and keep-alive.
pub fn configure_endpoint(addr: &str) -> Result<Endpoint, Error> {
let mut endpoint = Endpoint::new(addr.to_string())?
.timeout(Duration::from_secs(60))
.connect_timeout(Duration::from_secs(15))
.keep_alive_while_idle(true)
.http2_keep_alive_interval(Duration::from_secs(15))
.keep_alive_timeout(Duration::from_secs(15))
.tcp_keepalive(Some(Duration::from_secs(60)))
.tcp_nodelay(true);

// Configure TLS if using HTTPS.
if addr.starts_with("https://") {
let tls_config = ClientTlsConfig::new().with_enabled_roots();
endpoint = endpoint.tls_config(tls_config)?;
}

Ok(endpoint)
}
1 change: 1 addition & 0 deletions crates/sdk/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod prover;
pub mod proto;
pub mod builder;
mod error;
mod grpc;
pub mod prove;
pub mod utils;

Expand Down
Loading