Skip to content

Commit 60e21ac

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 d474ca6 commit 60e21ac

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
@@ -2244,8 +2244,8 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
22442244
// We track whether we already emitted a `FundingTxBroadcastSafe` event.
22452245
funding_tx_broadcast_safe_event_emitted: bool,
22462246

2247-
// We track whether we already emitted a `ChannelReady` event.
2248-
channel_ready_event_emitted: bool,
2247+
// We track whether we already emitted an initial `ChannelReady` event.
2248+
initial_channel_ready_event_emitted: bool,
22492249

22502250
/// Some if we initiated to shut down the channel.
22512251
local_initiated_shutdown: Option<()>,
@@ -3054,7 +3054,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
30543054

30553055
channel_pending_event_emitted: false,
30563056
funding_tx_broadcast_safe_event_emitted: false,
3057-
channel_ready_event_emitted: false,
3057+
initial_channel_ready_event_emitted: false,
30583058

30593059
channel_keys_id,
30603060

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

32923292
channel_pending_event_emitted: false,
32933293
funding_tx_broadcast_safe_event_emitted: false,
3294-
channel_ready_event_emitted: false,
3294+
initial_channel_ready_event_emitted: false,
32953295

32963296
channel_keys_id,
32973297

@@ -3725,14 +3725,14 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
37253725
self.channel_pending_event_emitted = true;
37263726
}
37273727

