@@ -9,6 +9,8 @@ use log::{debug, info, trace};
99use tonic:: transport:: { Channel , Uri } ;
1010use 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>;
2022pub type ClnClient = cln_client:: NodeClient < service:: AuthService > ;
2123
2224pub 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
3942impl 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
4548impl 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
5154impl 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