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