Skip to content

Commit d414ba9

Browse files
authored
Merge pull request #3493 from tnull/2024-12-3436-followup
Follow-ups to #3436
2 parents 42cc4e7 + dd91418 commit d414ba9

File tree

5 files changed

+35
-17
lines changed

5 files changed

+35
-17
lines changed

lightning-liquidity/README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
The goal of this crate is to provide types and primitives to integrate a spec-compliant LSP with an LDK-based node. To this end, this crate provides client-side as well as service-side logic to implement the [LSP specifications].
44

5+
**Note**: Service-side support is currently considered "beta", i.e., not fully
6+
ready for production use.
7+
58
Currently the following specifications are supported:
69
- [LSPS0] defines the transport protocol with the LSP over which the other protocols communicate.
710
- [LSPS1] allows to order Lightning channels from an LSP. This is useful when the client needs
811
inbound Lightning liquidity for which they are willing and able to pay in bitcoin.
9-
- [LSPS2] allows to generate a special invoice for which, when paid, an LSP will open a "just-in-time".
10-
This is useful for the initial on-boarding of clients as the channel opening fees are deducted
11-
from the incoming payment, i.e., no funds are required client-side to initiate this flow.
12+
- [LSPS2] allows to generate a special invoice for which, when paid, an LSP
13+
will open a "just-in-time" channel. This is useful for the initial
14+
on-boarding of clients as the channel opening fees are deducted from the
15+
incoming payment, i.e., no funds are required client-side to initiate this
16+
flow.
1217

1318
To get started, you'll want to setup a `LiquidityManager` and configure it to be the `CustomMessageHandler` of your LDK node. You can then call `LiquidityManager::lsps1_client_handler` / `LiquidityManager::lsps2_client_handler`, or `LiquidityManager::lsps2_service_handler`, to access the respective client-side or service-side handlers.
1419

lightning-liquidity/src/lib.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010

1111
//! The goal of this crate is to provide types and primitives to integrate a spec-compliant LSP with an LDK-based node. To this end, this crate provides client-side as well as service-side logic to implement the [LSP specifications].
1212
//!
13+
//! **Note**: Service-side support is currently considered "beta", i.e., not fully ready for
14+
//! production use.
15+
//!
1316
//! Currently the following specifications are supported:
1417
//! - [LSPS0] defines the transport protocol with the LSP over which the other protocols communicate.
1518
//! - [LSPS1] allows to order Lightning channels from an LSP. This is useful when the client needs
1619
//! inbound Lightning liquidity for which they are willing and able to pay in bitcoin.
17-
//! - [LSPS2] allows to generate a special invoice for which, when paid, an LSP will open a "just-in-time".
18-
//! This is useful for the initial on-boarding of clients as the channel opening fees are deducted
19-
//! from the incoming payment, i.e., no funds are required client-side to initiate this flow.
20+
//! - [LSPS2] allows to generate a special invoice for which, when paid, an LSP will open a
21+
//! "just-in-time" channel. This is useful for the initial on-boarding of clients as the channel
22+
//! opening fees are deducted from the incoming payment, i.e., no funds are required client-side to
23+
//! initiate this flow.
2024
//!
2125
//! To get started, you'll want to setup a [`LiquidityManager`] and configure it to be the
2226
//! [`CustomMessageHandler`] of your LDK node. You can then for example call

lightning-liquidity/src/lsps0/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Contains the main LSPS2 client-side object, [`LSPS0ClientHandler`].
1+
//! Contains the main LSPS0 client-side object, [`LSPS0ClientHandler`].
22
//!
33
//! Please refer to the [LSPS0
44
//! specifcation](https://github.com/BitcoinAndLightningLayerSpecs/lsp/tree/main/LSPS0) for more

lightning-liquidity/src/lsps0/msgs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Message, request, and other primitive types used to implement LSPS1.
1+
//! Message, request, and other primitive types used to implement LSPS0.
22
33
use crate::lsps0::ser::{LSPSMessage, RequestId, ResponseError};
44
use crate::prelude::Vec;

