@@ -800,20 +800,24 @@ impl OutboundPayments {
800800 {
801801 let payment_hash = invoice. payment_hash ( ) ;
802802 let max_total_routing_fee_msat;
803+ let retry_strategy;
803804 match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
804805 hash_map:: Entry :: Occupied ( entry) => match entry. get ( ) {
805- PendingOutboundPayment :: AwaitingInvoice { retry_strategy, max_total_routing_fee_msat : max_total_fee, .. } => {
806+ PendingOutboundPayment :: AwaitingInvoice {
807+ retry_strategy : retry, max_total_routing_fee_msat : max_total_fee, ..
808+ } => {
809+ retry_strategy = Some ( * retry) ;
806810 max_total_routing_fee_msat = * max_total_fee;
807811 * entry. into_mut ( ) = PendingOutboundPayment :: InvoiceReceived {
808812 payment_hash,
809- retry_strategy : * retry_strategy ,
813+ retry_strategy : * retry ,
810814 max_total_routing_fee_msat,
811815 } ;
812816 } ,
813817 _ => return Err ( Bolt12PaymentError :: DuplicateInvoice ) ,
814818 } ,
815819 hash_map:: Entry :: Vacant ( _) => return Err ( Bolt12PaymentError :: UnexpectedInvoice ) ,
816- } ;
820+ }
817821
818822 let mut payment_params = PaymentParameters :: from_bolt12_invoice ( & invoice) ;
819823
@@ -839,25 +843,64 @@ impl OutboundPayments {
839843 let mut route_params = RouteParameters :: from_payment_params_and_value (
840844 payment_params, amount_msat
841845 ) ;
842- onion_utils:: set_max_path_length (
843- & mut route_params, & RecipientOnionFields :: spontaneous_empty ( ) , None , best_block_height
844- )
845- . map_err ( |( ) | {
846- log_error ! ( logger, "Can't construct an onion packet without exceeding 1300-byte onion \
847- hop_data length for payment with id {} and hash {}", payment_id, payment_hash) ;
848- Bolt12PaymentError :: SendingFailed ( RetryableSendFailure :: OnionPacketSizeExceeded )
849- } ) ?;
850846
851847 if let Some ( max_fee_msat) = max_total_routing_fee_msat {
852848 route_params. max_total_routing_fee_msat = Some ( max_fee_msat) ;
853849 }
854850
855- self . find_route_and_send_payment (
856- payment_hash, payment_id, route_params, router, first_hops, & inflight_htlcs,
857- entropy_source, node_signer, best_block_height, logger, pending_events,
858- & send_payment_along_path
851+ let recipient_onion = RecipientOnionFields {
852+ payment_secret : None ,
853+ payment_metadata : None ,
854+ custom_tlvs : vec ! [ ] ,
855+ } ;
856+ let route = match self . find_initial_route (
857+ payment_id, payment_hash, & recipient_onion, None , & mut route_params, router,
858+ & first_hops, & inflight_htlcs, node_signer, best_block_height, logger,
859+ ) {
860+ Ok ( route) => route,
861+ Err ( e) => {
862+ let reason = match e {
863+ RetryableSendFailure :: PaymentExpired => PaymentFailureReason :: PaymentExpired ,
864+ RetryableSendFailure :: RouteNotFound => PaymentFailureReason :: RouteNotFound ,
865+ RetryableSendFailure :: DuplicatePayment => PaymentFailureReason :: UnexpectedError ,
866+ RetryableSendFailure :: OnionPacketSizeExceeded => PaymentFailureReason :: UnexpectedError ,
867+ } ;
868+ self . abandon_payment ( payment_id, reason, pending_events) ;
869+ return Err ( Bolt12PaymentError :: SendingFailed ( e) ) ;
870+ } ,
871+ } ;
872+
873+ let payment_params = Some ( route_params. payment_params . clone ( ) ) ;
874+ let ( retryable_payment, onion_session_privs) = self . create_pending_payment (
875+ payment_hash, recipient_onion. clone ( ) , None , & route,
876+ retry_strategy, payment_params, entropy_source, best_block_height
859877 ) ;
878+ match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
879+ hash_map:: Entry :: Occupied ( entry) => match entry. get ( ) {
880+ PendingOutboundPayment :: InvoiceReceived { .. } => {
881+ * entry. into_mut ( ) = retryable_payment;
882+ } ,
883+ _ => return Err ( Bolt12PaymentError :: DuplicateInvoice ) ,
884+ } ,
885+ hash_map:: Entry :: Vacant ( _) => return Err ( Bolt12PaymentError :: UnexpectedInvoice ) ,
886+ }
860887
888+ let result = self . pay_route_internal (
889+ & route, payment_hash, & recipient_onion, None , payment_id,
890+ Some ( route_params. final_value_msat ) , onion_session_privs, node_signer,
891+ best_block_height, & send_payment_along_path
892+ ) ;
893+ log_info ! (
894+ logger, "Sending payment with id {} and hash {} returned {:?}" , payment_id,
895+ payment_hash, result
896+ ) ;
897+ if let Err ( e) = result {
898+ self . handle_pay_route_err (
899+ e, payment_id, payment_hash, route, route_params, router, first_hops,
900+ & inflight_htlcs, entropy_source, node_signer, best_block_height, logger,
901+ pending_events, & send_payment_along_path
902+ ) ;
903+ }
861904 Ok ( ( ) )
862905 }
863906
@@ -2290,7 +2333,7 @@ mod tests {
22902333 &&keys_manager, & EmptyNodeIdLookUp { } , & secp_ctx, 0 , &&logger, & pending_events,
22912334 |_| panic!( )
22922335 ) ,
2293- Ok ( ( ) ) ,
2336+ Err ( Bolt12PaymentError :: SendingFailed ( RetryableSendFailure :: PaymentExpired ) ) ,
22942337 ) ;
22952338 assert ! ( !outbound_payments. has_pending_payments( ) ) ;
22962339
@@ -2351,7 +2394,7 @@ mod tests {
23512394 &&keys_manager, & EmptyNodeIdLookUp { } , & secp_ctx, 0 , &&logger, & pending_events,
23522395 |_| panic!( )
23532396 ) ,
2354- Ok ( ( ) ) ,
2397+ Err ( Bolt12PaymentError :: SendingFailed ( RetryableSendFailure :: RouteNotFound ) ) ,
23552398 ) ;
23562399 assert ! ( !outbound_payments. has_pending_payments( ) ) ;
23572400
0 commit comments