@@ -13,6 +13,7 @@ use std::time::Duration;
1313use bitcoin:: secp256k1:: PublicKey ;
1414use bitcoin:: Network ;
1515use lightning:: ln:: msgs:: SocketAddress ;
16+ use lightning:: ln:: outbound_payment:: Retry ;
1617use lightning:: routing:: gossip:: NodeAlias ;
1718use lightning:: routing:: router:: RouteParametersConfig ;
1819use lightning:: util:: config:: {
@@ -28,6 +29,7 @@ const DEFAULT_LDK_WALLET_SYNC_INTERVAL_SECS: u64 = 30;
2829const DEFAULT_FEE_RATE_CACHE_UPDATE_INTERVAL_SECS : u64 = 60 * 10 ;
2930const DEFAULT_PROBING_LIQUIDITY_LIMIT_MULTIPLIER : u64 = 3 ;
3031const DEFAULT_ANCHOR_PER_CHANNEL_RESERVE_SATS : u64 = 25_000 ;
32+ const DEFAULT_PAYMENT_RETRY_TIMEOUT_SECS : u64 = 10 ;
3133
3234// The default timeout after which we abort a wallet syncing operation.
3335const DEFAULT_BDK_WALLET_SYNC_TIMEOUT_SECS : u64 = 60 ;
@@ -63,9 +65,6 @@ pub(crate) const BDK_CLIENT_STOP_GAP: usize = 20;
6365// The number of concurrent requests made against the API provider.
6466pub ( crate ) const BDK_CLIENT_CONCURRENCY : usize = 4 ;
6567
66- // The timeout after which we abandon retrying failed payments.
67- pub ( crate ) const LDK_PAYMENT_RETRY_TIMEOUT : Duration = Duration :: from_secs ( 10 ) ;
68-
6968// The time in-between peer reconnection attempts.
7069pub ( crate ) const PEER_RECONNECTION_INTERVAL : Duration = Duration :: from_secs ( 60 ) ;
7170
@@ -131,6 +130,7 @@ pub(crate) const LNURL_AUTH_TIMEOUT_SECS: u64 = 15;
131130/// | `probing_liquidity_limit_multiplier` | 3 |
132131/// | `log_level` | Debug |
133132/// | `anchor_channels_config` | Some(..) |
133+ /// | `payment_retry_strategy` | Timeout(10s) |
134134/// | `route_parameters` | None |
135135/// | `tor_config` | None |
136136///
@@ -189,6 +189,12 @@ pub struct Config {
189189 /// closure. We *will* however still try to get the Anchor spending transactions confirmed
190190 /// on-chain with the funds available.
191191 pub anchor_channels_config : Option < AnchorChannelsConfig > ,
192+ /// The strategy used when retrying failed payments.
193+ ///
194+ /// When a payment fails to route, LDK will automatically retry according to this strategy.
195+ ///
196+ /// See [`PaymentRetryStrategy`] for available options.
197+ pub payment_retry_strategy : PaymentRetryStrategy ,
192198 /// Configuration options for payment routing and pathfinding.
193199 ///
194200 /// Setting the [`RouteParametersConfig`] provides flexibility to customize how payments are routed,
@@ -216,6 +222,7 @@ impl Default for Config {
216222 trusted_peers_0conf : Vec :: new ( ) ,
217223 probing_liquidity_limit_multiplier : DEFAULT_PROBING_LIQUIDITY_LIMIT_MULTIPLIER ,
218224 anchor_channels_config : Some ( AnchorChannelsConfig :: default ( ) ) ,
225+ payment_retry_strategy : PaymentRetryStrategy :: default ( ) ,
219226 tor_config : None ,
220227 route_parameters : None ,
221228 node_alias : None ,
@@ -638,6 +645,45 @@ pub enum AsyncPaymentsRole {
638645 Server ,
639646}
640647
648+ /// Strategies available to retry payment path failures.
649+ ///
650+ /// See [`Retry`] for details.
651+ #[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
652+ #[ cfg_attr( feature = "uniffi" , derive( uniffi:: Enum ) ) ]
653+ pub enum PaymentRetryStrategy {
654+ /// Max number of attempts to retry payment.
655+ ///
656+ /// Please refer to [`Retry`] for further details.
657+ Attempts {
658+ /// The maximum number of payment attempts.
659+ max_attempts : u32 ,
660+ } ,
661+ /// Time elapsed before abandoning retries for a payment.
662+ ///
663+ /// Please refer to [`Retry`] for further details.
664+ Timeout {
665+ /// The timeout in seconds after which we stop retrying.
666+ timeout_secs : u64 ,
667+ } ,
668+ }
669+
670+ impl Default for PaymentRetryStrategy {
671+ fn default ( ) -> Self {
672+ Self :: Timeout { timeout_secs : DEFAULT_PAYMENT_RETRY_TIMEOUT_SECS }
673+ }
674+ }
675+
676+ impl From < PaymentRetryStrategy > for Retry {
677+ fn from ( value : PaymentRetryStrategy ) -> Self {
678+ match value {
679+ PaymentRetryStrategy :: Attempts { max_attempts } => Retry :: Attempts ( max_attempts) ,
680+ PaymentRetryStrategy :: Timeout { timeout_secs } => {
681+ Retry :: Timeout ( Duration :: from_secs ( timeout_secs) )
682+ } ,
683+ }
684+ }
685+ }
686+
641687#[ cfg( test) ]
642688mod tests {
643689 use std:: str:: FromStr ;
0 commit comments