@@ -231,7 +231,7 @@ pub enum Retry {
231
231
///
232
232
/// Each attempt may be multiple HTLCs along multiple paths if the router decides to split up a
233
233
/// retry, and may retry multiple failed HTLCs at once if they failed around the same time and
234
- /// were retried along a route from a single call to [`Router::find_route `].
234
+ /// were retried along a route from a single call to [`Router::find_route_with_id `].
235
235
Attempts ( usize ) ,
236
236
#[ cfg( not( feature = "no-std" ) ) ]
237
237
/// Time elapsed before abandoning retries for a payment. At least one attempt at payment is made;
@@ -531,9 +531,9 @@ impl OutboundPayments {
531
531
let mut retry_id_route_params = None ;
532
532
for ( pmt_id, pmt) in outbounds. iter_mut ( ) {
533
533
if pmt. is_auto_retryable_now ( ) {
534
- if let PendingOutboundPayment :: Retryable { pending_amt_msat, total_msat, payment_params : Some ( params) , .. } = pmt {
534
+ if let PendingOutboundPayment :: Retryable { pending_amt_msat, total_msat, payment_params : Some ( params) , payment_hash , .. } = pmt {
535
535
if pending_amt_msat < total_msat {
536
- retry_id_route_params = Some ( ( * pmt_id, RouteParameters {
536
+ retry_id_route_params = Some ( ( * payment_hash , * pmt_id, RouteParameters {
537
537
final_value_msat : * total_msat - * pending_amt_msat,
538
538
payment_params : params. clone ( ) ,
539
539
} ) ) ;
@@ -543,8 +543,8 @@ impl OutboundPayments {
543
543
}
544
544
}
545
545
core:: mem:: drop ( outbounds) ;
546
- if let Some ( ( payment_id, route_params) ) = retry_id_route_params {
547
- self . retry_payment_internal ( payment_id, route_params, router, first_hops ( ) , & inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, & send_payment_along_path)
546
+ if let Some ( ( payment_hash , payment_id, route_params) ) = retry_id_route_params {
547
+ self . retry_payment_internal ( payment_hash , payment_id, route_params, router, first_hops ( ) , & inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, & send_payment_along_path)
548
548
} else { break }
549
549
}
550
550
@@ -597,9 +597,10 @@ impl OutboundPayments {
597
597
}
598
598
}
599
599
600
- let route = router. find_route (
600
+ let route = router. find_route_with_id (
601
601
& node_signer. get_node_id ( Recipient :: Node ) . unwrap ( ) , & route_params,
602
- Some ( & first_hops. iter ( ) . collect :: < Vec < _ > > ( ) ) , & inflight_htlcs ( )
602
+ Some ( & first_hops. iter ( ) . collect :: < Vec < _ > > ( ) ) , & inflight_htlcs ( ) ,
603
+ payment_hash, payment_id,
603
604
) . map_err ( |_| RetryableSendFailure :: RouteNotFound ) ?;
604
605
605
606
let onion_session_privs = self . add_new_pending_payment ( payment_hash, * payment_secret,
@@ -617,10 +618,10 @@ impl OutboundPayments {
617
618
}
618
619
619
620
fn retry_payment_internal < R : Deref , NS : Deref , ES : Deref , IH , SP , L : Deref > (
620
- & self , payment_id : PaymentId , route_params : RouteParameters , router : & R ,
621
- first_hops : Vec < ChannelDetails > , inflight_htlcs : & IH , entropy_source : & ES , node_signer : & NS ,
622
- best_block_height : u32 , logger : & L , pending_events : & Mutex < Vec < events :: Event > > ,
623
- send_payment_along_path : & SP ,
621
+ & self , payment_hash : PaymentHash , payment_id : PaymentId , route_params : RouteParameters ,
622
+ router : & R , first_hops : Vec < ChannelDetails > , inflight_htlcs : & IH , entropy_source : & ES ,
623
+ node_signer : & NS , best_block_height : u32 , logger : & L ,
624
+ pending_events : & Mutex < Vec < events :: Event > > , send_payment_along_path : & SP ,
624
625
)
625
626
where
626
627
R :: Target : Router ,
@@ -639,9 +640,10 @@ impl OutboundPayments {
639
640
}
640
641
}
641
642
642
- let route = match router. find_route (
643
+ let route = match router. find_route_with_id (
643
644
& node_signer. get_node_id ( Recipient :: Node ) . unwrap ( ) , & route_params,
644
- Some ( & first_hops. iter ( ) . collect :: < Vec < _ > > ( ) ) , & inflight_htlcs ( )
645
+ Some ( & first_hops. iter ( ) . collect :: < Vec < _ > > ( ) ) , & inflight_htlcs ( ) ,
646
+ payment_hash, payment_id,
645
647
) {
646
648
Ok ( route) => route,
647
649
Err ( e) => {
@@ -665,32 +667,31 @@ impl OutboundPayments {
665
667
}
666
668
667
669
macro_rules! abandon_with_entry {
668
- ( $payment_id : expr , $payment_hash : expr , $ payment: expr , $pending_events : expr) => {
670
+ ( $payment: expr) => {
669
671
if $payment. get_mut( ) . mark_abandoned( ) . is_ok( ) && $payment. get( ) . remaining_parts( ) == 0 {
670
- $ pending_events. lock( ) . unwrap( ) . push( events:: Event :: PaymentFailed {
671
- payment_id: $payment_id ,
672
- payment_hash: $payment_hash ,
672
+ pending_events. lock( ) . unwrap( ) . push( events:: Event :: PaymentFailed {
673
+ payment_id,
674
+ payment_hash,
673
675
} ) ;
674
676
$payment. remove( ) ;
675
677
}
676
678
}
677
679
}
678
- let ( total_msat, payment_hash , payment_secret, keysend_preimage) = {
680
+ let ( total_msat, payment_secret, keysend_preimage) = {
679
681
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
680
682
match outbounds. entry ( payment_id) {
681
683
hash_map:: Entry :: Occupied ( mut payment) => {
682
684
let res = match payment. get ( ) {
683
685
PendingOutboundPayment :: Retryable {
684
- total_msat, payment_hash , keysend_preimage, payment_secret, pending_amt_msat, ..
686
+ total_msat, keysend_preimage, payment_secret, pending_amt_msat, ..
685
687
} => {
686
688
let retry_amt_msat: u64 = route. paths . iter ( ) . map ( |path| path. last ( ) . unwrap ( ) . fee_msat ) . sum ( ) ;
687
689
if retry_amt_msat + * pending_amt_msat > * total_msat * ( 100 + RETRY_OVERFLOW_PERCENTAGE ) / 100 {
688
690
log_error ! ( logger, "retry_amt_msat of {} will put pending_amt_msat (currently: {}) more than 10% over total_payment_amt_msat of {}" , retry_amt_msat, pending_amt_msat, total_msat) ;
689
- let payment_hash = * payment_hash;
690
- abandon_with_entry ! ( payment_id, payment_hash, payment, pending_events) ;
691
+ abandon_with_entry ! ( payment) ;
691
692
return
692
693
}
693
- ( * total_msat, * payment_hash , * payment_secret, * keysend_preimage)
694
+ ( * total_msat, * payment_secret, * keysend_preimage)
694
695
} ,
695
696
PendingOutboundPayment :: Legacy { .. } => {
696
697
log_error ! ( logger, "Unable to retry payments that were initially sent on LDK versions prior to 0.0.102" ) ;
@@ -707,7 +708,7 @@ impl OutboundPayments {
707
708
} ;
708
709
if !payment. get ( ) . is_retryable_now ( ) {
709
710
log_error ! ( logger, "Retries exhausted for payment id {}" , log_bytes!( payment_id. 0 ) ) ;
710
- abandon_with_entry ! ( payment_id , res . 1 , payment, pending_events ) ;
711
+ abandon_with_entry ! ( payment) ;
711
712
return
712
713
}
713
714
payment. get_mut ( ) . increment_attempts ( ) ;
@@ -749,14 +750,14 @@ impl OutboundPayments {
749
750
match err {
750
751
PaymentSendFailure :: AllFailedResendSafe ( errs) => {
751
752
Self :: push_path_failed_evs_and_scids ( payment_id, payment_hash, & mut route_params, route. paths , errs. into_iter ( ) . map ( |e| Err ( e) ) , pending_events) ;
752
- self . retry_payment_internal ( payment_id, route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, send_payment_along_path) ;
753
+ self . retry_payment_internal ( payment_hash , payment_id, route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, send_payment_along_path) ;
753
754
} ,
754
755
PaymentSendFailure :: PartialFailure { failed_paths_retry : Some ( mut retry) , results, .. } => {
755
756
Self :: push_path_failed_evs_and_scids ( payment_id, payment_hash, & mut retry, route. paths , results. into_iter ( ) , pending_events) ;
756
757
// Some paths were sent, even if we failed to send the full MPP value our recipient may
757
758
// misbehave and claim the funds, at which point we have to consider the payment sent, so
758
759
// return `Ok()` here, ignoring any retry errors.
759
- self . retry_payment_internal ( payment_id, retry, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, send_payment_along_path) ;
760
+ self . retry_payment_internal ( payment_hash , payment_id, retry, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, send_payment_along_path) ;
760
761
} ,
761
762
PaymentSendFailure :: PartialFailure { failed_paths_retry : None , .. } => {
762
763
// This may happen if we send a payment and some paths fail, but only due to a temporary
@@ -1384,9 +1385,9 @@ mod tests {
1384
1385
& Route { paths : vec ! [ ] , payment_params : None } , Some ( Retry :: Attempts ( 1 ) ) ,
1385
1386
Some ( expired_route_params. payment_params . clone ( ) ) , & & keys_manager, 0 ) . unwrap ( ) ;
1386
1387
outbound_payments. retry_payment_internal (
1387
- PaymentId ( [ 0 ; 32 ] ) , expired_route_params, & & router, vec ! [ ] , & || InFlightHtlcs :: new ( ) ,
1388
- & & keys_manager, & & keys_manager, 0 , & & logger, & pending_events ,
1389
- & |_, _, _, _, _, _, _, _, _| Ok ( ( ) ) ) ;
1388
+ PaymentHash ( [ 0 ; 32 ] ) , PaymentId ( [ 0 ; 32 ] ) , expired_route_params, & & router, vec ! [ ] ,
1389
+ & || InFlightHtlcs :: new ( ) , & & keys_manager, & & keys_manager, 0 , & & logger,
1390
+ & pending_events , & |_, _, _, _, _, _, _, _, _| Ok ( ( ) ) ) ;
1390
1391
let events = pending_events. lock ( ) . unwrap ( ) ;
1391
1392
assert_eq ! ( events. len( ) , 1 ) ;
1392
1393
if let Event :: PaymentFailed { .. } = events[ 0 ] { } else { panic ! ( "Unexpected event" ) ; }
@@ -1428,9 +1429,9 @@ mod tests {
1428
1429
& Route { paths : vec ! [ ] , payment_params : None } , Some ( Retry :: Attempts ( 1 ) ) ,
1429
1430
Some ( route_params. payment_params . clone ( ) ) , & & keys_manager, 0 ) . unwrap ( ) ;
1430
1431
outbound_payments. retry_payment_internal (
1431
- PaymentId ( [ 0 ; 32 ] ) , route_params, & & router, vec ! [ ] , & || InFlightHtlcs :: new ( ) ,
1432
- & & keys_manager, & & keys_manager, 0 , & & logger, & pending_events ,
1433
- & |_, _, _, _, _, _, _, _, _| Ok ( ( ) ) ) ;
1432
+ PaymentHash ( [ 0 ; 32 ] ) , PaymentId ( [ 0 ; 32 ] ) , route_params, & & router, vec ! [ ] ,
1433
+ & || InFlightHtlcs :: new ( ) , & & keys_manager, & & keys_manager, 0 , & & logger,
1434
+ & pending_events , & |_, _, _, _, _, _, _, _, _| Ok ( ( ) ) ) ;
1434
1435
let events = pending_events. lock ( ) . unwrap ( ) ;
1435
1436
assert_eq ! ( events. len( ) , 1 ) ;
1436
1437
if let Event :: PaymentFailed { .. } = events[ 0 ] { } else { panic ! ( "Unexpected event" ) ; }
0 commit comments