lightning-liquidity/src/manager.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,18 @@ pub struct LiquidityClientConfig {
7575
/// Users need to continually poll [`LiquidityManager::get_and_clear_pending_events`] in order to surface
7676
/// [`Event`]'s that likely need to be handled.
7777
///
78-
/// If configured, users must forward the [`Event::HTLCIntercepted`] event parameters to [`LSPS2ServiceHandler::htlc_intercepted`]
79-
/// and the [`Event::ChannelReady`] event parameters to [`LSPS2ServiceHandler::channel_ready`].
78+
/// If the LSPS2 service is configured, users must forward the following parameters from LDK events:
79+
/// - [`Event::HTLCIntercepted`] to [`LSPS2ServiceHandler::htlc_intercepted`]
80+
/// - [`Event::ChannelReady`] to [`LSPS2ServiceHandler::channel_ready`]
81+
/// - [`Event::HTLCHandlingFailed`] to [`LSPS2ServiceHandler::htlc_handling_failed`]
82+
/// - [`Event::PaymentForwarded`] to [`LSPS2ServiceHandler::payment_forwarded`]
8083
///
8184
/// [`PeerManager`]: lightning::ln::peer_handler::PeerManager
8285
/// [`MessageHandler`]: lightning::ln::peer_handler::MessageHandler
8386
/// [`Event::HTLCIntercepted`]: lightning::events::Event::HTLCIntercepted
8487
/// [`Event::ChannelReady`]: lightning::events::Event::ChannelReady
88+
/// [`Event::HTLCHandlingFailed`]: lightning::events::Event::HTLCHandlingFailed
89+
/// [`Event::PaymentForwarded`]: lightning::events::Event::PaymentForwarded
8590
pub struct LiquidityManager<ES: Deref + Clone, CM: Deref + Clone, C: Deref + Clone>
8691
where
8792
ES::Target: EntropySource,
@@ -102,7 +107,7 @@ where
102107
lsps2_client_handler: Option<LSPS2ClientHandler<ES>>,
103108
service_config: Option<LiquidityServiceConfig>,
104109
_client_config: Option<LiquidityClientConfig>,
105-
best_block: Option<RwLock<BestBlock>>,
110+
best_block: RwLock<Option<BestBlock>>,
106111
_chain_source: Option<C>,
107112
}
108113

@@ -210,7 +215,7 @@ where {
210215
lsps2_service_handler,
211216
service_config,
212217
_client_config: client_config,
213-
best_block: chain_params.map(|chain_params| RwLock::new(chain_params.best_block)),
218+
best_block: RwLock::new(chain_params.map(|chain_params| chain_params.best_block)),
214219
_chain_source: chain_source,
215220
}
216221
}
@@ -613,6 +618,9 @@ where
613618
}
614619

615620
fn peer_disconnected(&self, counterparty_node_id: bitcoin::secp256k1::PublicKey) {
621+
// If the peer was misbehaving, drop it from the ignored list to cleanup the kept state.
622+
self.ignored_peers.write().unwrap().remove(&counterparty_node_id);
623+
616624
if let Some(lsps2_service_handler) = self.lsps2_service_handler.as_ref() {
617625
lsps2_service_handler.peer_disconnected(counterparty_node_id);
618626
}
@@ -634,8 +642,7 @@ where
634642
&self, header: &bitcoin::block::Header, txdata: &chain::transaction::TransactionData,
635643
height: u32,
636644
) {
637-
if let Some(best_block) = &self.best_block {
638-
let best_block = best_block.read().unwrap();
645+
if let Some(best_block) = self.best_block.read().unwrap().as_ref() {
639646
assert_eq!(best_block.block_hash, header.prev_blockhash,
640647
"Blocks must be connected in chain-order - the connected header must build on the last connected header");
641648
assert_eq!(best_block.height, height - 1,
@@ -648,8 +655,7 @@ where
648655

649656
fn block_disconnected(&self, header: &bitcoin::block::Header, height: u32) {
650657
let new_height = height - 1;
651-
if let Some(best_block) = &self.best_block {
652-
let mut best_block = best_block.write().unwrap();
658+
if let Some(best_block) = self.best_block.write().unwrap().as_mut() {
653659
assert_eq!(best_block.block_hash, header.block_hash(),
654660
"Blocks must be disconnected in chain-order - the disconnected header must be the last connected header");
655661
assert_eq!(best_block.height, height,
@@ -682,7 +688,10 @@ where
682688
// confirmed at a height <= the one we now unconfirmed.
683689
}
684690

685-
fn best_block_updated(&self, _header: &bitcoin::block::Header, _height: u32) {
691+
fn best_block_updated(&self, header: &bitcoin::block::Header, height: u32) {
692+
let new_best_block = BestBlock::new(header.block_hash(), height);
693+
*self.best_block.write().unwrap() = Some(new_best_block);
694+
686695
// TODO: Call best_block_updated on all sub-modules that require it, e.g., LSPS1MessageHandler.
687696
if let Some(lsps2_service_handler) = self.lsps2_service_handler.as_ref() {
688697
lsps2_service_handler.prune_peer_state();

0 commit comments

Comments
 (0)