Skip to content

LSPS5 implementation #3662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
46ac558
Separate time functionality into dedicated feature flag
martinsaposnic Mar 27, 2025
9e7f427
Prefactor - Improvements on LSPSDateTime
martinsaposnic Mar 27, 2025
6bca01b
fixup: Switch LSPSDateTime::is_past and related checks to use the 'ti…
martinsaposnic May 21, 2025
e9145b7
Add custom URL parser for LSPS5.
martinsaposnic Mar 20, 2025
62f32b8
fixup: LSPSUrl -> Only support HTTPS, remove scheme/public checks
martinsaposnic May 21, 2025
bf6e361
Add messaging types for webhook operations
martinsaposnic Mar 11, 2025
0ebbd2c
fixup: Remove unused String fields from errors and use &'static str f…
martinsaposnic May 21, 2025
2a515b5
fixup: Accommodate LSPSWebhookUrl to new LSPSUrl changes.
martinsaposnic May 21, 2025
2565472
Add LSPS5 event enums for webhook operations
martinsaposnic Mar 11, 2025
ae8d111
Add LSPS5 webhook service implementation
martinsaposnic Mar 24, 2025
b9afbb1
fixup: Fix vulnerability where a webhook update could be used to rese…
martinsaposnic May 21, 2025
ef7e530
fixup: Remove explicit timestamp and signature fields from SendWebhoo…
martinsaposnic May 21, 2025
d693e3f
Add LSPS5 webhook client implementation
martinsaposnic Mar 24, 2025
ea6686a
fixup: Refactor LSPS5 webhook notification handling: return notificat…
martinsaposnic May 21, 2025
ec934d9
Add LSPS5 module structure
martinsaposnic Mar 24, 2025
34f4e16
Integrate LSPS5 with liquidity manager
martinsaposnic Mar 24, 2025
9494b65
fixup: Refactor LSPS5 handlers and LiquidityManager to use generic Ti…
martinsaposnic May 21, 2025
a39cced
Add tests for LSPS5 client and service.
martinsaposnic Mar 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ use futures_util::{dummy_waker, OptionalSelector, Selector, SelectorOutput};
/// # use std::sync::atomic::{AtomicBool, Ordering};
/// # use std::time::SystemTime;
/// # use lightning_background_processor::{process_events_async, GossipSync};
/// # use lightning_liquidity::lsps5::service::TimeProvider;
/// # struct Logger {}
/// # impl lightning::util::logger::Logger for Logger {
/// # fn log(&self, _record: lightning::util::logger::Record) {}
Expand All @@ -658,6 +659,16 @@ use futures_util::{dummy_waker, OptionalSelector, Selector, SelectorOutput};
/// # fn remove(&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool) -> io::Result<()> { Ok(()) }
/// # fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> io::Result<Vec<String>> { Ok(Vec::new()) }
/// # }
/// #
/// # use core::time::Duration;
/// # struct DefaultTimeProvider;
/// #
/// # impl TimeProvider for DefaultTimeProvider {
/// # fn duration_since_epoch(&self) -> Duration {
/// # use std::time::{SystemTime, UNIX_EPOCH};
/// # SystemTime::now().duration_since(UNIX_EPOCH).expect("system time before Unix epoch")
/// # }
/// # }
/// # struct EventHandler {}
/// # impl EventHandler {
/// # async fn handle_event(&self, _: lightning::events::Event) -> Result<(), ReplayEvent> { Ok(()) }
Expand All @@ -673,7 +684,7 @@ use futures_util::{dummy_waker, OptionalSelector, Selector, SelectorOutput};
/// # type P2PGossipSync<UL> = lightning::routing::gossip::P2PGossipSync<Arc<NetworkGraph>, Arc<UL>, Arc<Logger>>;
/// # type ChannelManager<B, F, FE> = lightning::ln::channelmanager::SimpleArcChannelManager<ChainMonitor<B, F, FE>, B, FE, Logger>;
/// # type OnionMessenger<B, F, FE> = lightning::onion_message::messenger::OnionMessenger<Arc<lightning::sign::KeysManager>, Arc<lightning::sign::KeysManager>, Arc<Logger>, Arc<ChannelManager<B, F, FE>>, Arc<lightning::onion_message::messenger::DefaultMessageRouter<Arc<NetworkGraph>, Arc<Logger>, Arc<lightning::sign::KeysManager>>>, Arc<ChannelManager<B, F, FE>>, lightning::ln::peer_handler::IgnoringMessageHandler, lightning::ln::peer_handler::IgnoringMessageHandler, lightning::ln::peer_handler::IgnoringMessageHandler>;
/// # type LiquidityManager<B, F, FE> = lightning_liquidity::LiquidityManager<Arc<lightning::sign::KeysManager>, Arc<ChannelManager<B, F, FE>>, Arc<F>>;
/// # type LiquidityManager<B, F, FE> = lightning_liquidity::LiquidityManager<Arc<lightning::sign::KeysManager>, Arc<ChannelManager<B, F, FE>>, Arc<F>, Arc<DefaultTimeProvider>>;
/// # type Scorer = RwLock<lightning::routing::scoring::ProbabilisticScorer<Arc<NetworkGraph>, Arc<Logger>>>;
/// # type PeerManager<B, F, FE, UL> = lightning::ln::peer_handler::SimpleArcPeerManager<SocketDescriptor, ChainMonitor<B, F, FE>, B, FE, Arc<UL>, Logger>;
/// #
Expand Down Expand Up @@ -1189,6 +1200,7 @@ mod tests {
use lightning::util::sweep::{OutputSpendStatus, OutputSweeperSync, PRUNE_DELAY_BLOCKS};
use lightning::util::test_utils;
use lightning::{get_event, get_event_msg};
use lightning_liquidity::lsps5::service::TimeProvider;
use lightning_liquidity::LiquidityManager;
use lightning_persister::fs_store::FilesystemStore;
use lightning_rapid_gossip_sync::RapidGossipSync;
Expand Down Expand Up @@ -1284,8 +1296,12 @@ mod tests {
IgnoringMessageHandler,
>;

type LM =
LiquidityManager<Arc<KeysManager>, Arc<ChannelManager>, Arc<dyn Filter + Sync + Send>>;
type LM = LiquidityManager<
Arc<KeysManager>,
Arc<ChannelManager>,
Arc<dyn Filter + Sync + Send>,
Arc<DefaultTimeProvider>,
>;

struct Node {
node: Arc<ChannelManager>,
Expand Down Expand Up @@ -1625,6 +1641,16 @@ mod tests {
path.to_str().unwrap().to_string()
}

pub struct DefaultTimeProvider;

#[cfg(feature = "std")]
impl TimeProvider for DefaultTimeProvider {
fn duration_since_epoch(&self) -> Duration {
use std::time::{SystemTime, UNIX_EPOCH};
SystemTime::now().duration_since(UNIX_EPOCH).expect("system time before Unix epoch")
}
}

fn create_nodes(num_nodes: usize, persist_dir: &str) -> (String, Vec<Node>) {
let persist_temp_path = env::temp_dir().join(persist_dir);
let persist_dir = persist_temp_path.to_string_lossy().to_string();
Expand Down Expand Up @@ -1723,13 +1749,15 @@ mod tests {
logger.clone(),
keys_manager.clone(),
));
let liquidity_manager = Arc::new(LiquidityManager::new(
let time_provider = Arc::new(DefaultTimeProvider);
let liquidity_manager = Arc::new(LiquidityManager::new_with_custom_time_provider(
Arc::clone(&keys_manager),
Arc::clone(&manager),
None,
None,
None,
None,
time_provider,
));
let node = Node {
node: manager,
Expand Down
3 changes: 2 additions & 1 deletion lightning-liquidity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ categories = ["cryptography::cryptocurrencies"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["std"]
default = ["std", "time"]
std = ["lightning/std"]
time = ["std"]
backtrace = ["dep:backtrace"]

[dependencies]
Expand Down
17 changes: 17 additions & 0 deletions lightning-liquidity/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub use event_queue::MAX_EVENT_QUEUE_SIZE;
use crate::lsps0;
use crate::lsps1;
use crate::lsps2;
use crate::lsps5;

/// An event which you should probably take some action in response to.
#[derive(Debug, Clone, PartialEq, Eq)]
Expand All @@ -38,6 +39,10 @@ pub enum LiquidityEvent {
LSPS2Client(lsps2::event::LSPS2ClientEvent),
/// An LSPS2 (JIT Channel) server event.
LSPS2Service(lsps2::event::LSPS2ServiceEvent),
/// An LSPS5 (Webhook) client event.
LSPS5Client(lsps5::event::LSPS5ClientEvent),
/// An LSPS5 (Webhook) server event.
LSPS5Service(lsps5::event::LSPS5ServiceEvent),
}

impl From<lsps0::event::LSPS0ClientEvent> for LiquidityEvent {
Expand Down Expand Up @@ -70,3 +75,15 @@ impl From<lsps2::event::LSPS2ServiceEvent> for LiquidityEvent {
Self::LSPS2Service(event)
}
}

impl From<lsps5::event::LSPS5ClientEvent> for LiquidityEvent {
fn from(event: lsps5::event::LSPS5ClientEvent) -> Self {
Self::LSPS5Client(event)
}
}

impl From<lsps5::event::LSPS5ServiceEvent> for LiquidityEvent {
fn from(event: lsps5::event::LSPS5ServiceEvent) -> Self {
Self::LSPS5Service(event)
}
}
4 changes: 4 additions & 0 deletions lightning-liquidity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
//! an LSP will open a "just-in-time" channel. This is useful for the initial on-boarding of
//! clients as the channel opening fees are deducted from the incoming payment, i.e., no funds are
//! required client-side to initiate this flow.
//! - [bLIP-55 / LSPS5] defines a protocol for sending webhook notifications to clients. This is
//! useful for notifying clients about incoming payments, channel expiries, etc.
//!
//! To get started, you'll want to setup a [`LiquidityManager`] and configure it to be the
//! [`CustomMessageHandler`] of your LDK node. You can then for example call
Expand All @@ -37,6 +39,7 @@
//! [bLIP-50 / LSPS0]: https://github.com/lightning/blips/blob/master/blip-0050.md
//! [bLIP-51 / LSPS1]: https://github.com/lightning/blips/blob/master/blip-0051.md
//! [bLIP-52 / LSPS2]: https://github.com/lightning/blips/blob/master/blip-0052.md
//! [bLIP-55 / LSPS5]: https://github.com/lightning/blips/pull/55/files
//! [`CustomMessageHandler`]: lightning::ln::peer_handler::CustomMessageHandler
//! [`LiquidityManager::next_event`]: crate::LiquidityManager::next_event
#![deny(missing_docs)]
Expand All @@ -59,6 +62,7 @@ pub mod events;
pub mod lsps0;
pub mod lsps1;
pub mod lsps2;
pub mod lsps5;
mod manager;
pub mod message_queue;
#[allow(dead_code)]
Expand Down
1 change: 1 addition & 0 deletions lightning-liquidity/src/lsps0/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl TryFrom<LSPSMessage> for LSPS0Message {
LSPSMessage::LSPS0(message) => Ok(message),
LSPSMessage::LSPS1(_) => Err(()),
LSPSMessage::LSPS2(_) => Err(()),
LSPSMessage::LSPS5(_) => Err(()),
}
}
}
Expand Down
Loading
Loading