3728-
// Checks whether we should emit a `ChannelReady` event.
3729-
pub(crate) fn should_emit_channel_ready_event(&mut self) -> bool {
3730-
self.is_usable() && !self.channel_ready_event_emitted
3728+
// Checks whether we should emit an initial `ChannelReady` event.
3729+
pub(crate) fn should_emit_initial_channel_ready_event(&mut self) -> bool {
3730+
self.is_usable() && !self.initial_channel_ready_event_emitted
37313731
}
37323732

37333733
// Remembers that we already emitted a `ChannelReady` event.
3734-
pub(crate) fn set_channel_ready_event_emitted(&mut self) {
3735-
self.channel_ready_event_emitted = true;
3734+
pub(crate) fn set_initial_channel_ready_event_emitted(&mut self) {
3735+
self.initial_channel_ready_event_emitted = true;
37363736
}
37373737

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

1121211212
let channel_pending_event_emitted = Some(self.context.channel_pending_event_emitted);
11213-
let channel_ready_event_emitted = Some(self.context.channel_ready_event_emitted);
11213+
let initial_channel_ready_event_emitted = Some(self.context.initial_channel_ready_event_emitted);
1121411214
let funding_tx_broadcast_safe_event_emitted = Some(self.context.funding_tx_broadcast_safe_event_emitted);
1121511215

1121611216
// `user_id` used to be a single u64 value. In order to remain backwards compatible with
@@ -11254,7 +11254,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1125411254
(17, self.context.announcement_sigs_state, required),
1125511255
(19, self.context.latest_inbound_scid_alias, option),
1125611256
(21, self.context.outbound_scid_alias, required),
11257-
(23, channel_ready_event_emitted, option),
11257+
(23, initial_channel_ready_event_emitted, option),
1125811258
(25, user_id_high_opt, option),
1125911259
(27, self.context.channel_keys_id, required),
1126011260
(28, holder_max_accepted_htlcs, option),
@@ -11559,7 +11559,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1155911559
let mut latest_inbound_scid_alias = None;
1156011560
let mut outbound_scid_alias = 0u64;
1156111561
let mut channel_pending_event_emitted = None;
11562-
let mut channel_ready_event_emitted = None;
11562+
let mut initial_channel_ready_event_emitted = None;
1156311563
let mut funding_tx_broadcast_safe_event_emitted = None;
1156411564

1156511565
let mut user_id_high_opt: Option<u64> = None;
@@ -11610,7 +11610,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1161011610
(17, announcement_sigs_state, required),
1161111611
(19, latest_inbound_scid_alias, option),
1161211612
(21, outbound_scid_alias, required),
11613-
(23, channel_ready_event_emitted, option),
11613+
(23, initial_channel_ready_event_emitted, option),
1161411614
(25, user_id_high_opt, option),
1161511615
(27, channel_keys_id, required),
1161611616
(28, holder_max_accepted_htlcs, option),
@@ -11911,7 +11911,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1191111911

1191211912
funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
1191311913
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
11914-
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
11914+
initial_channel_ready_event_emitted: initial_channel_ready_event_emitted.unwrap_or(true),
1191511915

1191611916
channel_keys_id,
1191711917

lightning/src/ln/channelmanager.rs

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

3223-
macro_rules! emit_channel_ready_event {
3223+
macro_rules! emit_initial_channel_ready_event {
32243224
($locked_events: expr, $channel: expr) => {
3225-
if $channel.context.should_emit_channel_ready_event() {
3225+
if $channel.context.should_emit_initial_channel_ready_event() {
32263226
debug_assert!($channel.context.channel_pending_event_emitted());
32273227
$locked_events.push_back((events::Event::ChannelReady {
32283228
channel_id: $channel.context.channel_id(),
32293229
user_channel_id: $channel.context.get_user_id(),
32303230
counterparty_node_id: $channel.context.get_counterparty_node_id(),
32313231
channel_type: $channel.funding.get_channel_type().clone(),
32323232
}, None));
3233-
$channel.context.set_channel_ready_event_emitted();
3233+
$channel.context.set_initial_channel_ready_event_emitted();
32343234
}
32353235
}
32363236
}
@@ -7771,7 +7771,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
77717771
{
77727772
let mut pending_events = self.pending_events.lock().unwrap();
77737773
emit_channel_pending_event!(pending_events, channel);
7774-
emit_channel_ready_event!(pending_events, channel);
7774+
emit_initial_channel_ready_event!(pending_events, channel);
77757775
}
77767776

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

87258725
{
87268726
let mut pending_events = self.pending_events.lock().unwrap();
8727-
emit_channel_ready_event!(pending_events, chan);
8727+
emit_initial_channel_ready_event!(pending_events, chan);
87288728
}
87298729

87308730
Ok(())
@@ -9660,6 +9660,14 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
96609660
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
96619661
insert_short_channel_id!(short_to_chan_info, chan);
96629662

9663+
let mut pending_events = self.pending_events.lock().unwrap();
9664+
pending_events.push_back((events::Event::ChannelReady {
9665+
channel_id: chan.context.channel_id(),
9666+
user_channel_id: chan.context.get_user_id(),
9667+
counterparty_node_id: chan.context.get_counterparty_node_id(),
9668+
channel_type: chan.funding.get_channel_type().clone(),
9669+
}, None));
9670+
96639671
log_trace!(logger, "Sending announcement_signatures for channel {}", chan.context.channel_id());
96649672
peer_state.pending_msg_events.push(MessageSendEvent::SendAnnouncementSignatures {
96659673
node_id: counterparty_node_id.clone(),
@@ -11821,6 +11829,14 @@ where
1182111829
if announcement_sigs.is_some() {
1182211830
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
1182311831
insert_short_channel_id!(short_to_chan_info, funded_channel);
11832+
11833+
let mut pending_events = self.pending_events.lock().unwrap();
11834+
pending_events.push_back((events::Event::ChannelReady {
11835+
channel_id: funded_channel.context.channel_id(),
11836+
user_channel_id: funded_channel.context.get_user_id(),
11837+
counterparty_node_id: funded_channel.context.get_counterparty_node_id(),
11838+
channel_type: funded_channel.funding.get_channel_type().clone(),
11839+
}, None));
1182411840
}
1182511841

1182611842
pending_msg_events.push(MessageSendEvent::SendSpliceLocked {
@@ -11833,7 +11849,7 @@ where
1183311849

1183411850
{
1183511851
let mut pending_events = self.pending_events.lock().unwrap();
11836-
emit_channel_ready_event!(pending_events, funded_channel);
11852+
emit_initial_channel_ready_event!(pending_events, funded_channel);
1183711853
}
1183811854

1183911855
if let Some(height) = height_opt {

0 commit comments

Comments
 (0)