Skip to content

Commit b89fc71

Browse files
LSPS4 Splicing (#12)
Instead of always opening new channels when outbound capacity is insufficient, prefer splicing into the largest existing usable channel. Falls back to new channel open when no usable channels exist. Key changes: - Add SpliceChannel event variant to LSPS4ServiceEvent - Add per-peer liquidity_cooldown to prevent 1Hz retry loops - Modify calculate_htlc_actions_for_peer to prefer splice over new channel - Add cooldown checks in execute_htlc_actions and process_pending_htlcs - Clear cooldown on channel_ready (covers both splice-lock and new channel) Use is_channel_ready instead of is_usable when selecting splice candidates. This ensures we prefer splice over new channel even during channel_reestablish (~1s window). splice_channel() will fail with "pending open/close" if the channel isn't usable yet, and the timer retries once reestablishment completes. --------- Co-authored-by: Martin Saposnic <martinsaposnic@gmail.com>
1 parent 55f7619 commit b89fc71

2 files changed

Lines changed: 258 additions & 37 deletions

File tree

lightning-liquidity/src/lsps4/event.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
use crate::lsps0::ser::LSPSRequestId;
1313
use std::string::String;
1414
use std::vec::Vec;
15+
use lightning::ln::types::ChannelId;
1516
use lightning_types::payment::PaymentHash;
1617

17-
18-
1918
use bitcoin::secp256k1::PublicKey;
2019

2120
/// An event which an LSPS4 client should take some action in response to.
@@ -63,4 +62,22 @@ pub enum LSPS4ServiceEvent {
6362
/// The number of channels currently open with the peer when the request is made.
6463
channel_count: usize,
6564
},
65+
/// You should splice into an existing channel to add capacity.
66+
///
67+
/// If the splice fails, fall back to opening a new channel using the same sizing policy
68+
/// as [`OpenChannel`].
69+
///
70+
/// [`OpenChannel`]: Self::OpenChannel
71+
SpliceChannel {
72+
/// The node whose channel to splice.
73+
their_network_key: PublicKey,
74+
/// The channel to splice into (the largest usable channel with this peer).
75+
channel_id: ChannelId,
76+
/// The user channel id, for diagnostics.
77+
user_channel_id: u128,
78+
/// Additional capacity needed (msat). The splice-in amount should be at least this.
79+
amt_to_forward_msat: u64,
80+
/// The number of channels currently open with the peer.
81+
channel_count: usize,
82+
},
6683
}

0 commit comments

Comments
 (0)