Skip to content

Commit 29440f1

Browse files
committed
f Add more fields to LSPS2ServiceConfig
1 parent 7d8e26d commit 29440f1

File tree

4 files changed

+62
-31
lines changed

4 files changed

+62
-31
lines changed

bindings/ldk_node.udl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ dictionary EsploraSyncConfig {
2525
u64 fee_rate_cache_update_interval_secs;
2626
};
2727

28+
dictionary LSPS2ServiceConfig {
29+
string? require_token;
30+
boolean advertise_service;
31+
u32 channel_opening_fee_ppm;
32+
u32 channel_over_provisioning_ppm;
33+
u64 min_channel_opening_fee_msat;
34+
u32 min_channel_lifetime;
35+
u32 max_client_to_self_delay;
36+
u64 min_payment_size_msat;
37+
u64 max_payment_size_msat;
38+
};
39+
2840
enum LogLevel {
2941
"Gossip",
3042
"Trace",

src/builder.rs

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use crate::gossip::GossipSource;
1818
use crate::io::sqlite_store::SqliteStore;
1919
use crate::io::utils::{read_node_metrics, write_node_metrics};
2020
use crate::io::vss_store::VssStore;
21-
use crate::liquidity::{LSPS1ClientConfig, LSPS2ClientConfig, LiquiditySourceBuilder};
21+
use crate::liquidity::{
22+
LSPS1ClientConfig, LSPS2ClientConfig, LSPS2ServiceConfig, LiquiditySourceBuilder,
23+
};
2224
use crate::logger::{log_error, log_info, LdkLogger, LogLevel, LogWriter, Logger};
2325
use crate::message_handler::NodeCustomMessageHandler;
2426
use crate::payment::store::PaymentStore;
@@ -108,12 +110,6 @@ struct LiquiditySourceConfig {
108110
lsps2_service: Option<LSPS2ServiceConfig>,
109111
}
110112

111-
#[derive(Debug, Clone)]
112-
struct LSPS2ServiceConfig {
113-
token: Option<String>,
114-
advertise_service: bool,
115-
}
116-
117113
#[derive(Clone)]
118114
enum LogWriterConfig {
119115
File { log_file_path: Option<String>, log_level: Option<LogLevel> },
@@ -352,20 +348,15 @@ impl NodeBuilder {
352348
/// Configures the [`Node`] instance to provide an [LSPS2] service, issuing just-in-time
353349
/// channels to clients.
354350
///
355-
/// If a `token` is provided, only requests matching this token will be accepted.
356-
///
357-
/// If `advertise_service` is set, the LSPS service will be announced via the gossip network.
358-
///
359351
/// **Caution**: LSP service support is in **alpha** and is considered an experimental feature.
360352
///
361353
/// [LSPS2]: https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md
362354
pub fn set_liquidity_provider_lsps2(
363-
&mut self, token: Option<String>, advertise_service: bool,
355+
&mut self, service_config: LSPS2ServiceConfig,
364356
) -> &mut Self {
365357
let liquidity_source_config =
366358
self.liquidity_source_config.get_or_insert(LiquiditySourceConfig::default());
367-
let lsps2_service_config = LSPS2ServiceConfig { token, advertise_service };
368-
liquidity_source_config.lsps2_service = Some(lsps2_service_config);
359+
liquidity_source_config.lsps2_service = Some(service_config);
369360
self
370361
}
371362

@@ -724,15 +715,11 @@ impl ArcedNodeBuilder {
724715
/// Configures the [`Node`] instance to provide an [LSPS2] service, issuing just-in-time
725716
/// channels to clients.
726717
///
727-
/// If a `token` is provided, only requests matching this token will be accepted.
728-
///
729-
/// If `advertise_service` is set, the LSPS service will be announced via the gossip network.
730-
///
731718
/// **Caution**: LSP service support is in **alpha** and is considered an experimental feature.
732719
///
733720
/// [LSPS2]: https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md
734-
pub fn set_liquidity_provider_lsps2(&self, token: Option<String>, advertise_service: bool) {
735-
self.inner.write().unwrap().set_liquidity_provider_lsps2(token, advertise_service);
721+
pub fn set_liquidity_provider_lsps2(&self, service_config: LSPS2ServiceConfig) {
722+
self.inner.write().unwrap().set_liquidity_provider_lsps2(service_config);
736723
}
737724

738725
/// Sets the used storage directory path.
@@ -1246,11 +1233,7 @@ fn build_with_store_internal(
12461233
lsps_xpriv.private_key.secret_bytes()
12471234
};
12481235
lsc.lsps2_service.as_ref().map(|config| {
1249-
liquidity_source_builder.lsps2_service(
1250-
promise_secret,
1251-
config.token.clone(),
1252-
config.advertise_service,
1253-
)
1236+
liquidity_source_builder.lsps2_service(promise_secret, config.clone())
12541237
});
12551238

12561239
let liquidity_source = Arc::new(liquidity_source_builder.build());

src/liquidity.rs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,45 @@ pub(crate) struct LSPS2ClientConfig {
7777
}
7878

7979
struct LSPS2Service {
80-
token: Option<String>,
80+
service_config: LSPS2ServiceConfig,
8181
ldk_service_config: LdkLSPS2ServiceConfig,
82-
advertise_service: bool,
82+
}
83+
84+
/// Represents the configuration of the LSPS2 service.
85+
///
86+
/// See [bLIP-52 / LSPS2] for more information.
87+
///
88+
/// [bLIP-52 / LSPS2]: https://github.com/lightning/blips/blob/master/blip-0052.md
89+
#[derive(Debug, Clone)]
90+
pub struct LSPS2ServiceConfig {
91+
/// A token we may require to be sent by the clients.
92+
///
93+
/// If set, only requests matching this token will be accepted.
94+
pub require_token: Option<String>,
95+
/// Indicates whether the LSPS service will be announced via the gossip network.
96+
pub advertise_service: bool,
97+
/// The fee we withhold for the channel open from the initial payment.
98+
///
99+
/// This fee is proportional to the client-requested amount, in parts-per-million.
100+
pub channel_opening_fee_ppm: u32,
101+
/// The proportional overprovisioning for the channel.
102+
///
103+
/// This determines, in parts-per-million of the client-requested amount, how much value we'll
104+
/// provision on top of the client-requested payment amount.
105+
///
106+
/// For example, setting this to `100_000` will result in a channel being opened that is 10%
107+
/// larger than the client-requested payment amount.
108+
pub channel_over_provisioning_ppm: u32,
109+
/// The minimum fee required for opening a channel.
110+
pub min_channel_opening_fee_msat: u64,
111+
/// The minimum number of blocks after confirmation we promise to keep the channel open.
112+
pub min_channel_lifetime: u32,
113+
/// The maximum number of blocks that the client is allowed to set its `to_self_delay` parameter.
114+
pub max_client_to_self_delay: u32,
115+
/// The minimum payment size that we will accept when opening a channel.
116+
pub min_payment_size_msat: u64,
117+
/// The maximum payment size that we will accept when opening a channel.
118+
pub max_payment_size_msat: u64,
83119
}
84120

85121
pub(crate) struct LiquiditySourceBuilder<L: Deref>
@@ -157,17 +193,17 @@ where
157193
}
158194

159195
pub(crate) fn lsps2_service(
160-
&mut self, promise_secret: [u8; 32], token: Option<String>, advertise_service: bool,
196+
&mut self, promise_secret: [u8; 32], service_config: LSPS2ServiceConfig,
161197
) -> &mut Self {
162198
let ldk_service_config = LdkLSPS2ServiceConfig { promise_secret };
163-
self.lsps2_service = Some(LSPS2Service { token, ldk_service_config, advertise_service });
199+
self.lsps2_service = Some(LSPS2Service { service_config, ldk_service_config });
164200
self
165201
}
166202

167203
pub(crate) fn build(self) -> LiquiditySource<L> {
168204
let liquidity_service_config = self.lsps2_service.as_ref().map(|s| {
169205
let lsps2_service_config = Some(s.ldk_service_config.clone());
170-
let advertise_service = s.advertise_service;
206+
let advertise_service = s.service_config.advertise_service;
171207
LiquidityServiceConfig { lsps2_service_config, advertise_service }
172208
});
173209

src/uniffi_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub use crate::config::{
1414
default_config, AnchorChannelsConfig, EsploraSyncConfig, MaxDustHTLCExposure,
1515
};
1616
pub use crate::graph::{ChannelInfo, ChannelUpdateInfo, NodeAnnouncementInfo, NodeInfo};
17-
pub use crate::liquidity::{LSPS1OrderStatus, OnchainPaymentInfo, PaymentInfo};
17+
pub use crate::liquidity::{LSPS1OrderStatus, LSPS2ServiceConfig, OnchainPaymentInfo, PaymentInfo};
1818
pub use crate::logger::{LogLevel, LogRecord, LogWriter};
1919
pub use crate::payment::store::{
2020
ConfirmationStatus, LSPFeeLimits, PaymentDirection, PaymentKind, PaymentStatus,

0 commit comments

Comments
 (0)