@@ -45,15 +45,15 @@ use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, No
45
45
#[ cfg( any( feature = "_test_utils" , test) ) ]
46
46
use crate :: ln:: features:: InvoiceFeatures ;
47
47
use crate :: routing:: gossip:: NetworkGraph ;
48
- use crate :: routing:: router:: { DefaultRouter , InFlightHtlcs , PaymentParameters , Route , RouteHop , RoutePath , Router } ;
48
+ use crate :: routing:: router:: { DefaultRouter , InFlightHtlcs , PaymentParameters , Route , RouteHop , RouteParameters , RoutePath , Router } ;
49
49
use crate :: routing:: scoring:: ProbabilisticScorer ;
50
50
use crate :: ln:: msgs;
51
51
use crate :: ln:: onion_utils;
52
52
use crate :: ln:: onion_utils:: HTLCFailReason ;
53
53
use crate :: ln:: msgs:: { ChannelMessageHandler , DecodeError , LightningError , MAX_VALUE_MSAT } ;
54
54
#[ cfg( test) ]
55
55
use crate :: ln:: outbound_payment;
56
- use crate :: ln:: outbound_payment:: { OutboundPayments , PendingOutboundPayment } ;
56
+ use crate :: ln:: outbound_payment:: { OutboundPayments , PaymentAttempts , PendingOutboundPayment , Retry } ;
57
57
use crate :: ln:: wire:: Encode ;
58
58
use crate :: chain:: keysinterface:: { EntropySource , KeysManager , NodeSigner , Recipient , SignerProvider , ChannelSigner } ;
59
59
use crate :: util:: config:: { UserConfig , ChannelConfig } ;
@@ -407,7 +407,7 @@ impl MsgHandleErrInternal {
407
407
/// Event::PendingHTLCsForwardable for the API guidelines indicating how long should be waited).
408
408
/// This provides some limited amount of privacy. Ideally this would range from somewhere like one
409
409
/// second to 30 seconds, but people expect lightning to be, you know, kinda fast, sadly.
410
- const MIN_HTLC_RELAY_HOLDING_CELL_MILLIS : u64 = 100 ;
410
+ pub ( super ) const MIN_HTLC_RELAY_HOLDING_CELL_MILLIS : u64 = 100 ;
411
411
412
412
/// For events which result in both a RevokeAndACK and a CommitmentUpdate, by default they should
413
413
/// be sent in the order they appear in the return value, however sometimes the order needs to be
@@ -2466,6 +2466,18 @@ where
2466
2466
self . send_payment_along_path ( path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv) )
2467
2467
}
2468
2468
2469
+ /// Similar to [`ChannelManager::send_payment`], but will automatically find a route based on
2470
+ /// `route_params` and retry failed payment paths based on `retry_strategy`.
2471
+ pub fn send_payment_with_retry ( & self , payment_hash : PaymentHash , payment_secret : & Option < PaymentSecret > , payment_id : PaymentId , route_params : RouteParameters , retry_strategy : Retry ) -> Result < ( ) , PaymentSendFailure > {
2472
+ let best_block_height = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
2473
+ self . pending_outbound_payments
2474
+ . send_payment ( payment_hash, payment_secret, payment_id, retry_strategy, route_params,
2475
+ & self . router , self . list_usable_channels ( ) , self . compute_inflight_htlcs ( ) ,
2476
+ & self . entropy_source , & self . node_signer , best_block_height,
2477
+ |path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
2478
+ self . send_payment_along_path ( path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv) )
2479
+ }
2480
+
2469
2481
#[ cfg( test) ]
2470
2482
fn test_send_payment_internal ( & self , route : & Route , payment_hash : PaymentHash , payment_secret : & Option < PaymentSecret > , keysend_preimage : Option < PaymentPreimage > , payment_id : PaymentId , recv_value_msat : Option < u64 > , onion_session_privs : Vec < [ u8 ; 32 ] > ) -> Result < ( ) , PaymentSendFailure > {
2471
2483
let best_block_height = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
@@ -2477,7 +2489,7 @@ where
2477
2489
#[ cfg( test) ]
2478
2490
pub ( crate ) fn test_add_new_pending_payment ( & self , payment_hash : PaymentHash , payment_secret : Option < PaymentSecret > , payment_id : PaymentId , route : & Route ) -> Result < Vec < [ u8 ; 32 ] > , PaymentSendFailure > {
2479
2491
let best_block_height = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
2480
- self . pending_outbound_payments . test_add_new_pending_payment ( payment_hash, payment_secret, payment_id, route, & self . entropy_source , best_block_height)
2492
+ self . pending_outbound_payments . test_add_new_pending_payment ( payment_hash, payment_secret, payment_id, route, Retry :: Attempts ( 0 ) , & self . entropy_source , best_block_height)
2481
2493
}
2482
2494
2483
2495
@@ -3280,6 +3292,12 @@ where
3280
3292
}
3281
3293
}
3282
3294
3295
+ let best_block_height = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
3296
+ self . pending_outbound_payments . check_retry_payments ( & self . router , || self . list_usable_channels ( ) ,
3297
+ || self . compute_inflight_htlcs ( ) , & self . entropy_source , & self . node_signer , best_block_height, & self . logger ,
3298
+ |path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
3299
+ self . send_payment_along_path ( path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv) ) ;
3300
+
3283
3301
for ( htlc_source, payment_hash, failure_reason, destination) in failed_forwards. drain ( ..) {
3284
3302
self . fail_htlc_backwards_internal ( & htlc_source, & payment_hash, & failure_reason, destination) ;
3285
3303
}
@@ -7339,6 +7357,9 @@ where
7339
7357
hash_map:: Entry :: Vacant ( entry) => {
7340
7358
let path_fee = path. get_path_fees ( ) ;
7341
7359
entry. insert ( PendingOutboundPayment :: Retryable {
7360
+ retry_strategy : Retry :: Attempts ( 0 ) ,
7361
+ attempts : PaymentAttempts :: new ( ) ,
7362
+ route_params : None ,
7342
7363
session_privs : [ session_priv_bytes] . iter ( ) . map ( |a| * a) . collect ( ) ,
7343
7364
payment_hash : htlc. payment_hash ,
7344
7365
payment_secret,
0 commit comments