Skip to content

Commit 27d8b10

Browse files
committed
Allow configuring LSPS2 JIT channel parameters
Allow LSPS2 services to configure dust HTLC exposure and the maximum force-close avoidance fee separately from regular channels through an optional LSPS2ChannelConfig in LSPS2ServiceConfig. Expose only max_dust_htlc_exposure and force_close_avoidance_max_fee_satoshis. Unset fields inherit the node-wide configuration. Forwarding fees remain zero, accept_underpaying_htlcs is not exposed, and the preexisting CLTV defaults and advertisement are unchanged. Extend the LSPS2 integration test to check the configured force-close avoidance fee and zero base forwarding fee. This change was developed with the assistance of AI tooling (Claude Code). This change was developed with assistance from OpenAI Codex.
1 parent 41c44cd commit 27d8b10

3 files changed

Lines changed: 62 additions & 5 deletions

File tree

‎src/liquidity/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use lightning_liquidity::lsps1::client::LSPS1ClientConfig as LdkLSPS1ClientConfi
2626
use lightning_liquidity::lsps2::client::LSPS2ClientConfig as LdkLSPS2ClientConfig;
2727
use lightning_liquidity::lsps2::service::LSPS2ServiceConfig as LdkLSPS2ServiceConfig;
2828
use lightning_liquidity::{LiquidityClientConfig, LiquidityServiceConfig};
29-
pub use service::lsps2::LSPS2ServiceConfig;
29+
pub use service::lsps2::{LSPS2ChannelConfig, LSPS2ServiceConfig};
3030
use tokio::sync::oneshot;
3131

3232
use crate::builder::BuildError;

‎src/liquidity/service/lsps2.rs‎

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use lightning_liquidity::lsps2::msgs::LSPS2RawOpeningFeeParams;
2121
use lightning_liquidity::lsps2::service::LSPS2ServiceConfig as LdkLSPS2ServiceConfig;
2222
use lightning_types::payment::PaymentHash;
2323

24+
use crate::config::MaxDustHTLCExposure;
2425
use crate::fee_estimator::{ConfirmationTarget, FeeEstimator, OnchainFeeEstimator};
2526
use crate::logger::{log_error, log_trace, LdkLogger};
2627
use crate::types::{ChannelManager, KeysManager, LiquidityManager, PeerManager, Wallet};
@@ -107,6 +108,28 @@ pub struct LSPS2ServiceConfig {
107108
///
108109
/// [`Node::open_0reserve_channel`]: crate::Node::open_0reserve_channel
109110
pub disable_client_reserve: bool,
111+
/// The channel config we'll apply to the JIT channels we open to clients, allowing to
112+
/// configure them separately from regular channels.
113+
///
114+
/// Any unset fields, or if set to `None` entirely, fall back to the node-wide config.
115+
pub channel_config: Option<LSPS2ChannelConfig>,
116+
}
117+
118+
/// A subset of channel configuration options applied to the JIT channels opened towards
119+
/// clients when acting as an LSPS2 service.
120+
///
121+
/// Any fields set to `None` fall back to the node-wide config.
122+
///
123+
/// Note that the forwarding fees of JIT channels are always set to zero, as we're
124+
/// compensated via the channel opening fee.
125+
#[derive(Debug, Clone)]
126+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
127+
pub struct LSPS2ChannelConfig {
128+
/// The total exposure we're willing to allow to potential loss due to dust HTLCs.
129+
pub max_dust_htlc_exposure: Option<MaxDustHTLCExposure>,
130+
/// The additional fee we're willing to pay to avoid waiting for the counterparty's
131+
/// `to_self_delay` to reclaim funds.
132+
pub force_close_avoidance_max_fee_satoshis: Option<u64>,
110133
}
111134

112135
impl<L: Deref> LSPS2ServiceLiquiditySource<L>
@@ -573,12 +596,25 @@ where
573596
debug_assert!(!config.channel_handshake_config.announce_for_forwarding);
574597
debug_assert!(config.accept_forwards_to_priv_channels);
575598

576-
// We set the forwarding fee to 0 for now as we're getting paid by the channel fee.
577-
//
578-
// TODO: revisit this decision eventually.
599+
// We set the forwarding fees to 0 as we're getting paid by the channel opening
600+
// fee.
579601
config.channel_config.forwarding_fee_base_msat = 0;
580602
config.channel_config.forwarding_fee_proportional_millionths = 0;
581603

