Skip to content

Commit 0cb7874

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 a06a7de commit 0cb7874

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

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

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

30543054
channel_pending_event_emitted: false,
30553055
funding_tx_broadcast_safe_event_emitted: false,
3056-
channel_ready_event_emitted: false,
3056+
initial_channel_ready_event_emitted: false,
30573057

30583058
channel_keys_id,
30593059

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

32913291
channel_pending_event_emitted: false,
32923292
funding_tx_broadcast_safe_event_emitted: false,
3293-
channel_ready_event_emitted: false,
3293+
initial_channel_ready_event_emitted: false,
32943294

32953295
channel_keys_id,
32963296

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

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

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

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

1121911219
let channel_pending_event_emitted = Some(self.context.channel_pending_event_emitted);
11220-
let channel_ready_event_emitted = Some(self.context.channel_ready_event_emitted);
11220+
let initial_channel_ready_event_emitted = Some(self.context.initial_channel_ready_event_emitted);
1122111221
let funding_tx_broadcast_safe_event_emitted = Some(self.context.funding_tx_broadcast_safe_event_emitted);
1122211222

1122311223
// `user_id` used to be a single u64 value. In order to remain backwards compatible with
@@ -11261,7 +11261,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1126111261
(17, self.context.announcement_sigs_state, required),
1126211262
(19, self.context.latest_inbound_scid_alias, option),
1126311263
(21, self.context.outbound_scid_alias, required),
11264-
(23, channel_ready_event_emitted, option),
11264+
(23, initial_channel_ready_event_emitted, option),
1126511265
(25, user_id_high_opt, option),
1126611266
(27, self.context.channel_keys_id, required),
1126711267
(28, holder_max_accepted_htlcs, option),
@@ -11566,7 +11566,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1156611566
let mut latest_inbound_scid_alias = None;
1156711567
let mut outbound_scid_alias = 0u64;
1156811568
let mut channel_pending_event_emitted = None;
11569-
let mut channel_ready_event_emitted = None;
11569+
let mut initial_channel_ready_event_emitted = None;
1157011570
let mut funding_tx_broadcast_safe_event_emitted = None;
1157111571

1157211572
let mut user_id_high_opt: Option<u64> = None;
@@ -11617,7 +11617,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1161711617
(17, announcement_sigs_state, required),
1161811618
(19, latest_inbound_scid_alias, option),
1161911619
(21, outbound_scid_alias, required),
11620-
(23, channel_ready_event_emitted, option),
11620+
(23, initial_channel_ready_event_emitted, option),
1162111621
(25, user_id_high_opt, option),
1162211622
(27, channel_keys_id, required),
1162311623
(28, holder_max_accepted_htlcs, option),
@@ -11918,7 +11918,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1191811918

1191911919
funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
1192011920
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
11921-
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
11921+
initial_channel_ready_event_emitted: initial_channel_ready_event_emitted.unwrap_or(true),
1192211922

1192311923
channel_keys_id,
1192411924

lightning/src/ln/channelmanager.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3225,17 +3225,17 @@ macro_rules! emit_channel_pending_event {
32253225
}
32263226
}
32273227

3228-
macro_rules! emit_channel_ready_event {
3228+
macro_rules! emit_initial_channel_ready_event {
32293229
($locked_events: expr, $channel: expr) => {
3230-
if $channel.context.should_emit_channel_ready_event() {
3230+
if $channel.context.should_emit_initial_channel_ready_event() {
32313231
debug_assert!($channel.context.channel_pending_event_emitted());
32323232
$locked_events.push_back((events::Event::ChannelReady {
32333233
channel_id: $channel.context.channel_id(),
32343234
user_channel_id: $channel.context.get_user_id(),
32353235
counterparty_node_id: $channel.context.get_counterparty_node_id(),
32363236
channel_type: $channel.funding.get_channel_type().clone(),
32373237
}, None));
3238-
$channel.context.set_channel_ready_event_emitted();
3238+
$channel.context.set_initial_channel_ready_event_emitted();
32393239
}
32403240
}
32413241
}
@@ -7776,7 +7776,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
77767776
{
77777777
let mut pending_events = self.pending_events.lock().unwrap();
77787778
emit_channel_pending_event!(pending_events, channel);
7779-
emit_channel_ready_event!(pending_events, channel);
7779+
emit_initial_channel_ready_event!(pending_events, channel);
77807780
}
77817781

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

87308730
{
87318731
let mut pending_events = self.pending_events.lock().unwrap();
8732-
emit_channel_ready_event!(pending_events, chan);
8732+
emit_initial_channel_ready_event!(pending_events, chan);
87338733
}
87348734

87358735
Ok(())
@@ -9665,6 +9665,14 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
96659665
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
96669666
insert_short_channel_id!(short_to_chan_info, chan);
96679667

9668+
let mut pending_events = self.pending_events.lock().unwrap();
9669+
pending_events.push_back((events::Event::ChannelReady {
9670+
channel_id: chan.context.channel_id(),
9671+
user_channel_id: chan.context.get_user_id(),
9672+
counterparty_node_id: chan.context.get_counterparty_node_id(),
9673+
channel_type: chan.funding.get_channel_type().clone(),
9674+
}, None));
9675+
96689676
log_trace!(logger, "Sending announcement_signatures for channel {}", chan.context.channel_id());
96699677
peer_state.pending_msg_events.push(MessageSendEvent::SendAnnouncementSignatures {
96709678
node_id: counterparty_node_id.clone(),
@@ -11838,6 +11846,14 @@ where
1183811846
if announcement_sigs.is_some() {
1183911847
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
1184011848
insert_short_channel_id!(short_to_chan_info, funded_channel);
11849+
11850+
let mut pending_events = self.pending_events.lock().unwrap();
11851+
pending_events.push_back((events::Event::ChannelReady {
11852+
channel_id: funded_channel.context.channel_id(),
11853+
user_channel_id: funded_channel.context.get_user_id(),
11854+
counterparty_node_id: funded_channel.context.get_counterparty_node_id(),
11855+
channel_type: funded_channel.funding.get_channel_type().clone(),
11856+
}, None));
1184111857
}
1184211858

1184311859
pending_msg_events.push(MessageSendEvent::SendSpliceLocked {
@@ -11850,7 +11866,7 @@ where
1185011866

1185111867
{
1185211868
let mut pending_events = self.pending_events.lock().unwrap();
11853-
emit_channel_ready_event!(pending_events, funded_channel);
11869+
emit_initial_channel_ready_event!(pending_events, funded_channel);
1185411870
}
1185511871

1185611872
if let Some(height) = height_opt {

0 commit comments

Comments
 (0)