@@ -800,20 +800,24 @@ impl OutboundPayments {
800
800
{
801
801
let payment_hash = invoice. payment_hash ( ) ;
802
802
let max_total_routing_fee_msat;
803
+ let retry_strategy;
803
804
match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
804
805
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) ;
806
810
max_total_routing_fee_msat = * max_total_fee;
807
811
* entry. into_mut ( ) = PendingOutboundPayment :: InvoiceReceived {
808
812
payment_hash,
809
- retry_strategy : * retry_strategy ,
813
+ retry_strategy : * retry ,
810
814
max_total_routing_fee_msat,
811
815
} ;
812
816
} ,
813
817
_ => return Err ( Bolt12PaymentError :: DuplicateInvoice ) ,
814
818
} ,
815
819
hash_map:: Entry :: Vacant ( _) => return Err ( Bolt12PaymentError :: UnexpectedInvoice ) ,
816
- } ;
820
+ }
817
821
818
822
let mut payment_params = PaymentParameters :: from_bolt12_invoice ( & invoice) ;
819
823
@@ -839,25 +843,64 @@ impl OutboundPayments {
839
843
let mut route_params = RouteParameters :: from_payment_params_and_value (
840
844
payment_params, amount_msat
841
845
) ;
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
- } ) ?;
850
846
851
847
if let Some ( max_fee_msat) = max_total_routing_fee_msat {
852
848
route_params. max_total_routing_fee_msat = Some ( max_fee_msat) ;
853
849
}
854
850
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
859
877
) ;
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
+ }
860
887
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
+ }
861
904
Ok ( ( ) )
862
905
}
863
906
@@ -2290,7 +2333,7 @@ mod tests {
2290
2333
&&keys_manager, & EmptyNodeIdLookUp { } , & secp_ctx, 0 , &&logger, & pending_events,
2291
2334
|_| panic!( )
2292
2335
) ,
2293
- Ok ( ( ) ) ,
2336
+ Err ( Bolt12PaymentError :: SendingFailed ( RetryableSendFailure :: PaymentExpired ) ) ,
2294
2337
) ;
2295
2338
assert ! ( !outbound_payments. has_pending_payments( ) ) ;
2296
2339
@@ -2351,7 +2394,7 @@ mod tests {
2351
2394
&&keys_manager, & EmptyNodeIdLookUp { } , & secp_ctx, 0 , &&logger, & pending_events,
2352
2395
|_| panic!( )
2353
2396
) ,
2354
- Ok ( ( ) ) ,
2397
+ Err ( Bolt12PaymentError :: SendingFailed ( RetryableSendFailure :: RouteNotFound ) ) ,
2355
2398
) ;
2356
2399
assert ! ( !outbound_payments. has_pending_payments( ) ) ;
2357
2400
0 commit comments