604+
if let Some(jit_channel_config) = service_config.channel_config.as_ref() {
605+
if let Some(max_dust_htlc_exposure) = jit_channel_config.max_dust_htlc_exposure
606+
{
607+
config.channel_config.max_dust_htlc_exposure =
608+
max_dust_htlc_exposure.into();
609+
}
610+
if let Some(force_close_avoidance_max_fee_satoshis) =
611+
jit_channel_config.force_close_avoidance_max_fee_satoshis
612+
{
613+
config.channel_config.force_close_avoidance_max_fee_satoshis =
614+
force_close_avoidance_max_fee_satoshis;
615+
}
616+
}
617+
582618
let result = if service_config.disable_client_reserve {
583619
self.channel_manager.create_channel_to_trusted_peer_0reserve(
584620
their_network_key,

‎tests/integration_tests_rust.rs‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use ldk_node::config::{
4545
ADDRESS_POOL_SIZE, DEFAULT_FULL_SCAN_STOP_GAP,
4646
};
4747
use ldk_node::entropy::NodeEntropy;
48-
use ldk_node::liquidity::LSPS2ServiceConfig;
48+
use ldk_node::liquidity::{LSPS2ChannelConfig, LSPS2ServiceConfig};
4949
use ldk_node::payment::{
5050
ConfirmationStatus, ForwardedPaymentId, PayerProofOptions, PaymentDetails, PaymentDirection,
5151
PaymentKind, PaymentStatus, TransactionType, UnifiedPaymentResult,
@@ -7575,6 +7575,11 @@ async fn do_lsps2_client_service_integration(client_trusts_lsp: bool) {
75757575
// Setup three nodes: service, client, and payer
75767576
let channel_opening_fee_ppm = 10_000;
75777577
let channel_over_provisioning_ppm = 100_000;
7578+
7579+
let jit_channel_config = LSPS2ChannelConfig {
7580+
max_dust_htlc_exposure: None,
7581+
force_close_avoidance_max_fee_satoshis: Some(1337),
7582+
};
75787583
let lsps2_service_config = LSPS2ServiceConfig {
75797584
require_token: None,
75807585
advertise_service: false,
@@ -7587,6 +7592,7 @@ async fn do_lsps2_client_service_integration(client_trusts_lsp: bool) {
75877592
max_client_to_self_delay: 1024,
75887593
client_trusts_lsp,
75897594
disable_client_reserve: false,
7595+
channel_config: Some(jit_channel_config),
75907596
};
75917597

75927598
let service_config = random_config();
@@ -7724,6 +7730,14 @@ async fn do_lsps2_client_service_integration(client_trusts_lsp: bool) {
77247730
let channel_value_sats = client_node.list_channels().first().unwrap().channel_value_sats;
77257731
assert_eq!(channel_value_sats, expected_channel_size_sat);
77267732

7733+
let jit_channel = service_node
7734+
.list_channels()
7735+
.into_iter()
7736+
.find(|c| c.counterparty.node_id == client_node.node_id())
7737+
.unwrap();
7738+
assert_eq!(jit_channel.config.force_close_avoidance_max_fee_satoshis, 1337);
7739+
assert_eq!(jit_channel.config.forwarding_fee_base_msat, 0);
7740+
77277741
println!("Generating regular invoice!");
77287742
let invoice_description =
77297743
Bolt11InvoiceDescription::Direct(Description::new(String::from("asdf")).unwrap()).into();
@@ -7927,6 +7941,7 @@ async fn bolt12_lsps2_client_service_integration() {
79277941
max_client_to_self_delay: 1024,
79287942
client_trusts_lsp: true,
79297943
disable_client_reserve: false,
7944+
channel_config: None,
79307945
};
79317946

79327947
let service_config = random_config();
@@ -8400,6 +8415,7 @@ async fn lsps2_client_trusts_lsp() {
84008415
max_client_to_self_delay: 1024,
84018416
client_trusts_lsp: true,
84028417
disable_client_reserve: false,
8418+
channel_config: None,
84038419
};
84048420

84058421
let service_config = random_config();
@@ -8573,6 +8589,7 @@ async fn lsps2_lsp_trusts_client_but_client_does_not_claim() {
85738589
max_client_to_self_delay: 1024,
85748590
client_trusts_lsp: false,
85758591
disable_client_reserve: false,
8592+
channel_config: None,
85768593
};
85778594

85788595
let service_config = random_config();
@@ -8702,6 +8719,7 @@ async fn setup_lsps2_nodes<S: PaginatedKVStore + Send + Sync + 'static>(
87028719
max_client_to_self_delay: 1024,
87038720
client_trusts_lsp: false,
87048721
disable_client_reserve: false,
8722+
channel_config: None,
87058723
};
87068724

87078725
let service_config = random_config();
@@ -9823,6 +9841,7 @@ async fn do_lsps2_multi_lsp_picks_cheapest(
98239841
max_client_to_self_delay: 1024,
98249842
client_trusts_lsp: true,
98259843
disable_client_reserve: false,
9844+
channel_config: None,
98269845
};
98279846
let cheap_node_config = random_config();
98289847
setup_builder!(cheap_builder, cheap_node_config.node_config);
@@ -9846,6 +9865,7 @@ async fn do_lsps2_multi_lsp_picks_cheapest(
98469865
max_client_to_self_delay: 1024,
98479866
client_trusts_lsp: true,
98489867
disable_client_reserve: false,
9868+
channel_config: None,
98499869
};
98509870
let expensive_node_config = random_config();
98519871
setup_builder!(expensive_builder, expensive_node_config.node_config);
@@ -10130,6 +10150,7 @@ async fn lsps2_service_funding_fee_does_not_spend_anchor_reserve() {
1013010150
max_client_to_self_delay: 1024,
1013110151
client_trusts_lsp: false,
1013210152
disable_client_reserve: false,
10153+
channel_config: None,
1013310154
};
1013410155

1013510156
let service_config = random_config();

0 commit comments

Comments
 (0)