@@ -505,10 +505,12 @@ impl OutboundPayments {
505
505
loop {
506
506
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
507
507
let mut retry_id_route_params = None ;
508
- for ( pmt_id, pmt) in outbounds. iter_mut ( ) {
509
- if pmt. is_auto_retryable_now ( ) {
510
- if let PendingOutboundPayment :: Retryable { pending_amt_msat, total_msat, payment_params : Some ( params) , .. } = pmt {
511
- if pending_amt_msat < total_msat {
508
+ outbounds. retain ( |pmt_id, pmt| {
509
+ let mut retain = true ;
510
+ let auto_retryable = pmt. is_auto_retryable_now ( ) ;
511
+ if let PendingOutboundPayment :: Retryable { pending_amt_msat, total_msat, payment_params : Some ( params) , .. } = pmt {
512
+ if pending_amt_msat < total_msat {
513
+ if auto_retryable {
512
514
retry_id_route_params = Some ( ( * pmt_id, RouteParameters {
513
515
final_value_msat : * total_msat - * pending_amt_msat,
514
516
final_cltv_expiry_delta :
@@ -517,13 +519,19 @@ impl OutboundPayments {
517
519
debug_assert ! ( false , "We always set the final_cltv_expiry_delta when a path fails" ) ;
518
520
LDK_DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA . into ( )
519
521
} ,
520
- payment_params : params. clone ( ) ,
522
+ payment_params : params. clone ( ) ,
521
523
} ) ) ;
522
- break
524
+ } else if pmt. mark_abandoned ( ) . is_ok ( ) && pmt. remaining_parts ( ) == 0 {
525
+ pending_events. lock ( ) . unwrap ( ) . push ( events:: Event :: PaymentFailed {
526
+ payment_id : * pmt_id,
527
+ payment_hash : pmt. payment_hash ( ) . expect ( "PendingOutboundPayments::RetriesExceeded always has a payment hash set" ) ,
528
+ } ) ;
529
+ retain = false ;
523
530
}
524
531
}
525
532
}
526
- }
533
+ retain
534
+ } ) ;
527
535
core:: mem:: drop ( outbounds) ;
528
536
if let Some ( ( payment_id, route_params) ) = retry_id_route_params {
529
537
if let Err ( e) = self . pay_internal ( payment_id, None , route_params, router, first_hops ( ) , inflight_htlcs ( ) , entropy_source, node_signer, best_block_height, logger, & send_payment_along_path) {
0 commit comments