@@ -473,6 +473,18 @@ impl RecipientOnionFields {
473
473
}
474
474
}
475
475
476
+ /// Arguments for [`super::channelmanager::ChannelManager::send_payment_along_path`].
477
+ pub ( super ) struct SendAlongPathArgs < ' a > {
478
+ pub path : & ' a Path ,
479
+ pub payment_hash : & ' a PaymentHash ,
480
+ pub recipient_onion : RecipientOnionFields ,
481
+ pub total_value : u64 ,
482
+ pub cur_height : u32 ,
483
+ pub payment_id : PaymentId ,
484
+ pub keysend_preimage : & ' a Option < PaymentPreimage > ,
485
+ pub session_priv_bytes : [ u8 ; 32 ] ,
486
+ }
487
+
476
488
pub ( super ) struct OutboundPayments {
477
489
pub ( super ) pending_outbound_payments : Mutex < HashMap < PaymentId , PendingOutboundPayment > > ,
478
490
pub ( super ) retry_lock : Mutex < ( ) > ,
@@ -499,8 +511,7 @@ impl OutboundPayments {
499
511
NS :: Target : NodeSigner ,
500
512
L :: Target : Logger ,
501
513
IH : Fn ( ) -> InFlightHtlcs ,
502
- SP : Fn ( & Path , & PaymentHash , RecipientOnionFields , u64 , u32 , PaymentId ,
503
- & Option < PaymentPreimage > , [ u8 ; 32 ] ) -> Result < ( ) , APIError > ,
514
+ SP : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError > ,
504
515
{
505
516
self . send_payment_internal ( payment_id, payment_hash, recipient_onion, None , retry_strategy,
506
517
route_params, router, first_hops, & compute_inflight_htlcs, entropy_source, node_signer,
@@ -515,8 +526,7 @@ impl OutboundPayments {
515
526
where
516
527
ES :: Target : EntropySource ,
517
528
NS :: Target : NodeSigner ,
518
- F : Fn ( & Path , & PaymentHash , RecipientOnionFields , u64 , u32 , PaymentId ,
519
- & Option < PaymentPreimage > , [ u8 ; 32 ] ) -> Result < ( ) , APIError >
529
+ F : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError >
520
530
{
521
531
let onion_session_privs = self . add_new_pending_payment ( payment_hash, recipient_onion. clone ( ) , payment_id, None , route, None , None , entropy_source, best_block_height) ?;
522
532
self . pay_route_internal ( route, payment_hash, recipient_onion, None , payment_id, None ,
@@ -537,8 +547,7 @@ impl OutboundPayments {
537
547
NS :: Target : NodeSigner ,
538
548
L :: Target : Logger ,
539
549
IH : Fn ( ) -> InFlightHtlcs ,
540
- SP : Fn ( & Path , & PaymentHash , RecipientOnionFields , u64 , u32 , PaymentId ,
541
- & Option < PaymentPreimage > , [ u8 ; 32 ] ) -> Result < ( ) , APIError > ,
550
+ SP : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError > ,
542
551
{
543
552
let preimage = payment_preimage
544
553
. unwrap_or_else ( || PaymentPreimage ( entropy_source. get_secure_random_bytes ( ) ) ) ;
@@ -557,8 +566,7 @@ impl OutboundPayments {
557
566
where
558
567
ES :: Target : EntropySource ,
559
568
NS :: Target : NodeSigner ,
560
- F : Fn ( & Path , & PaymentHash , RecipientOnionFields , u64 , u32 , PaymentId ,
561
- & Option < PaymentPreimage > , [ u8 ; 32 ] ) -> Result < ( ) , APIError >
569
+ F : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError > ,
562
570
{
563
571
let preimage = payment_preimage
564
572
. unwrap_or_else ( || PaymentPreimage ( entropy_source. get_secure_random_bytes ( ) ) ) ;
@@ -587,8 +595,7 @@ impl OutboundPayments {
587
595
R :: Target : Router ,
588
596
ES :: Target : EntropySource ,
589
597
NS :: Target : NodeSigner ,
590
- SP : Fn ( & Path , & PaymentHash , RecipientOnionFields , u64 , u32 , PaymentId ,
591
- & Option < PaymentPreimage > , [ u8 ; 32 ] ) -> Result < ( ) , APIError > ,
598
+ SP : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError > ,
592
599
IH : Fn ( ) -> InFlightHtlcs ,
593
600
FH : Fn ( ) -> Vec < ChannelDetails > ,
594
601
L :: Target : Logger ,
@@ -658,8 +665,7 @@ impl OutboundPayments {
658
665
NS :: Target : NodeSigner ,
659
666
L :: Target : Logger ,
660
667
IH : Fn ( ) -> InFlightHtlcs ,
661
- SP : Fn ( & Path , & PaymentHash , RecipientOnionFields , u64 , u32 , PaymentId ,
662
- & Option < PaymentPreimage > , [ u8 ; 32 ] ) -> Result < ( ) , APIError >
668
+ SP : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError > ,
663
669
{
664
670
#[ cfg( feature = "std" ) ] {
665
671
if has_expired ( & route_params) {
@@ -699,8 +705,7 @@ impl OutboundPayments {
699
705
NS :: Target : NodeSigner ,
700
706
L :: Target : Logger ,
701
707
IH : Fn ( ) -> InFlightHtlcs ,
702
- SP : Fn ( & Path , & PaymentHash , RecipientOnionFields , u64 , u32 , PaymentId ,
703
- & Option < PaymentPreimage > , [ u8 ; 32 ] ) -> Result < ( ) , APIError >
708
+ SP : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError > ,
704
709
{
705
710
#[ cfg( feature = "std" ) ] {
706
711
if has_expired ( & route_params) {
@@ -821,8 +826,7 @@ impl OutboundPayments {
821
826
NS :: Target : NodeSigner ,
822
827
L :: Target : Logger ,
823
828
IH : Fn ( ) -> InFlightHtlcs ,
824
- SP : Fn ( & Path , & PaymentHash , RecipientOnionFields , u64 , u32 , PaymentId ,
825
- & Option < PaymentPreimage > , [ u8 ; 32 ] ) -> Result < ( ) , APIError >
829
+ SP : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError > ,
826
830
{
827
831
match err {
828
832
PaymentSendFailure :: AllFailedResendSafe ( errs) => {
@@ -894,8 +898,7 @@ impl OutboundPayments {
894
898
where
895
899
ES :: Target : EntropySource ,
896
900
NS :: Target : NodeSigner ,
897
- F : Fn ( & Path , & PaymentHash , RecipientOnionFields , u64 , u32 , PaymentId ,
898
- & Option < PaymentPreimage > , [ u8 ; 32 ] ) -> Result < ( ) , APIError >
901
+ F : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError > ,
899
902
{
900
903
let payment_id = PaymentId ( entropy_source. get_secure_random_bytes ( ) ) ;
901
904
@@ -989,8 +992,7 @@ impl OutboundPayments {
989
992
) -> Result < ( ) , PaymentSendFailure >
990
993
where
991
994
NS :: Target : NodeSigner ,
992
- F : Fn ( & Path , & PaymentHash , RecipientOnionFields , u64 , u32 , PaymentId ,
993
- & Option < PaymentPreimage > , [ u8 ; 32 ] ) -> Result < ( ) , APIError >
995
+ F : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError > ,
994
996
{
995
997
if route. paths . len ( ) < 1 {
996
998
return Err ( PaymentSendFailure :: ParameterError ( APIError :: InvalidRoute { err : "There must be at least one path to send over" . to_owned ( ) } ) ) ;
@@ -1031,9 +1033,11 @@ impl OutboundPayments {
1031
1033
let cur_height = best_block_height + 1 ;
1032
1034
let mut results = Vec :: new ( ) ;
1033
1035
debug_assert_eq ! ( route. paths. len( ) , onion_session_privs. len( ) ) ;
1034
- for ( path, session_priv) in route. paths . iter ( ) . zip ( onion_session_privs. into_iter ( ) ) {
1035
- let mut path_res = send_payment_along_path ( & path, & payment_hash, recipient_onion. clone ( ) ,
1036
- total_value, cur_height, payment_id, & keysend_preimage, session_priv) ;
1036
+ for ( path, session_priv_bytes) in route. paths . iter ( ) . zip ( onion_session_privs. into_iter ( ) ) {
1037
+ let mut path_res = send_payment_along_path ( SendAlongPathArgs {
1038
+ path : & path, payment_hash : & payment_hash, recipient_onion : recipient_onion. clone ( ) ,
1039
+ total_value, cur_height, payment_id, keysend_preimage : & keysend_preimage, session_priv_bytes
1040
+ } ) ;
1037
1041
match path_res {
1038
1042
Ok ( _) => { } ,
1039
1043
Err ( APIError :: MonitorUpdateInProgress ) => {
@@ -1044,7 +1048,7 @@ impl OutboundPayments {
1044
1048
Err ( _) => {
1045
1049
let mut pending_outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1046
1050
if let Some ( payment) = pending_outbounds. get_mut ( & payment_id) {
1047
- let removed = payment. remove ( & session_priv , Some ( path) ) ;
1051
+ let removed = payment. remove ( & session_priv_bytes , Some ( path) ) ;
1048
1052
debug_assert ! ( removed, "This can't happen as the payment has an entry for this path added by callers" ) ;
1049
1053
} else {
1050
1054
debug_assert ! ( false , "This can't happen as the payment was added by callers" ) ;
@@ -1098,8 +1102,7 @@ impl OutboundPayments {
1098
1102
) -> Result < ( ) , PaymentSendFailure >
1099
1103
where
1100
1104
NS :: Target : NodeSigner ,
1101
- F : Fn ( & Path , & PaymentHash , RecipientOnionFields , u64 , u32 , PaymentId ,
1102
- & Option < PaymentPreimage > , [ u8 ; 32 ] ) -> Result < ( ) , APIError >
1105
+ F : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError > ,
1103
1106
{
1104
1107
self . pay_route_internal ( route, payment_hash, recipient_onion, keysend_preimage, payment_id,
1105
1108
recv_value_msat, onion_session_privs, node_signer, best_block_height,
@@ -1480,8 +1483,8 @@ mod tests {
1480
1483
& & keys_manager, 0 ) . unwrap ( ) ;
1481
1484
outbound_payments. retry_payment_internal (
1482
1485
PaymentHash ( [ 0 ; 32 ] ) , PaymentId ( [ 0 ; 32 ] ) , expired_route_params, & & router, vec ! [ ] ,
1483
- & || InFlightHtlcs :: new ( ) , & & keys_manager, & & keys_manager, 0 , & & logger,
1484
- & pending_events , & |_ , _ , _ , _ , _ , _ , _ , _| Ok ( ( ) ) ) ;
1486
+ & || InFlightHtlcs :: new ( ) , & & keys_manager, & & keys_manager, 0 , & & logger, & pending_events ,
1487
+ & | _| Ok ( ( ) ) ) ;
1485
1488
let events = pending_events. lock ( ) . unwrap ( ) ;
1486
1489
assert_eq ! ( events. len( ) , 1 ) ;
1487
1490
if let Event :: PaymentFailed { ref reason, .. } = events[ 0 ] . 0 {
@@ -1491,8 +1494,7 @@ mod tests {
1491
1494
let err = outbound_payments. send_payment (
1492
1495
PaymentHash ( [ 0 ; 32 ] ) , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1493
1496
Retry :: Attempts ( 0 ) , expired_route_params, & & router, vec ! [ ] , || InFlightHtlcs :: new ( ) ,
1494
- & & keys_manager, & & keys_manager, 0 , & & logger,
1495
- & pending_events, |_, _, _, _, _, _, _, _| Ok ( ( ) ) ) . unwrap_err ( ) ;
1497
+ & & keys_manager, & & keys_manager, 0 , & & logger, & pending_events, |_| Ok ( ( ) ) ) . unwrap_err ( ) ;
1496
1498
if let RetryableSendFailure :: PaymentExpired = err { } else { panic ! ( "Unexpected error" ) ; }
1497
1499
}
1498
1500
}
@@ -1528,17 +1530,16 @@ mod tests {
1528
1530
& & keys_manager, 0 ) . unwrap ( ) ;
1529
1531
outbound_payments. retry_payment_internal (
1530
1532
PaymentHash ( [ 0 ; 32 ] ) , PaymentId ( [ 0 ; 32 ] ) , route_params, & & router, vec ! [ ] ,
1531
- & || InFlightHtlcs :: new ( ) , & & keys_manager, & & keys_manager, 0 , & & logger,
1532
- & pending_events , & |_ , _ , _ , _ , _ , _ , _ , _| Ok ( ( ) ) ) ;
1533
+ & || InFlightHtlcs :: new ( ) , & & keys_manager, & & keys_manager, 0 , & & logger, & pending_events ,
1534
+ & | _| Ok ( ( ) ) ) ;
1533
1535
let events = pending_events. lock ( ) . unwrap ( ) ;
1534
1536
assert_eq ! ( events. len( ) , 1 ) ;
1535
1537
if let Event :: PaymentFailed { .. } = events[ 0 ] . 0 { } else { panic ! ( "Unexpected event" ) ; }
1536
1538
} else {
1537
1539
let err = outbound_payments. send_payment (
1538
1540
PaymentHash ( [ 0 ; 32 ] ) , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1539
1541
Retry :: Attempts ( 0 ) , route_params, & & router, vec ! [ ] , || InFlightHtlcs :: new ( ) ,
1540
- & & keys_manager, & & keys_manager, 0 , & & logger,
1541
- & pending_events, |_, _, _, _, _, _, _, _| Ok ( ( ) ) ) . unwrap_err ( ) ;
1542
+ & & keys_manager, & & keys_manager, 0 , & & logger, & pending_events, |_| Ok ( ( ) ) ) . unwrap_err ( ) ;
1542
1543
if let RetryableSendFailure :: RouteNotFound = err {
1543
1544
} else { panic ! ( "Unexpected error" ) ; }
1544
1545
}
@@ -1587,8 +1588,7 @@ mod tests {
1587
1588
PaymentHash ( [ 0 ; 32 ] ) , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1588
1589
Retry :: Attempts ( 0 ) , route_params. clone ( ) , & & router, vec ! [ ] , || InFlightHtlcs :: new ( ) ,
1589
1590
& & keys_manager, & & keys_manager, 0 , & & logger, & pending_events,
1590
- |_, _, _, _, _, _, _, _| Err ( APIError :: ChannelUnavailable { err : "test" . to_owned ( ) } ) )
1591
- . unwrap ( ) ;
1591
+ |_| Err ( APIError :: ChannelUnavailable { err : "test" . to_owned ( ) } ) ) . unwrap ( ) ;
1592
1592
let mut events = pending_events. lock ( ) . unwrap ( ) ;
1593
1593
assert_eq ! ( events. len( ) , 2 ) ;
1594
1594
if let Event :: PaymentPathFailed {
@@ -1606,16 +1606,15 @@ mod tests {
1606
1606
PaymentHash ( [ 0 ; 32 ] ) , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1607
1607
Retry :: Attempts ( 0 ) , route_params. clone ( ) , & & router, vec ! [ ] , || InFlightHtlcs :: new ( ) ,
1608
1608
& & keys_manager, & & keys_manager, 0 , & & logger, & pending_events,
1609
- |_, _ , _ , _ , _ , _ , _ , _ | Err ( APIError :: MonitorUpdateInProgress ) ) . unwrap ( ) ;
1609
+ |_| Err ( APIError :: MonitorUpdateInProgress ) ) . unwrap ( ) ;
1610
1610
assert_eq ! ( pending_events. lock( ) . unwrap( ) . len( ) , 0 ) ;
1611
1611
1612
1612
// Ensure that any other error will result in a PaymentPathFailed event but no blamed scid.
1613
1613
outbound_payments. send_payment (
1614
1614
PaymentHash ( [ 0 ; 32 ] ) , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 1 ; 32 ] ) ,
1615
1615
Retry :: Attempts ( 0 ) , route_params. clone ( ) , & & router, vec ! [ ] , || InFlightHtlcs :: new ( ) ,
1616
1616
& & keys_manager, & & keys_manager, 0 , & & logger, & pending_events,
1617
- |_, _, _, _, _, _, _, _| Err ( APIError :: APIMisuseError { err : "test" . to_owned ( ) } ) )
1618
- . unwrap ( ) ;
1617
+ |_| Err ( APIError :: APIMisuseError { err : "test" . to_owned ( ) } ) ) . unwrap ( ) ;
1619
1618
let events = pending_events. lock ( ) . unwrap ( ) ;
1620
1619
assert_eq ! ( events. len( ) , 2 ) ;
1621
1620
if let Event :: PaymentPathFailed {
0 commit comments