diff --git a/libs/gl-client/src/node/generic.rs b/libs/gl-client/src/node/generic.rs index 6a79485e2..4dd8bf6ed 100644 --- a/libs/gl-client/src/node/generic.rs +++ b/libs/gl-client/src/node/generic.rs @@ -66,6 +66,14 @@ where } // TODO Add a `streaming_call` for methods that return a stream to the client + + pub fn max_decoding_message_size(mut self, limit: usize) -> Self + where + T: tonic::client::GrpcService, + { + self.inner = self.inner.max_decoding_message_size(limit); + self + } } /// `tonic::client::Grpc` requires a codec to convert between the diff --git a/libs/gl-client/src/node/mod.rs b/libs/gl-client/src/node/mod.rs index 9517ed248..24cb05241 100644 --- a/libs/gl-client/src/node/mod.rs +++ b/libs/gl-client/src/node/mod.rs @@ -9,6 +9,8 @@ use log::{debug, info, trace}; use tonic::transport::{Channel, Uri}; use tower::ServiceBuilder; +const DEFAULT_MAX_DECODING_MESSAGE_SIZE: usize = 32 * 1024 * 1024; // 32 MiB + /// A client to the remotely running node on the greenlight /// infrastructure. It is configured to authenticate itself with the /// device mTLS keypair and will sign outgoing requests with the same @@ -20,7 +22,7 @@ pub type GClient = GenericClient; pub type ClnClient = cln_client::NodeClient; pub trait GrpcClient { - fn new_with_inner(inner: service::AuthService) -> Self; + fn new_with_inner(inner: service::AuthService, max_decoding_message_size: usize) -> Self; } /// A builder to configure a [`Client`] that can either connect to a @@ -34,23 +36,24 @@ pub struct Node { node_id: Vec, tls: TlsConfig, rune: String, + max_decoding_message_size: Option, } impl GrpcClient for Client { - fn new_with_inner(inner: service::AuthService) -> Self { - Client::new(inner) + fn new_with_inner(inner: service::AuthService, max_decoding_message_size: usize) -> Self { + Client::new(inner).max_decoding_message_size(max_decoding_message_size) } } impl GrpcClient for GClient { - fn new_with_inner(inner: service::AuthService) -> Self { - GenericClient::new(inner) + fn new_with_inner(inner: service::AuthService, max_decoding_message_size: usize) -> Self { + GenericClient::new(inner).max_decoding_message_size(max_decoding_message_size) } } impl GrpcClient for ClnClient { - fn new_with_inner(inner: service::AuthService) -> Self { - ClnClient::new(inner) + fn new_with_inner(inner: service::AuthService, max_decoding_message_size: usize) -> Self { + ClnClient::new(inner).max_decoding_message_size(max_decoding_message_size) } } @@ -65,9 +68,15 @@ impl Node { node_id, tls, rune, + max_decoding_message_size: None, }) } + pub fn with_max_decoding_message_size(mut self, size: usize) -> Self { + self.max_decoding_message_size = Some(size); + self + } + pub async fn connect(&self, node_uri: String) -> Result where C: GrpcClient, @@ -112,7 +121,11 @@ impl Node { .connect_lazy(); let chan = ServiceBuilder::new().layer(layer).service(chan); - Ok(C::new_with_inner(chan)) + let size = self + .max_decoding_message_size + .unwrap_or(DEFAULT_MAX_DECODING_MESSAGE_SIZE); + + Ok(C::new_with_inner(chan, size)) } pub async fn schedule_with_uri(self, scheduler_uri: String) -> Result