Skip to content

Commit 659bddc

Browse files
YusukeShimizucdecker
authored andcommitted
glclient: lift default decoding size
Lift the maximum decoding message size from 4MB to 32MB by default. Prevent large gRPC responses from failing. Make it configurable via the Node builder. Retain a safe default to limit DoS risks We trust the server logic, so increasing the default is safe.
1 parent ed1f18b commit 659bddc

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

libs/gl-client/src/node/generic.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ where
6666
}
6767

6868
// TODO Add a `streaming_call` for methods that return a stream to the client
69+
70+
pub fn max_decoding_message_size(mut self, limit: usize) -> Self
71+
where
72+
T: tonic::client::GrpcService<tonic::body::BoxBody>,
73+
{
74+
self.inner = self.inner.max_decoding_message_size(limit);
75+
self
76+
}
6977
}
7078

7179
/// `tonic::client::Grpc<T>` requires a codec to convert between the

libs/gl-client/src/node/mod.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use log::{debug, info, trace};
99
use tonic::transport::{Channel, Uri};
1010
use tower::ServiceBuilder;
1111

12+
const DEFAULT_MAX_DECODING_MESSAGE_SIZE: usize = 32 * 1024 * 1024; // 32 MiB
13+
1214
/// A client to the remotely running node on the greenlight
1315
/// infrastructure. It is configured to authenticate itself with the
1416
/// device mTLS keypair and will sign outgoing requests with the same
@@ -20,7 +22,7 @@ pub type GClient = GenericClient<service::AuthService>;
2022
pub type ClnClient = cln_client::NodeClient<service::AuthService>;
2123

2224
pub trait GrpcClient {
23-
fn new_with_inner(inner: service::AuthService) -> Self;
25+
fn new_with_inner(inner: service::AuthService, max_decoding_message_size: usize) -> Self;
2426
}
2527

2628
/// A builder to configure a [`Client`] that can either connect to a
@@ -34,23 +36,24 @@ pub struct Node {
3436
node_id: Vec<u8>,
3537
tls: TlsConfig,
3638
rune: String,
39+
max_decoding_message_size: Option<usize>,
3740
}
3841

3942
impl GrpcClient for Client {
40-
fn new_with_inner(inner: service::AuthService) -> Self {
41-
Client::new(inner)
43+
fn new_with_inner(inner: service::AuthService, max_decoding_message_size: usize) -> Self {
44+
Client::new(inner).max_decoding_message_size(max_decoding_message_size)
4245
}
4346
}
4447

4548
impl GrpcClient for GClient {
46-
fn new_with_inner(inner: service::AuthService) -> Self {
47-
GenericClient::new(inner)
49+
fn new_with_inner(inner: service::AuthService, max_decoding_message_size: usize) -> Self {
50+
GenericClient::new(inner).max_decoding_message_size(max_decoding_message_size)
4851
}
4952
}
5053

5154
impl GrpcClient for ClnClient {
52-
fn new_with_inner(inner: service::AuthService) -> Self {
53-
ClnClient::new(inner)
55+
fn new_with_inner(inner: service::AuthService, max_decoding_message_size: usize) -> Self {
56+
ClnClient::new(inner).max_decoding_message_size(max_decoding_message_size)
5457
}
5558
}
5659

@@ -65,9 +68,15 @@ impl Node {
6568
node_id,
6669
tls,
6770
rune,
71+
max_decoding_message_size: None,
6872
})
6973
}
7074

75+
pub fn with_max_decoding_message_size(mut self, size: usize) -> Self {
76+
self.max_decoding_message_size = Some(size);
77+
self
78+
}
79+
7180
pub async fn connect<C>(&self, node_uri: String) -> Result<C>
7281
where
7382
C: GrpcClient,
@@ -112,7 +121,11 @@ impl Node {
112121
.connect_lazy();
113122
let chan = ServiceBuilder::new().layer(layer).service(chan);
114123

115-
Ok(C::new_with_inner(chan))
124+
let size = self
125+
.max_decoding_message_size
126+
.unwrap_or(DEFAULT_MAX_DECODING_MESSAGE_SIZE);
127+
128+
Ok(C::new_with_inner(chan, size))
116129
}
117130

118131
pub async fn schedule_with_uri<C>(self, scheduler_uri: String) -> Result<C>

0 commit comments

Comments
 (0)