@@ -11,6 +11,7 @@ use crate::payment::store::{
11
11
LSPFeeLimits , PaymentDetails , PaymentDetailsUpdate , PaymentDirection , PaymentKind ,
12
12
PaymentStatus , PaymentStore ,
13
13
} ;
14
+ use crate :: payment:: SendingParameters ;
14
15
use crate :: peer_store:: { PeerInfo , PeerStore } ;
15
16
use crate :: types:: { ChannelManager , KeysManager } ;
16
17
@@ -69,13 +70,20 @@ impl Bolt11Payment {
69
70
}
70
71
71
72
/// 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 > {
73
81
let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
74
82
if rt_lock. is_none ( ) {
75
83
return Err ( Error :: NotRunning ) ;
76
84
}
77
85
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 ( |_| {
79
87
log_error ! ( self . logger, "Failed to send payment due to the given invoice being \" zero-amount\" . Please use send_using_amount instead." ) ;
80
88
Error :: InvalidInvoice
81
89
} ) ?;
@@ -90,6 +98,40 @@ impl Bolt11Payment {
90
98
}
91
99
}
92
100
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
+
93
135
let payment_secret = Some ( * invoice. payment_secret ( ) ) ;
94
136
let retry_strategy = Retry :: Timeout ( LDK_PAYMENT_RETRY_TIMEOUT ) ;
95
137
@@ -148,14 +190,20 @@ impl Bolt11Payment {
148
190
}
149
191
}
150
192
151
- /// Send a payment given an invoice and an amount in millisatoshi .
193
+ /// Send a payment given an invoice and an amount in millisatoshis .
152
194
///
153
195
/// This will fail if the amount given is less than the value required by the given invoice.
154
196
///
155
197
/// This can be used to pay a so-called "zero-amount" invoice, i.e., an invoice that leaves the
156
198
/// 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.
157
204
pub fn send_using_amount (
158
205
& self , invoice : & Bolt11Invoice , amount_msat : u64 ,
206
+ sending_parameters : Option < SendingParameters > ,
159
207
) -> Result < PaymentId , Error > {
160
208
let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
161
209
if rt_lock. is_none ( ) {
@@ -196,9 +244,43 @@ impl Bolt11Payment {
196
244
. with_bolt11_features ( features. clone ( ) )
197
245
. map_err ( |_| Error :: InvalidInvoice ) ?;
198
246
}
199
- let route_params =
247
+ let mut route_params =
200
248
RouteParameters :: from_payment_params_and_value ( payment_params, amount_msat) ;
201
249
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
+
202
284
let retry_strategy = Retry :: Timeout ( LDK_PAYMENT_RETRY_TIMEOUT ) ;
203
285
let recipient_fields = RecipientOnionFields :: secret_only ( * payment_secret) ;
204
286
0 commit comments