@@ -380,7 +380,14 @@ impl OutboundPayments {
380
380
u32 , PaymentId , & Option < PaymentPreimage > , [ u8 ; 32 ] ) -> Result < ( ) , APIError >
381
381
{
382
382
let onion_session_privs = self . add_new_pending_payment ( payment_hash, * payment_secret, payment_id, route, Retry :: Attempts ( 0 ) , None , entropy_source, best_block_height) ?;
383
- self . send_payment_internal ( route, payment_hash, payment_secret, None , payment_id, None , onion_session_privs, node_signer, best_block_height, send_payment_along_path)
383
+ self . send_payment_internal ( route, payment_hash, payment_secret, None , payment_id, None ,
384
+ onion_session_privs, node_signer, best_block_height, send_payment_along_path)
385
+ . map_err ( |e| { // TODO: use inspect_err instead when it's within MSRV
386
+ if let PaymentSendFailure :: AllFailedResendSafe ( _) = e {
387
+ self . all_failed_remove_outbound ( payment_id) ;
388
+ }
389
+ e
390
+ } )
384
391
}
385
392
386
393
pub ( super ) fn send_spontaneous_payment < ES : Deref , NS : Deref , F > (
@@ -402,7 +409,12 @@ impl OutboundPayments {
402
409
403
410
match self . send_payment_internal ( route, payment_hash, & None , Some ( preimage) , payment_id, None , onion_session_privs, node_signer, best_block_height, send_payment_along_path) {
404
411
Ok ( ( ) ) => Ok ( payment_hash) ,
405
- Err ( e) => Err ( e)
412
+ Err ( e) => {
413
+ if let PaymentSendFailure :: AllFailedResendSafe ( _) = e {
414
+ self . all_failed_remove_outbound ( payment_id) ;
415
+ }
416
+ Err ( e)
417
+ }
406
418
}
407
419
}
408
420
@@ -501,7 +513,12 @@ impl OutboundPayments {
501
513
502
514
match self . send_payment_internal ( & route, payment_hash, & None , None , payment_id, None , onion_session_privs, node_signer, best_block_height, send_payment_along_path) {
503
515
Ok ( ( ) ) => Ok ( ( payment_hash, payment_id) ) ,
504
- Err ( e) => Err ( e)
516
+ Err ( e) => {
517
+ if let PaymentSendFailure :: AllFailedResendSafe ( _) = e {
518
+ self . all_failed_remove_outbound ( payment_id) ;
519
+ }
520
+ Err ( e)
521
+ }
505
522
}
506
523
}
507
524
@@ -648,10 +665,6 @@ impl OutboundPayments {
648
665
} else { None } ,
649
666
} )
650
667
} else if has_err {
651
- // If we failed to send any paths, we should remove the new PaymentId from the
652
- // `pending_outbound_payments` map, as the user isn't expected to `abandon_payment`.
653
- let removed = self . pending_outbound_payments . lock ( ) . unwrap ( ) . remove ( & payment_id) . is_some ( ) ;
654
- debug_assert ! ( removed, "We should always have a pending payment to remove here" ) ;
655
668
Err ( PaymentSendFailure :: AllFailedResendSafe ( results. drain ( ..) . map ( |r| r. unwrap_err ( ) ) . collect ( ) ) )
656
669
} else {
657
670
Ok ( ( ) )
@@ -673,6 +686,19 @@ impl OutboundPayments {
673
686
self . send_payment_internal ( route, payment_hash, payment_secret, keysend_preimage, payment_id,
674
687
recv_value_msat, onion_session_privs, node_signer, best_block_height,
675
688
send_payment_along_path)
689
+ . map_err ( |e| { // TODO: use inspect_err instead when it's within MSRV
690
+ if let PaymentSendFailure :: AllFailedResendSafe ( _) = e {
691
+ self . all_failed_remove_outbound ( payment_id) ;
692
+ }
693
+ e
694
+ } )
695
+ }
696
+
697
+ // If we failed to send any paths, we should remove the new PaymentId from the
698
+ // `pending_outbound_payments` map, as the user isn't expected to `abandon_payment`.
699
+ fn all_failed_remove_outbound ( & self , payment_id : PaymentId ) {
700
+ let removed = self . pending_outbound_payments . lock ( ) . unwrap ( ) . remove ( & payment_id) . is_some ( ) ;
701
+ debug_assert ! ( removed, "We should always have a pending payment to remove here" ) ;
676
702
}
677
703
678
704
pub ( super ) fn claim_htlc < L : Deref > (
0 commit comments