Skip to content

Commit 44e94c4

Browse files
committed
Add LSPS5 webhook notification support
Integrates LSPS5 (BLIP-0055) from lightning-liquidity to enable webhook-based push notifications for clients. - Add event system integration for LSPS5 events - Expose public API for webhook management This allows client developers to register webhook endpoints with their LSP to receive notifications when their app is offline.
1 parent a6a54a4 commit 44e94c4

7 files changed

Lines changed: 1079 additions & 11 deletions

File tree

bindings/ldk_node.udl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,9 @@ enum NodeError {
361361
"InvalidBlindedPaths",
362362
"AsyncPaymentServicesDisabled",
363363
"HrnParsingFailed",
364+
"LiquiditySetWebhookFailed",
365+
"LiquidityRemoveWebhookFailed",
366+
"LiquidityListWebhooksFailed"
364367
};
365368

366369
dictionary NodeStatus {

src/builder.rs

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ use crate::io::{
6666
PENDING_PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE,
6767
};
6868
use crate::liquidity::{
69-
LSPS1ClientConfig, LSPS2ClientConfig, LSPS2ServiceConfig, LiquiditySourceBuilder,
69+
LSPS1ClientConfig, LSPS2ClientConfig, LSPS2ServiceConfig, LSPS5ClientConfig,
70+
LiquiditySourceBuilder,
7071
};
7172
use crate::logger::{log_error, LdkLogger, LogLevel, LogWriter, Logger};
7273
use crate::message_handler::NodeCustomMessageHandler;
@@ -76,8 +77,8 @@ use crate::runtime::{Runtime, RuntimeSpawner};
7677
use crate::tx_broadcaster::TransactionBroadcaster;
7778
use crate::types::{
7879
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreWrapper, GossipSync, Graph,
79-
KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager, PendingPaymentStore,
80-
Persister, SyncAndAsyncKVStore,
80+
KeysManager, LSPS5ServiceConfig, MessageRouter, OnionMessenger, PaymentStore, PeerManager,
81+
PendingPaymentStore, Persister, SyncAndAsyncKVStore,
8182
};
8283
use crate::wallet::persist::KVStoreWalletPersister;
8384
use crate::wallet::Wallet;
@@ -125,6 +126,10 @@ struct LiquiditySourceConfig {
125126
lsps2_client: Option<LSPS2ClientConfig>,
126127
// Act as an LSPS2 service.
127128
lsps2_service: Option<LSPS2ServiceConfig>,
129+
// Act as an LSPS5 client connecting to the given service.
130+
lsps5_client: Option<LSPS5ClientConfig>,
131+
// Act as an LSPS5 service.
132+
lsps5_service: Option<LSPS5ServiceConfig>,
128133
}
129134

130135
#[derive(Clone)]
@@ -450,6 +455,36 @@ impl NodeBuilder {
450455
self
451456
}
452457

458+
/// Configures the [`Node`] instance to source webhook notifications from the given
459+
/// [bLIP-55 / LSPS5] service.
460+
///
461+
/// This allows the client to register webhook endpoints with the LSP to receive
462+
/// push notifications for Lightning events when the client is offline.
463+
///
464+
/// [bLIP-55 / LSPS5]: https://github.com/lightning/blips/blob/master/blip-0055.md
465+
pub fn set_liquidity_source_lsps5(
466+
&mut self, node_id: PublicKey, address: SocketAddress,
467+
) -> &mut Self {
468+
let liquidity_source_config =
469+
self.liquidity_source_config.get_or_insert(LiquiditySourceConfig::default());
470+
let lsps5_client_config = LSPS5ClientConfig { node_id, address };
471+
liquidity_source_config.lsps5_client = Some(lsps5_client_config);
472+
self
473+
}
474+
475+
/// Configures the [`Node`] instance to provide an [LSPS5] service, enabling clients
476+
/// to register webhooks for push notifications.
477+
///
478+
/// [LSPS5]: https://github.com/lightning/blips/blob/master/blip-0055.md
479+
pub fn set_liquidity_provider_lsps5(
480+
&mut self, service_config: LSPS5ServiceConfig,
481+
) -> &mut Self {
482+
let liquidity_source_config =
483+
self.liquidity_source_config.get_or_insert(LiquiditySourceConfig::default());
484+
liquidity_source_config.lsps5_service = Some(service_config);
485+
self
486+
}
487+
453488
/// Sets the used storage directory path.
454489
pub fn set_storage_dir_path(&mut self, storage_dir_path: String) -> &mut Self {
455490
self.config.storage_dir_path = storage_dir_path;
@@ -851,6 +886,25 @@ impl ArcedNodeBuilder {
851886
self.inner.write().unwrap().set_liquidity_provider_lsps2(service_config);
852887
}
853888

889+
/// Configures the [`Node`] instance to source webhook notifications from the given
890+
/// [bLIP-55 / LSPS5] service.
891+
///
892+
/// This allows the client to register webhook endpoints with the LSP to receive
893+
/// push notifications for Lightning events when the client is offline.
894+
///
895+
/// [bLIP-55 / LSPS5]: https://github.com/lightning/blips/blob/master/blip-0055.md
896+
pub fn set_liquidity_source_lsps5(&self, node_id: PublicKey, address: SocketAddress) {
897+
self.inner.write().unwrap().set_liquidity_source_lsps5(node_id, address);
898+
}
899+
900+
/// Configures the [`Node`] instance to provide an [LSPS5] service, enabling clients
901+
/// to register webhooks for push notifications.
902+
///
903+
/// [LSPS5]: https://github.com/lightning/blips/blob/master/blip-0055.md
904+
pub fn set_liquidity_provider_lsps5(&self, service_config: LSPS5ServiceConfig) {
905+
self.inner.write().unwrap().set_liquidity_provider_lsps5(service_config);
906+
}
907+
854908
/// Sets the used storage directory path.
855909
pub fn set_storage_dir_path(&self, storage_dir_path: String) {
856910
self.inner.write().unwrap().set_storage_dir_path(storage_dir_path);
@@ -1627,6 +1681,14 @@ fn build_with_store_internal(
16271681
liquidity_source_builder.lsps2_service(promise_secret, config.clone())
16281682
});
16291683

1684+
lsc.lsps5_client.as_ref().map(|config| {
1685+
liquidity_source_builder.lsps5_client(config.node_id, config.address.clone())
1686+
});
1687+
1688+
lsc.lsps5_service
1689+
.as_ref()
1690+
.map(|config| liquidity_source_builder.lsps5_service(config.clone()));
1691+
16301692
let liquidity_source = runtime
16311693
.block_on(async move { liquidity_source_builder.build().await.map(Arc::new) })?;
16321694
let custom_message_handler =

src/error.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ pub enum Error {
131131
AsyncPaymentServicesDisabled,
132132
/// Parsing a Human-Readable Name has failed.
133133
HrnParsingFailed,
134+
/// Failed to set a webhook with the LSP.
135+
LiquiditySetWebhookFailed,
136+
/// Failed to remove a webhook with the LSP.
137+
LiquidityRemoveWebhookFailed,
138+
/// Failed to list webhooks with the LSP.
139+
LiquidityListWebhooksFailed,
134140
}
135141

136142
impl fmt::Display for Error {
@@ -213,6 +219,15 @@ impl fmt::Display for Error {
213219
Self::HrnParsingFailed => {
214220
write!(f, "Failed to parse a human-readable name.")
215221
},
222+
Self::LiquiditySetWebhookFailed => {
223+
write!(f, "Failed to set a webhook with the LSP.")
224+
},
225+
Self::LiquidityRemoveWebhookFailed => {
226+
write!(f, "Failed to remove a webhook with the LSP.")
227+
},
228+
Self::LiquidityListWebhooksFailed => {
229+
write!(f, "Failed to list webhooks with the LSP.")
230+
},
216231
}
217232
}
218233
}

src/lib.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ use lightning::ln::msgs::SocketAddress;
148148
use lightning::routing::gossip::NodeAlias;
149149
use lightning::util::persist::KVStoreSync;
150150
use lightning_background_processor::process_events_async;
151-
use liquidity::{LSPS1Liquidity, LiquiditySource};
151+
use liquidity::{LSPS1Liquidity, LSPS5Liquidity, LiquiditySource};
152152
use logger::{log_debug, log_error, log_info, log_trace, LdkLogger, Logger};
153153
use payment::asynchronous::om_mailbox::OnionMessageMailbox;
154154
use payment::asynchronous::static_invoice_store::StaticInvoiceStore;
@@ -1032,6 +1032,32 @@ impl Node {
10321032
))
10331033
}
10341034

