@@ -378,6 +378,25 @@ 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| { self . remove_outbound_if_all_failed ( payment_id, & e) ; e } )
398
+ }
399
+
381
400
pub ( super ) fn send_payment_with_route < ES : Deref , NS : Deref , F > (
382
401
& self , route : & Route , payment_hash : PaymentHash , payment_secret : & Option < PaymentSecret > ,
383
402
payment_id : PaymentId , entropy_source : & ES , node_signer : & NS , best_block_height : u32 ,
@@ -391,7 +410,7 @@ impl OutboundPayments {
391
410
{
392
411
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
412
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)
413
+ onion_session_privs, node_signer, best_block_height, & send_payment_along_path)
395
414
. map_err ( |e| { self . remove_outbound_if_all_failed ( payment_id, & e) ; e } )
396
415
}
397
416
@@ -412,7 +431,7 @@ impl OutboundPayments {
412
431
let payment_hash = PaymentHash ( Sha256 :: hash ( & preimage. 0 ) . into_inner ( ) ) ;
413
432
let onion_session_privs = self . add_new_pending_payment ( payment_hash, None , payment_id, & route, Retry :: Attempts ( 0 ) , None , entropy_source, best_block_height) ?;
414
433
415
- 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) {
434
+ 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) {
416
435
Ok ( ( ) ) => Ok ( payment_hash) ,
417
436
Err ( e) => {
418
437
self . remove_outbound_if_all_failed ( payment_id, & e) ;
@@ -450,17 +469,19 @@ impl OutboundPayments {
450
469
}
451
470
if let Some ( ( payment_id, route_params) ) = retry_id_route_params {
452
471
core:: mem:: drop ( outbounds) ;
453
- 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) {
472
+ 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) {
454
473
log_trace ! ( logger, "Errored retrying payment: {:?}" , e) ;
455
474
}
456
475
} else { break }
457
476
}
458
477
}
459
478
460
479
fn pay_internal < R : Deref , NS : Deref , ES : Deref , F > (
461
- & self , payment_id : PaymentId , route_params : RouteParameters , router : & R ,
462
- first_hops : Vec < ChannelDetails > , inflight_htlcs : InFlightHtlcs , entropy_source : & ES ,
463
- node_signer : & NS , best_block_height : u32 , send_payment_along_path : & F
480
+ & self , payment_id : PaymentId ,
481
+ initial_send_info : Option < ( PaymentHash , & Option < PaymentSecret > , Retry ) > ,
482
+ route_params : RouteParameters , router : & R , first_hops : Vec < ChannelDetails > ,
483
+ inflight_htlcs : InFlightHtlcs , entropy_source : & ES , node_signer : & NS , best_block_height : u32 ,
484
+ send_payment_along_path : & F
464
485
) -> Result < ( ) , PaymentSendFailure >
465
486
where
466
487
R :: Target : Router ,
@@ -484,7 +505,12 @@ impl OutboundPayments {
484
505
err : format ! ( "Failed to find a route for payment {}: {:?}" , log_bytes!( payment_id. 0 ) , e) , // TODO: add APIError::RouteNotFound
485
506
} ) ) ?;
486
507
487
- let res = self . retry_payment_with_route ( & route, payment_id, entropy_source, node_signer, best_block_height, send_payment_along_path) ;
508
+ let res = if let Some ( ( payment_hash, payment_secret, retry_strategy) ) = initial_send_info {
509
+ 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) ?;
510
+ 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)
511
+ } else {
512
+ self . retry_payment_with_route ( & route, payment_id, entropy_source, node_signer, best_block_height, send_payment_along_path)
513
+ } ;
488
514
match res {
489
515
Err ( PaymentSendFailure :: AllFailedResendSafe ( _) ) => {
490
516
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
@@ -495,7 +521,7 @@ impl OutboundPayments {
495
521
} else { return res }
496
522
} else { return res }
497
523
core:: mem:: drop ( outbounds) ;
498
- self . pay_internal ( payment_id, route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, send_payment_along_path)
524
+ self . pay_internal ( payment_id, None , route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, send_payment_along_path)
499
525
} ,
500
526
Err ( PaymentSendFailure :: PartialFailure { failed_paths_retry : Some ( retry) , results, .. } ) => {
501
527
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
@@ -510,7 +536,7 @@ impl OutboundPayments {
510
536
// Some paths were sent, even if we failed to send the full MPP value our recipient may
511
537
// misbehave and claim the funds, at which point we have to consider the payment sent, so
512
538
// return `Ok()` here, ignoring any retry errors.
513
- let _ = self . pay_internal ( payment_id, retry, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, send_payment_along_path) ;
539
+ let _ = self . pay_internal ( payment_id, None , retry, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, send_payment_along_path) ;
514
540
Ok ( ( ) )
515
541
} ,
516
542
Err ( PaymentSendFailure :: PartialFailure { failed_paths_retry : None , .. } ) => {
@@ -590,7 +616,7 @@ impl OutboundPayments {
590
616
} ) ) ,
591
617
}
592
618
} ;
593
- 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)
619
+ 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)
594
620
}
595
621
596
622
pub ( super ) fn send_probe < ES : Deref , NS : Deref , F > (
@@ -616,7 +642,7 @@ impl OutboundPayments {
616
642
let route = Route { paths : vec ! [ hops] , payment_params : None } ;
617
643
let onion_session_privs = self . add_new_pending_payment ( payment_hash, None , payment_id, & route, Retry :: Attempts ( 0 ) , None , entropy_source, best_block_height) ?;
618
644
619
- 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) {
645
+ 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) {
620
646
Ok ( ( ) ) => Ok ( ( payment_hash, payment_id) ) ,
621
647
Err ( e) => {
622
648
self . remove_outbound_if_all_failed ( payment_id, & e) ;
@@ -673,7 +699,7 @@ impl OutboundPayments {
673
699
& self , route : & Route , payment_hash : PaymentHash , payment_secret : & Option < PaymentSecret > ,
674
700
keysend_preimage : Option < PaymentPreimage > , payment_id : PaymentId , recv_value_msat : Option < u64 > ,
675
701
onion_session_privs : Vec < [ u8 ; 32 ] > , node_signer : & NS , best_block_height : u32 ,
676
- send_payment_along_path : F
702
+ send_payment_along_path : & F
677
703
) -> Result < ( ) , PaymentSendFailure >
678
704
where
679
705
NS :: Target : NodeSigner ,
@@ -788,7 +814,7 @@ impl OutboundPayments {
788
814
{
789
815
self . send_payment_internal ( route, payment_hash, payment_secret, keysend_preimage, payment_id,
790
816
recv_value_msat, onion_session_privs, node_signer, best_block_height,
791
- send_payment_along_path)
817
+ & send_payment_along_path)
792
818
. map_err ( |e| { self . remove_outbound_if_all_failed ( payment_id, & e) ; e } )
793
819
}
794
820
0 commit comments