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