@@ -505,10 +505,12 @@ impl OutboundPayments {
505505 loop {
506506 let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
507507 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 {
512514 retry_id_route_params = Some ( ( * pmt_id, RouteParameters {
513515 final_value_msat : * total_msat - * pending_amt_msat,
514516 final_cltv_expiry_delta :
@@ -517,13 +519,19 @@ impl OutboundPayments {
517519 debug_assert ! ( false , "We always set the final_cltv_expiry_delta when a path fails" ) ;
518520 LDK_DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA . into ( )
519521 } ,
520- payment_params : params. clone ( ) ,
522+ payment_params : params. clone ( ) ,
521523 } ) ) ;
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 ;
523530 }
524531 }
525532 }
526- }
533+ retain
534+ } ) ;
527535 core:: mem:: drop ( outbounds) ;
528536 if let Some ( ( payment_id, route_params) ) = retry_id_route_params {
529537 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