@@ -378,6 +378,30 @@ impl OutboundPayments {
378
378
}
379
379
}
380
380
381
+ pub ( super ) fn send_payment < R : Deref , ES : Deref , NS : Deref , F > (
382
+ & self , payment_hash : PaymentHash , payment_secret : & Option < PaymentSecret > , payment_id : PaymentId ,
383
+ retry_strategy : Retry , route_params : RouteParameters , router : & R ,
384
+ first_hops : Vec < ChannelDetails > , inflight_htlcs : InFlightHtlcs , entropy_source : & ES ,
385
+ node_signer : & NS , best_block_height : u32 , send_payment_along_path : F
386
+ ) -> Result < ( ) , PaymentSendFailure >
387
+ where
388
+ R :: Target : Router ,
389
+ ES :: Target : EntropySource ,
390
+ NS :: Target : NodeSigner ,
391
+ F : Fn ( & Vec < RouteHop > , & Option < PaymentParameters > , & PaymentHash , & Option < PaymentSecret > , u64 ,
392
+ u32 , PaymentId , & Option < PaymentPreimage > , [ u8 ; 32 ] ) -> Result < ( ) , APIError > ,
393
+ {
394
+ self . pay_internal ( payment_id, Some ( ( payment_hash, payment_secret, retry_strategy) ) ,
395
+ route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer,
396
+ best_block_height, & send_payment_along_path)
397
+ . map_err ( |e| { // TODO: use inspect_err instead when it's within MSRV
398
+ if let PaymentSendFailure :: AllFailedResendSafe ( _) = e {
399
+ self . all_failed_remove_outbound ( payment_id) ;
400
+ }
401
+ e
402
+ } )
403
+ }
404
+
381
405
pub ( super ) fn send_payment_with_route < ES : Deref , NS : Deref , F > (
382
406
& self , route : & Route , payment_hash : PaymentHash , payment_secret : & Option < PaymentSecret > ,
383
407
payment_id : PaymentId , entropy_source : & ES , node_signer : & NS , best_block_height : u32 ,
@@ -391,7 +415,7 @@ impl OutboundPayments {
391
415
{
392
416
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) ?;
393
417
self . send_payment_internal ( route, payment_hash, payment_secret, None , payment_id, None ,
394
- onion_session_privs, node_signer, best_block_height, send_payment_along_path)
418
+ onion_session_privs, node_signer, best_block_height, & send_payment_along_path)
395
419
. map_err ( |e| { // TODO: use inspect_err instead when it's within MSRV
396
420
if let PaymentSendFailure :: AllFailedResendSafe ( _) = e {
397
421
self . all_failed_remove_outbound ( payment_id) ;
@@ -417,7 +441,7 @@ impl OutboundPayments {
417
441
let payment_hash = PaymentHash ( Sha256 :: hash ( & preimage. 0 ) . into_inner ( ) ) ;
418
442
let onion_session_privs = self . add_new_pending_payment ( payment_hash, None , payment_id, & route, Retry :: Attempts ( 0 ) , None , entropy_source, best_block_height) ?;
419
443
420
- 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) {
444
+ 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) {
421
445
Ok ( ( ) ) => Ok ( payment_hash) ,
422
446
Err ( e) => {
423
447
if let PaymentSendFailure :: AllFailedResendSafe ( _) = e {
@@ -457,17 +481,19 @@ impl OutboundPayments {
457
481
}
458
482
if let Some ( ( payment_id, route_params) ) = retry_id_route_params {
459
483
core:: mem:: drop ( outbounds) ;
460
- if let Err ( e) = self . pay_internal ( payment_id, route_params, router, first_hops ( ) , inflight_htlcs ( ) , entropy_source, node_signer, best_block_height, & send_payment_along_path) {
484
+ if let Err ( e) = self . pay_internal ( payment_id, None , route_params, router, first_hops ( ) , inflight_htlcs ( ) , entropy_source, node_signer, best_block_height, & send_payment_along_path) {
461
485
log_trace ! ( logger, "Errored retrying payment: {:?}" , e) ;
462
486
}
463
487
} else { break }
464
488
}
465
489
}
466
490
467
491
fn pay_internal < R : Deref , NS : Deref , ES : Deref , F > (
468
- & self , payment_id : PaymentId , route_params : RouteParameters , router : & R ,
469
- first_hops : Vec < ChannelDetails > , inflight_htlcs : InFlightHtlcs , entropy_source : & ES ,
470
- node_signer : & NS , best_block_height : u32 , send_payment_along_path : & F
492
+ & self , payment_id : PaymentId ,
493
+ initial_send_info : Option < ( PaymentHash , & Option < PaymentSecret > , Retry ) > ,
494
+ route_params : RouteParameters , router : & R , first_hops : Vec < ChannelDetails > ,
495
+ inflight_htlcs : InFlightHtlcs , entropy_source : & ES , node_signer : & NS , best_block_height : u32 ,
496
+ send_payment_along_path : & F
471
497
) -> Result < ( ) , PaymentSendFailure >
472
498
where
473
499
R :: Target : Router ,
@@ -491,7 +517,12 @@ impl OutboundPayments {
491
517
err : format ! ( "Failed to find a route for payment {}: {:?}" , log_bytes!( payment_id. 0 ) , e) , // TODO: add APIError::RouteNotFound
492
518
} ) ) ?;
493
519
494
- let res = self . retry_payment_with_route ( & route, payment_id, entropy_source, node_signer, best_block_height, send_payment_along_path) ;
520
+ let res = if let Some ( ( payment_hash, payment_secret, retry_strategy) ) = initial_send_info {
521
+ let onion_session_privs = self . add_new_pending_payment ( payment_hash, * payment_secret, payment_id, & route, retry_strategy, Some ( route_params. clone ( ) ) , entropy_source, best_block_height) ?;
522
+ 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)
523
+ } else {
524
+ self . retry_payment_with_route ( & route, payment_id, entropy_source, node_signer, best_block_height, send_payment_along_path)
525
+ } ;
495
526
match res {
496
527
Err ( PaymentSendFailure :: AllFailedResendSafe ( _) ) | Err ( PaymentSendFailure :: PartialFailure { .. } ) => {
497
528
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
@@ -506,14 +537,14 @@ impl OutboundPayments {
506
537
}
507
538
match res {
508
539
Err ( PaymentSendFailure :: AllFailedResendSafe ( _) ) => {
509
- self . pay_internal ( payment_id, route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, send_payment_along_path)
540
+ self . pay_internal ( payment_id, None , route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, send_payment_along_path)
510
541
} ,
511
542
Err ( PaymentSendFailure :: PartialFailure { failed_paths_retry, .. } ) => {
512
543
if let Some ( retry) = failed_paths_retry {
513
544
// Some paths were sent, even if we failed to send the full MPP value our recipient may
514
545
// misbehave and claim the funds, at which point we have to consider the payment sent, so
515
546
// return `Ok()` here, ignoring any retry errors.
516
- let _ = self . pay_internal ( payment_id, retry, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, send_payment_along_path) ;
547
+ let _ = self . pay_internal ( payment_id, None , retry, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, send_payment_along_path) ;
517
548
Ok ( ( ) )
518
549
} else {
519
550
// This may happen if we send a payment and some paths fail, but only due to a temporary
@@ -593,7 +624,7 @@ impl OutboundPayments {
593
624
} ) ) ,
594
625
}
595
626
} ;
596
- self . send_payment_internal ( route, payment_hash, & payment_secret, None , payment_id, Some ( total_msat) , onion_session_privs, node_signer, best_block_height, send_payment_along_path)
627
+ self . send_payment_internal ( route, payment_hash, & payment_secret, None , payment_id, Some ( total_msat) , onion_session_privs, node_signer, best_block_height, & send_payment_along_path)
597
628
}
598
629
599
630
pub ( super ) fn send_probe < ES : Deref , NS : Deref , F > (
@@ -619,7 +650,7 @@ impl OutboundPayments {
619
650
let route = Route { paths : vec ! [ hops] , payment_params : None } ;
620
651
let onion_session_privs = self . add_new_pending_payment ( payment_hash, None , payment_id, & route, Retry :: Attempts ( 0 ) , None , entropy_source, best_block_height) ?;
621
652
622
- 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) {
653
+ 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) {
623
654
Ok ( ( ) ) => Ok ( ( payment_hash, payment_id) ) ,
624
655
Err ( e) => {
625
656
if let PaymentSendFailure :: AllFailedResendSafe ( _) = e {
@@ -678,7 +709,7 @@ impl OutboundPayments {
678
709
& self , route : & Route , payment_hash : PaymentHash , payment_secret : & Option < PaymentSecret > ,
679
710
keysend_preimage : Option < PaymentPreimage > , payment_id : PaymentId , recv_value_msat : Option < u64 > ,
680
711
onion_session_privs : Vec < [ u8 ; 32 ] > , node_signer : & NS , best_block_height : u32 ,
681
- send_payment_along_path : F
712
+ send_payment_along_path : & F
682
713
) -> Result < ( ) , PaymentSendFailure >
683
714
where
684
715
NS :: Target : NodeSigner ,
@@ -793,7 +824,7 @@ impl OutboundPayments {
793
824
{
794
825
self . send_payment_internal ( route, payment_hash, payment_secret, keysend_preimage, payment_id,
795
826
recv_value_msat, onion_session_privs, node_signer, best_block_height,
796
- send_payment_along_path)
827
+ & send_payment_along_path)
797
828
. map_err ( |e| { // TODO: use inspect_err instead when it's within MSRV
798
829
if let PaymentSendFailure :: AllFailedResendSafe ( _) = e {
799
830
self . all_failed_remove_outbound ( payment_id) ;
0 commit comments