Skip to content

Commit 5af55c9

Browse files
benthecarmanclaude
andcommitted
Make payment retry timeout configurable via Config
Add `payment_retry_timeout_secs` field to `Config`, replacing the hardcoded `LDK_PAYMENT_RETRY_TIMEOUT` constant. This allows users to tune how long LDK retries failed payments before giving up. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b0e159a commit 5af55c9

4 files changed

Lines changed: 23 additions & 12 deletions

File tree

src/config.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const DEFAULT_LDK_WALLET_SYNC_INTERVAL_SECS: u64 = 30;
2828
const DEFAULT_FEE_RATE_CACHE_UPDATE_INTERVAL_SECS: u64 = 60 * 10;
2929
const DEFAULT_PROBING_LIQUIDITY_LIMIT_MULTIPLIER: u64 = 3;
3030
const DEFAULT_ANCHOR_PER_CHANNEL_RESERVE_SATS: u64 = 25_000;
31+
const DEFAULT_PAYMENT_RETRY_TIMEOUT_SECS: u64 = 10;
3132

3233
// The default timeout after which we abort a wallet syncing operation.
3334
const DEFAULT_BDK_WALLET_SYNC_TIMEOUT_SECS: u64 = 60;
@@ -63,9 +64,6 @@ pub(crate) const BDK_CLIENT_STOP_GAP: usize = 20;
6364
// The number of concurrent requests made against the API provider.
6465
pub(crate) const BDK_CLIENT_CONCURRENCY: usize = 4;
6566

66-
// The timeout after which we abandon retrying failed payments.
67-
pub(crate) const LDK_PAYMENT_RETRY_TIMEOUT: Duration = Duration::from_secs(10);
68-
6967
// The time in-between peer reconnection attempts.
7068
pub(crate) const PEER_RECONNECTION_INTERVAL: Duration = Duration::from_secs(60);
7169

