@@ -11,6 +11,7 @@ use crate::payment::store::{
1111 LSPFeeLimits , PaymentDetails , PaymentDetailsUpdate , PaymentDirection , PaymentKind ,
1212 PaymentStatus , PaymentStore ,
1313} ;
14+ use crate :: payment:: SendingParameters ;
1415use crate :: peer_store:: { PeerInfo , PeerStore } ;
1516use crate :: types:: { ChannelManager , KeysManager } ;
1617
@@ -69,13 +70,20 @@ impl Bolt11Payment {
6970 }
7071
7172 /// Send a payment given an invoice.
72- pub fn send ( & self , invoice : & Bolt11Invoice ) -> Result < PaymentId , Error > {
73+ ///
74+ /// If [`SendingParameters`] are provided they will override the node's default routing parameters
75+ /// on a per-field basis. Each field in `SendingParameters` that is set replaces the corresponding
76+ /// default value. Fields that are not set fall back to the node's configured defaults. If no
77+ /// `SendingParameters` are provided, the method fully relies on these defaults.
78+ pub fn send (
79+ & self , invoice : & Bolt11Invoice , sending_parameters : Option < SendingParameters > ,
80+ ) -> Result < PaymentId , Error > {
7381 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
7482 if rt_lock. is_none ( ) {
7583 return Err ( Error :: NotRunning ) ;
7684 }
7785
78- let ( payment_hash, recipient_onion, route_params) = payment:: payment_parameters_from_invoice ( & invoice) . map_err ( |_| {
86+ let ( payment_hash, recipient_onion, mut route_params) = payment:: payment_parameters_from_invoice ( & invoice) . map_err ( |_| {
7987 log_error ! ( self . logger, "Failed to send payment due to the given invoice being \" zero-amount\" . Please use send_using_amount instead." ) ;
8088 Error :: InvalidInvoice
8189 } ) ?;
@@ -90,6 +98,40 @@ impl Bolt11Payment {
9098 }
9199 }
92100
101+ if let Some ( user_set_params) = sending_parameters {
102+ if let Some ( mut default_params) =
103+ self . config . sending_parameters_config . as_ref ( ) . cloned ( )
104+ {
105+ default_params. max_total_routing_fee_msat = user_set_params
106+ . max_total_routing_fee_msat
107+ . or ( default_params. max_total_routing_fee_msat ) ;
108+ default_params. max_total_cltv_expiry_delta = user_set_params
109+ . max_total_cltv_expiry_delta
110+ . or ( default_params. max_total_cltv_expiry_delta ) ;
111+ default_params. max_path_count =
112+ user_set_params. max_path_count . or ( default_params. max_path_count ) ;
113+ default_params. max_channel_saturation_power_of_half = user_set_params
114+ . max_channel_saturation_power_of_half
115+ . or ( default_params. max_channel_saturation_power_of_half ) ;
116+
117+ route_params. max_total_routing_fee_msat = default_params. max_total_routing_fee_msat ;
118+ route_params. payment_params . max_total_cltv_expiry_delta =
119+ default_params. max_total_cltv_expiry_delta . unwrap_or_default ( ) ;
120+ route_params. payment_params . max_path_count =
121+ default_params. max_path_count . unwrap_or_default ( ) ;
122+ route_params. payment_params . max_channel_saturation_power_of_half =
123+ default_params. max_channel_saturation_power_of_half . unwrap_or_default ( ) ;
124+ }
125+ } else if let Some ( default_params) = & self . config . sending_parameters_config {
126+ route_params. max_total_routing_fee_msat = default_params. max_total_routing_fee_msat ;
127+ route_params. payment_params . max_total_cltv_expiry_delta =
128+ default_params. max_total_cltv_expiry_delta . unwrap_or_default ( ) ;
129+ route_params. payment_params . max_path_count =
130+ default_params. max_path_count . unwrap_or_default ( ) ;
131+ route_params. payment_params . max_channel_saturation_power_of_half =
132+ default_params. max_channel_saturation_power_of_half . unwrap_or_default ( ) ;
133+ }
134+
93135 let payment_secret = Some ( * invoice. payment_secret ( ) ) ;
94136 let retry_strategy = Retry :: Timeout ( LDK_PAYMENT_RETRY_TIMEOUT ) ;
95137
@@ -148,14 +190,20 @@ impl Bolt11Payment {
148190 }
149191 }
150192
151- /// Send a payment given an invoice and an amount in millisatoshi .
193+ /// Send a payment given an invoice and an amount in millisatoshis .
152194 ///
153195 /// This will fail if the amount given is less than the value required by the given invoice.
154196 ///
155197 /// This can be used to pay a so-called "zero-amount" invoice, i.e., an invoice that leaves the
156198 /// amount paid to be determined by the user.
199+ ///
200+ /// If [`SendingParameters`] are provided they will override the node's default routing parameters
201+ /// on a per-field basis. Each field in `SendingParameters` that is set replaces the corresponding
202+ /// default value. Fields that are not set fall back to the node's configured defaults. If no
203+ /// `SendingParameters` are provided, the method fully relies on these defaults.
157204 pub fn send_using_amount (
158205 & self , invoice : & Bolt11Invoice , amount_msat : u64 ,
206+ sending_parameters : Option < SendingParameters > ,
159207 ) -> Result < PaymentId , Error > {
160208 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
161209 if rt_lock. is_none ( ) {
@@ -196,9 +244,43 @@ impl Bolt11Payment {
196244 . with_bolt11_features ( features. clone ( ) )
197245 . map_err ( |_| Error :: InvalidInvoice ) ?;
198246 }
199- let route_params =
247+ let mut route_params =
200248 RouteParameters :: from_payment_params_and_value ( payment_params, amount_msat) ;
201249
250+ if let Some ( user_set_params) = sending_parameters {
251+ if let Some ( mut default_params) =
252+ self . config . sending_parameters_config . as_ref ( ) . cloned ( )
253+ {
254+ default_params. max_total_routing_fee_msat = user_set_params
255+ . max_total_routing_fee_msat
256+ . or ( default_params. max_total_routing_fee_msat ) ;
257+ default_params. max_total_cltv_expiry_delta = user_set_params
258+ . max_total_cltv_expiry_delta
259+ . or ( default_params. max_total_cltv_expiry_delta ) ;
260+ default_params. max_path_count =
261+ user_set_params. max_path_count . or ( default_params. max_path_count ) ;
262+ default_params. max_channel_saturation_power_of_half = user_set_params
263+ . max_channel_saturation_power_of_half
264+ . or ( default_params. max_channel_saturation_power_of_half ) ;
265+
266+ route_params. max_total_routing_fee_msat = default_params. max_total_routing_fee_msat ;
267+ route_params. payment_params . max_total_cltv_expiry_delta =
268+ default_params. max_total_cltv_expiry_delta . unwrap_or_default ( ) ;
269+ route_params. payment_params . max_path_count =
270+ default_params. max_path_count . unwrap_or_default ( ) ;
271+ route_params. payment_params . max_channel_saturation_power_of_half =
272+ default_params. max_channel_saturation_power_of_half . unwrap_or_default ( ) ;
273+ }
274+ } else if let Some ( default_params) = & self . config . sending_parameters_config {
275+ route_params. max_total_routing_fee_msat = default_params. max_total_routing_fee_msat ;
276+ route_params. payment_params . max_total_cltv_expiry_delta =
277+ default_params. max_total_cltv_expiry_delta . unwrap_or_default ( ) ;
278+ route_params. payment_params . max_path_count =
279+ default_params. max_path_count . unwrap_or_default ( ) ;
280+ route_params. payment_params . max_channel_saturation_power_of_half =
281+ default_params. max_channel_saturation_power_of_half . unwrap_or_default ( ) ;
282+ }
283+
202284 let retry_strategy = Retry :: Timeout ( LDK_PAYMENT_RETRY_TIMEOUT ) ;
203285 let recipient_fields = RecipientOnionFields :: secret_only ( * payment_secret) ;
204286
0 commit comments