@@ -22,8 +22,7 @@ use crate::peer_store::{PeerInfo, PeerStore};
2222use crate :: types:: ChannelManager ;
2323
2424use lightning:: ln:: channelmanager:: {
25- Bolt11InvoiceParameters , Bolt11PaymentError , PaymentId , RecipientOnionFields , Retry ,
26- RetryableSendFailure ,
25+ Bolt11InvoiceParameters , Bolt11PaymentError , PaymentId , Retry , RetryableSendFailure ,
2726} ;
2827use lightning:: routing:: router:: { PaymentParameters , RouteParameters , RouteParametersConfig } ;
2928
@@ -187,8 +186,14 @@ impl Bolt11Payment {
187186 } ,
188187 Err ( Bolt11PaymentError :: InvalidAmount ) => {
189188 log_error ! ( self . logger,
190- "Failed to send payment due to the given invoice being \" zero-amount\" . Please use send_using_amount instead."
191- ) ;
189+ "Failed to send payment due to the given invoice being \" zero-amount\" . Please use send_using_amount instead."
190+ ) ;
191+ return Err ( Error :: InvalidInvoice ) ;
192+ } ,
193+ Err ( Bolt11PaymentError :: InvalidInvoice ) => {
194+ log_error ! ( self . logger,
195+ "Failed to send payment due to the given invoice being invalid or incompatible."
196+ ) ;
192197 return Err ( Error :: InvalidInvoice ) ;
193198 } ,
194199 Err ( Bolt11PaymentError :: SendingFailed ( e) ) => {
@@ -303,6 +308,12 @@ impl Bolt11Payment {
303308 ) ;
304309 return Err ( Error :: InvalidInvoice ) ;
305310 } ,
311+ Err ( Bolt11PaymentError :: InvalidInvoice ) => {
312+ log_error ! ( self . logger,
313+ "Failed to send payment due to the given invoice being invalid or incompatible."
314+ ) ;
315+ return Err ( Error :: InvalidInvoice ) ;
316+ } ,
306317 Err ( Bolt11PaymentError :: SendingFailed ( e) ) => {
307318 log_error ! ( self . logger, "Failed to send payment: {:?}" , e) ;
308319 match e {
@@ -714,18 +725,42 @@ impl Bolt11Payment {
714725 /// payment. To mitigate this issue, channels with available liquidity less than the required
715726 /// amount times [`Config::probing_liquidity_limit_multiplier`] won't be used to send
716727 /// pre-flight probes.
717- pub fn send_probes ( & self , invoice : & Bolt11Invoice ) -> Result < ( ) , Error > {
728+ pub fn send_probes (
729+ & self , invoice : & Bolt11Invoice , route_parameters : Option < RouteParametersConfig > ,
730+ ) -> Result < ( ) , Error > {
718731 let invoice = maybe_convert_invoice ( invoice) ;
719732 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
720733 if rt_lock. is_none ( ) {
721734 return Err ( Error :: NotRunning ) ;
722735 }
723736
724- let ( _payment_hash, _recipient_onion, route_params) = bolt11_payment:: payment_parameters_from_invoice ( & invoice) . map_err ( |_| {
737+ let payment_params = PaymentParameters :: from_bolt11_invoice ( invoice) . map_err ( |e| {
738+ log_error ! ( self . logger, "Failed to send payment probes: {:?}" , e) ;
739+ Error :: InvalidInvoice
740+ } ) ?;
741+
742+ let amount_msat = invoice. amount_milli_satoshis ( ) . ok_or_else ( || {
725743 log_error ! ( self . logger, "Failed to send probes due to the given invoice being \" zero-amount\" . Please use send_probes_using_amount instead." ) ;
726744 Error :: InvalidInvoice
727745 } ) ?;
728746
747+ let mut route_params =
748+ RouteParameters :: from_payment_params_and_value ( payment_params, amount_msat) ;
749+
750+ if let Some ( RouteParametersConfig {
751+ max_total_routing_fee_msat,
752+ max_total_cltv_expiry_delta,
753+ max_path_count,
754+ max_channel_saturation_power_of_half,
755+ } ) = route_parameters. as_ref ( ) . or ( self . config . route_parameters . as_ref ( ) )
756+ {
757+ route_params. max_total_routing_fee_msat = * max_total_routing_fee_msat;
758+ route_params. payment_params . max_total_cltv_expiry_delta = * max_total_cltv_expiry_delta;
759+ route_params. payment_params . max_path_count = * max_path_count;
760+ route_params. payment_params . max_channel_saturation_power_of_half =
761+ * max_channel_saturation_power_of_half;
762+ }
763+
729764 let liquidity_limit_multiplier = Some ( self . config . probing_liquidity_limit_multiplier ) ;
730765
731766 self . channel_manager
@@ -747,33 +782,47 @@ impl Bolt11Payment {
747782 /// See [`Self::send_probes`] for more information.
748783 pub fn send_probes_using_amount (
749784 & self , invoice : & Bolt11Invoice , amount_msat : u64 ,
785+ route_parameters : Option < RouteParametersConfig > ,
750786 ) -> Result < ( ) , Error > {
751787 let invoice = maybe_convert_invoice ( invoice) ;
752788 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
753789 if rt_lock. is_none ( ) {
754790 return Err ( Error :: NotRunning ) ;
755791 }
756792
757- let ( _payment_hash, _recipient_onion, route_params) = if let Some ( invoice_amount_msat) =
758- invoice. amount_milli_satoshis ( )
759- {
793+ let payment_params = PaymentParameters :: from_bolt11_invoice ( invoice) . map_err ( |e| {
794+ log_error ! ( self . logger, "Failed to send payment probes: {:?}" , e) ;
795+ Error :: InvalidInvoice
796+ } ) ?;
797+
798+ if let Some ( invoice_amount_msat) = invoice. amount_milli_satoshis ( ) {
760799 if amount_msat < invoice_amount_msat {
761800 log_error ! (
762801 self . logger,
763- "Failed to send probes as the given amount needs to be at least the invoice amount: required {}msat, gave {}msat." , invoice_amount_msat, amount_msat) ;
802+ "Failed to send probes as the given amount needs to be at least the invoice amount: required {}msat, gave {}msat." ,
803+ invoice_amount_msat,
804+ amount_msat
805+ ) ;
764806 return Err ( Error :: InvalidAmount ) ;
765807 }
808+ }
766809
767- bolt11_payment:: payment_parameters_from_invoice ( & invoice) . map_err ( |_| {
768- log_error ! ( self . logger, "Failed to send probes due to the given invoice unexpectedly being \" zero-amount\" ." ) ;
769- Error :: InvalidInvoice
770- } ) ?
771- } else {
772- bolt11_payment:: payment_parameters_from_variable_amount_invoice ( & invoice, amount_msat) . map_err ( |_| {
773- log_error ! ( self . logger, "Failed to send probes due to the given invoice unexpectedly being not \" zero-amount\" ." ) ;
774- Error :: InvalidInvoice
775- } ) ?
776- } ;
810+ let mut route_params =
811+ RouteParameters :: from_payment_params_and_value ( payment_params, amount_msat) ;
812+
813+ if let Some ( RouteParametersConfig {
814+ max_total_routing_fee_msat,
815+ max_total_cltv_expiry_delta,
816+ max_path_count,
817+ max_channel_saturation_power_of_half,
818+ } ) = route_parameters. as_ref ( ) . or ( self . config . route_parameters . as_ref ( ) )
819+ {
820+ route_params. max_total_routing_fee_msat = * max_total_routing_fee_msat;
821+ route_params. payment_params . max_total_cltv_expiry_delta = * max_total_cltv_expiry_delta;
822+ route_params. payment_params . max_path_count = * max_path_count;
823+ route_params. payment_params . max_channel_saturation_power_of_half =
824+ * max_channel_saturation_power_of_half;
825+ }
777826
778827 let liquidity_limit_multiplier = Some ( self . config . probing_liquidity_limit_multiplier ) ;
779828
0 commit comments