@@ -131,6 +129,7 @@ pub(crate) const LNURL_AUTH_TIMEOUT_SECS: u64 = 15;
131129
/// | `probing_liquidity_limit_multiplier` | 3 |
132130
/// | `log_level` | Debug |
133131
/// | `anchor_channels_config` | Some(..) |
132+
/// | `payment_retry_timeout_secs` | 10 |
134133
/// | `route_parameters` | None |
135134
///
136135
/// See [`AnchorChannelsConfig`] and [`RouteParametersConfig`] for more information regarding their
@@ -188,6 +187,10 @@ pub struct Config {
188187
/// closure. We *will* however still try to get the Anchor spending transactions confirmed
189188
/// on-chain with the funds available.
190189
pub anchor_channels_config: Option<AnchorChannelsConfig>,
190+
/// The timeout in seconds after which we stop retrying failed payments.
191+
///
192+
/// When a payment fails to route, LDK will automatically retry until this timeout elapses.
193+
pub payment_retry_timeout_secs: u64,
191194
/// Configuration options for payment routing and pathfinding.
192195
///
193196
/// Setting the [`RouteParametersConfig`] provides flexibility to customize how payments are routed,
@@ -208,6 +211,7 @@ impl Default for Config {
208211
trusted_peers_0conf: Vec::new(),
209212
probing_liquidity_limit_multiplier: DEFAULT_PROBING_LIQUIDITY_LIMIT_MULTIPLIER,
210213
anchor_channels_config: Some(AnchorChannelsConfig::default()),
214+
payment_retry_timeout_secs: DEFAULT_PAYMENT_RETRY_TIMEOUT_SECS,
211215
route_parameters: None,
212216
node_alias: None,
213217
}

src/payment/bolt11.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//! [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
1111
1212
use std::sync::{Arc, RwLock};
13+
use std::time::Duration;
1314

1415
use bitcoin::hashes::sha256::Hash as Sha256;
1516
use bitcoin::hashes::Hash;
@@ -23,7 +24,7 @@ use lightning_invoice::{
2324
};
2425
use lightning_types::payment::{PaymentHash, PaymentPreimage};
2526

26-
use crate::config::{Config, LDK_PAYMENT_RETRY_TIMEOUT};
27+
use crate::config::Config;
2728
use crate::connection::ConnectionManager;
2829
use crate::data_store::DataStoreUpdateResult;
2930
use crate::error::Error;
@@ -259,7 +260,8 @@ impl Bolt11Payment {
259260

260261
let route_params_config =
261262
route_parameters.or(self.config.route_parameters).unwrap_or_default();
262-
let retry_strategy = Retry::Timeout(LDK_PAYMENT_RETRY_TIMEOUT);
263+
let retry_strategy =
264+
Retry::Timeout(Duration::from_secs(self.config.payment_retry_timeout_secs));
263265
let payment_secret = Some(*invoice.payment_secret());
264266

265267
let optional_params = OptionalBolt11PaymentParams {
@@ -369,7 +371,8 @@ impl Bolt11Payment {
369371

370372
let route_params_config =
371373
route_parameters.or(self.config.route_parameters).unwrap_or_default();
372-
let retry_strategy = Retry::Timeout(LDK_PAYMENT_RETRY_TIMEOUT);
374+
let retry_strategy =
375+
Retry::Timeout(Duration::from_secs(self.config.payment_retry_timeout_secs));
373376
let payment_secret = Some(*invoice.payment_secret());
374377

375378
let optional_params = OptionalBolt11PaymentParams {

src/payment/bolt12.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use lightning::sign::EntropySource;
2424
use lightning::util::ser::{Readable, Writeable};
2525
use lightning_types::string::UntrustedString;
2626

27-
use crate::config::{AsyncPaymentsRole, Config, LDK_PAYMENT_RETRY_TIMEOUT};
27+
use crate::config::{AsyncPaymentsRole, Config};
2828
use crate::error::Error;
2929
use crate::ffi::{maybe_deref, maybe_wrap};
3030
use crate::logger::{log_error, log_info, LdkLogger, Logger};
@@ -96,7 +96,8 @@ impl Bolt12Payment {
9696
let offer = maybe_deref(offer);
9797

9898
let payment_id = PaymentId(self.keys_manager.get_secure_random_bytes());
99-
let retry_strategy = Retry::Timeout(LDK_PAYMENT_RETRY_TIMEOUT);
99+
let retry_strategy =
100+
Retry::Timeout(Duration::from_secs(self.config.payment_retry_timeout_secs));
100101
let route_parameters =
101102
route_parameters.or(self.config.route_parameters).unwrap_or_default();
102103

@@ -269,7 +270,8 @@ impl Bolt12Payment {
269270
let offer = maybe_deref(offer);
270271

271272
let payment_id = PaymentId(self.keys_manager.get_secure_random_bytes());
272-
let retry_strategy = Retry::Timeout(LDK_PAYMENT_RETRY_TIMEOUT);
273+
let retry_strategy =
274+
Retry::Timeout(Duration::from_secs(self.config.payment_retry_timeout_secs));
273275
let route_parameters =
274276
route_parameters.or(self.config.route_parameters).unwrap_or_default();
275277

@@ -475,7 +477,8 @@ impl Bolt12Payment {
475477
let absolute_expiry = (SystemTime::now() + Duration::from_secs(expiry_secs as u64))
476478
.duration_since(UNIX_EPOCH)
477479
.unwrap();
478-
let retry_strategy = Retry::Timeout(LDK_PAYMENT_RETRY_TIMEOUT);
480+
let retry_strategy =
481+
Retry::Timeout(Duration::from_secs(self.config.payment_retry_timeout_secs));
479482
let route_parameters =
480483
route_parameters.or(self.config.route_parameters).unwrap_or_default();
481484

src/payment/spontaneous.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//! Holds a payment handler allowing to send spontaneous ("keysend") payments.
99
1010
use std::sync::{Arc, RwLock};
11+
use std::time::Duration;
1112

1213
use bitcoin::secp256k1::PublicKey;
1314
use lightning::ln::channelmanager::PaymentId;
@@ -18,7 +19,7 @@ use lightning::routing::router::{PaymentParameters, RouteParameters, RouteParame
1819
use lightning::sign::EntropySource;
1920
use lightning_types::payment::{PaymentHash, PaymentPreimage};
2021

21-
use crate::config::{Config, LDK_PAYMENT_RETRY_TIMEOUT};
22+
use crate::config::Config;
2223
use crate::error::Error;
2324
use crate::logger::{log_error, log_info, LdkLogger, Logger};
2425
use crate::payment::store::{PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus};
@@ -113,7 +114,7 @@ impl SpontaneousPayment {
113114
recipient_fields,
114115
PaymentId(payment_hash.0),
115116
route_params,
116-
Retry::Timeout(LDK_PAYMENT_RETRY_TIMEOUT),
117+
Retry::Timeout(Duration::from_secs(self.config.payment_retry_timeout_secs)),
117118
) {
118119
Ok(_hash) => {
119120
log_info!(self.logger, "Initiated sending {}msat to {}.", amount_msat, node_id);

0 commit comments

Comments
 (0)