Skip to content

Commit 0f528b3

Browse files
committed
Emit SpliceLocked event
Once both parties have exchanged splice_locked messages, the splice funding is ready for use. Emit an event to the user indicating as much.
1 parent 9cb486b commit 0f528b3

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
lines changed

lightning/src/events/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,10 +1353,13 @@ pub enum Event {
13531353
/// Will be `None` for channels created prior to LDK version 0.0.122.
13541354
channel_type: Option<ChannelTypeFeatures>,
13551355
},
1356-
/// Used to indicate that a channel with the given `channel_id` is ready to
1357-
/// be used. This event is emitted either when the funding transaction has been confirmed
1358-
/// on-chain, or, in case of a 0conf channel, when both parties have confirmed the channel
1359-
/// establishment.
1356+
/// Used to indicate that a channel with the given `channel_id` is ready to be used. This event
1357+
/// is emitted when
1358+
/// - the initial funding transaction has been confirmed on-chain to an acceptable depth
1359+
/// according to both parties (i.e., `channel_ready` messages were exchanged),
1360+
/// - a splice funding transaction has been confirmed on-chain to an acceptable depth according
1361+
/// to both parties (i.e., `splice_locked` messages were exchanged), or,
1362+
/// - in case of a 0conf channel, when both parties have confirmed the channel establishment.
13601363
///
13611364
/// # Failure Behavior and Persistence
13621365
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler

lightning/src/ln/channel.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,8 +2290,8 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
22902290
// We track whether we already emitted a `FundingTxBroadcastSafe` event.
22912291
funding_tx_broadcast_safe_event_emitted: bool,
22922292

2293-
// We track whether we already emitted a `ChannelReady` event.
2294-
channel_ready_event_emitted: bool,
2293+
// We track whether we already emitted an initial `ChannelReady` event.
2294+
initial_channel_ready_event_emitted: bool,
22952295

22962296
/// Some if we initiated to shut down the channel.
22972297
local_initiated_shutdown: Option<()>,
@@ -3105,7 +3105,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
31053105

31063106
channel_pending_event_emitted: false,
31073107
funding_tx_broadcast_safe_event_emitted: false,
3108-
channel_ready_event_emitted: false,
3108+
initial_channel_ready_event_emitted: false,
31093109

31103110
channel_keys_id,
31113111

@@ -3341,7 +3341,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
33413341

33423342
channel_pending_event_emitted: false,
33433343
funding_tx_broadcast_safe_event_emitted: false,
3344-
channel_ready_event_emitted: false,
3344+
initial_channel_ready_event_emitted: false,
33453345

33463346
channel_keys_id,
33473347

@@ -3760,14 +3760,14 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
37603760
self.channel_pending_event_emitted = true;
37613761
}
37623762