1035+
/// Returns a liquidity handler allowing to handle webhooks and notifications via the [bLIP-55 / LSPS5] protocol.
1036+
///
1037+
/// [bLIP-55 / LSPS5]: https://github.com/lightning/blips/blob/master/blip-0055.md
1038+
#[cfg(not(feature = "uniffi"))]
1039+
pub fn lsps5_liquidity(&self) -> LSPS5Liquidity {
1040+
LSPS5Liquidity::new(
1041+
Arc::clone(&self.runtime),
1042+
Arc::clone(&self.connection_manager),
1043+
self.liquidity_source.clone(),
1044+
Arc::clone(&self.logger),
1045+
)
1046+
}
1047+
1048+
/// Returns a liquidity handler allowing to handle webhooks and notifications via the [bLIP-55 / LSPS5] protocol.
1049+
///
1050+
/// [bLIP-55 / LSPS5]: https://github.com/lightning/blips/blob/master/blip-0055.md
1051+
#[cfg(feature = "uniffi")]
1052+
pub fn lsps5_liquidity(&self) -> Arc<LSPS5Liquidity> {
1053+
Arc::new(LSPS5Liquidity::new(
1054+
Arc::clone(&self.runtime),
1055+
Arc::clone(&self.connection_manager),
1056+
self.liquidity_source.clone(),
1057+
Arc::clone(&self.logger),
1058+
))
1059+
}
1060+
10351061
/// Retrieve a list of known channels.
10361062
pub fn list_channels(&self) -> Vec<ChannelDetails> {
10371063
self.channel_manager.list_channels().into_iter().map(|c| c.into()).collect()

0 commit comments

Comments
 (0)