@@ -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///
136136/// See [`AnchorChannelsConfig`] and [`RouteParametersConfig`] for more information regarding their
@@ -188,6 +188,12 @@ pub struct Config {
188188 /// closure. We *will* however still try to get the Anchor spending transactions confirmed
189189 /// on-chain with the funds available.
190190 pub anchor_channels_config : Option < AnchorChannelsConfig > ,
191+ /// The strategy used when retrying failed payments.
192+ ///
193+ /// When a payment fails to route, LDK will automatically retry according to this strategy.
194+ ///
195+ /// See [`PaymentRetryStrategy`] for available options.
196+ pub payment_retry_strategy : PaymentRetryStrategy ,
191197 /// Configuration options for payment routing and pathfinding.
192198 ///
193199 /// Setting the [`RouteParametersConfig`] provides flexibility to customize how payments are routed,
@@ -208,6 +214,7 @@ impl Default for Config {
208214 trusted_peers_0conf : Vec :: new ( ) ,
209215 probing_liquidity_limit_multiplier : DEFAULT_PROBING_LIQUIDITY_LIMIT_MULTIPLIER ,
210216 anchor_channels_config : Some ( AnchorChannelsConfig :: default ( ) ) ,
217+ payment_retry_strategy : PaymentRetryStrategy :: default ( ) ,
211218 route_parameters : None ,
212219 node_alias : None ,
213220 }
@@ -619,6 +626,45 @@ pub enum AsyncPaymentsRole {
619626 Server ,
620627}
621628
629+ /// Strategies available to retry payment path failures.
630+ ///
631+ /// See [`Retry`] for details.
632+ #[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
633+ #[ cfg_attr( feature = "uniffi" , derive( uniffi:: Enum ) ) ]
634+ pub enum PaymentRetryStrategy {
635+ /// Max number of attempts to retry payment.
636+ ///
637+ /// Please refer to [`Retry`] for further details.
638+ Attempts {
639+ /// The maximum number of payment attempts.
640+ max_attempts : u32 ,
641+ } ,
642+ /// Time elapsed before abandoning retries for a payment.
643+ ///
644+ /// Please refer to [`Retry`] for further details.
645+ Timeout {
646+ /// The timeout in seconds after which we stop retrying.
647+ timeout_secs : u64 ,
648+ } ,
649+ }
650+
651+ impl Default for PaymentRetryStrategy {
652+ fn default ( ) -> Self {
653+ Self :: Timeout { timeout_secs : DEFAULT_PAYMENT_RETRY_TIMEOUT_SECS }
654+ }
655+ }
656+
657+ impl From < PaymentRetryStrategy > for Retry {
658+ fn from ( value : PaymentRetryStrategy ) -> Self {
659+ match value {
660+ PaymentRetryStrategy :: Attempts { max_attempts } => Retry :: Attempts ( max_attempts) ,
661+ PaymentRetryStrategy :: Timeout { timeout_secs } => {
662+ Retry :: Timeout ( Duration :: from_secs ( timeout_secs) )
663+ } ,
664+ }
665+ }
666+ }
667+
622668#[ cfg( test) ]
623669mod tests {
624670 use std:: str:: FromStr ;
0 commit comments