3763-
// Checks whether we should emit a `ChannelReady` event.
3764-
pub(crate) fn should_emit_channel_ready_event(&mut self) -> bool {
3765-
self.is_usable() && !self.channel_ready_event_emitted
3763+
// Checks whether we should emit an initial `ChannelReady` event.
3764+
pub(crate) fn should_emit_initial_channel_ready_event(&mut self) -> bool {
3765+
self.is_usable() && !self.initial_channel_ready_event_emitted
37663766
}
37673767

37683768
// Remembers that we already emitted a `ChannelReady` event.
3769-
pub(crate) fn set_channel_ready_event_emitted(&mut self) {
3770-
self.channel_ready_event_emitted = true;
3769+
pub(crate) fn set_initial_channel_ready_event_emitted(&mut self) {
3770+
self.initial_channel_ready_event_emitted = true;
37713771
}
37723772

37733773
// Remembers that we already emitted a `FundingTxBroadcastSafe` event.
@@ -11505,7 +11505,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1150511505
{ Some(self.context.holder_max_htlc_value_in_flight_msat) } else { None };
1150611506

1150711507
let channel_pending_event_emitted = Some(self.context.channel_pending_event_emitted);
11508-
let channel_ready_event_emitted = Some(self.context.channel_ready_event_emitted);
11508+
let initial_channel_ready_event_emitted = Some(self.context.initial_channel_ready_event_emitted);
1150911509
let funding_tx_broadcast_safe_event_emitted = Some(self.context.funding_tx_broadcast_safe_event_emitted);
1151011510

1151111511
// `user_id` used to be a single u64 value. In order to remain backwards compatible with
@@ -11549,7 +11549,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1154911549
(17, self.context.announcement_sigs_state, required),
1155011550
(19, self.context.latest_inbound_scid_alias, option),
1155111551
(21, self.context.outbound_scid_alias, required),
11552-
(23, channel_ready_event_emitted, option),
11552+
(23, initial_channel_ready_event_emitted, option),
1155311553
(25, user_id_high_opt, option),
1155411554
(27, self.context.channel_keys_id, required),
1155511555
(28, holder_max_accepted_htlcs, option),
@@ -11856,7 +11856,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1185611856
let mut latest_inbound_scid_alias = None;
1185711857
let mut outbound_scid_alias = 0u64;
1185811858
let mut channel_pending_event_emitted = None;
11859-
let mut channel_ready_event_emitted = None;
11859+
let mut initial_channel_ready_event_emitted = None;
1186011860
let mut funding_tx_broadcast_safe_event_emitted = None;
1186111861

1186211862
let mut user_id_high_opt: Option<u64> = None;
@@ -11911,7 +11911,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1191111911
(17, announcement_sigs_state, required),
1191211912
(19, latest_inbound_scid_alias, option),
1191311913
(21, outbound_scid_alias, required),
11914-
(23, channel_ready_event_emitted, option),
11914+
(23, initial_channel_ready_event_emitted, option),
1191511915
(25, user_id_high_opt, option),
1191611916
(27, channel_keys_id, required),
1191711917
(28, holder_max_accepted_htlcs, option),
@@ -12211,7 +12211,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1221112211

1221212212
funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
1221312213
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
12214-
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
12214+
initial_channel_ready_event_emitted: initial_channel_ready_event_emitted.unwrap_or(true),
1221512215

1221612216
channel_keys_id,
1221712217

lightning/src/ln/channelmanager.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,17 +3222,17 @@ macro_rules! emit_channel_pending_event {
32223222
}
32233223
}
32243224

3225-
macro_rules! emit_channel_ready_event {
3225+
macro_rules! emit_initial_channel_ready_event {
32263226
($locked_events: expr, $channel: expr) => {
3227-
if $channel.context.should_emit_channel_ready_event() {
3227+
if $channel.context.should_emit_initial_channel_ready_event() {
32283228
debug_assert!($channel.context.channel_pending_event_emitted());
32293229
$locked_events.push_back((events::Event::ChannelReady {
32303230
channel_id: $channel.context.channel_id(),
32313231
user_channel_id: $channel.context.get_user_id(),
32323232
counterparty_node_id: $channel.context.get_counterparty_node_id(),
32333233
channel_type: $channel.funding.get_channel_type().clone(),
32343234
}, None));
3235-
$channel.context.set_channel_ready_event_emitted();
3235+
$channel.context.set_initial_channel_ready_event_emitted();
32363236
}
32373237
}
32383238
}
@@ -7780,7 +7780,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
77807780
{
77817781
let mut pending_events = self.pending_events.lock().unwrap();
77827782
emit_channel_pending_event!(pending_events, channel);
7783-
emit_channel_ready_event!(pending_events, channel);
7783+
emit_initial_channel_ready_event!(pending_events, channel);
77847784
}
77857785

77867786
(htlc_forwards, decode_update_add_htlcs)
@@ -8733,7 +8733,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
87338733

87348734
{
87358735
let mut pending_events = self.pending_events.lock().unwrap();
8736-
emit_channel_ready_event!(pending_events, chan);
8736+
emit_initial_channel_ready_event!(pending_events, chan);
87378737
}
87388738

87398739
Ok(())
@@ -9670,6 +9670,14 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
96709670
if !chan.has_pending_splice() {
96719671
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
96729672
insert_short_channel_id!(short_to_chan_info, chan);
9673+
9674+
let mut pending_events = self.pending_events.lock().unwrap();
9675+
pending_events.push_back((events::Event::ChannelReady {
9676+
channel_id: chan.context.channel_id(),
9677+
user_channel_id: chan.context.get_user_id(),
9678+
counterparty_node_id: chan.context.get_counterparty_node_id(),
9679+
channel_type: chan.funding.get_channel_type().clone(),
9680+
}, None));
96739681
}
96749682

96759683
if let Some(announcement_sigs) = announcement_sigs_opt {
@@ -11835,6 +11843,14 @@ where
1183511843
if !funded_channel.has_pending_splice() {
1183611844
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
1183711845
insert_short_channel_id!(short_to_chan_info, funded_channel);
11846+
11847+
let mut pending_events = self.pending_events.lock().unwrap();
11848+
pending_events.push_back((events::Event::ChannelReady {
11849+
channel_id: funded_channel.context.channel_id(),
11850+
user_channel_id: funded_channel.context.get_user_id(),
11851+
counterparty_node_id: funded_channel.context.get_counterparty_node_id(),
11852+
channel_type: funded_channel.funding.get_channel_type().clone(),
11853+
}, None));
1183811854
}
1183911855

1184011856
pending_msg_events.push(MessageSendEvent::SendSpliceLocked {
@@ -11847,7 +11863,7 @@ where
1184711863

1184811864
{
1184911865
let mut pending_events = self.pending_events.lock().unwrap();
11850-
emit_channel_ready_event!(pending_events, funded_channel);
11866+
emit_initial_channel_ready_event!(pending_events, funded_channel);
1185111867
}
1185211868

1185311869
if let Some(height) = height_opt {

0 commit comments

Comments
 (0)