Skip to content

Commit b3a615f

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 0fb0ef1 commit b3a615f

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

2239-
// We track whether we already emitted a `ChannelReady` event.
2240-
channel_ready_event_emitted: bool,
2239+
// We track whether we already emitted an initial `ChannelReady` event.
2240+
initial_channel_ready_event_emitted: bool,
22412241

22422242
/// Some if we initiated to shut down the channel.
22432243
local_initiated_shutdown: Option<()>,
@@ -3045,7 +3045,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
30453045

30463046
channel_pending_event_emitted: false,
30473047
funding_tx_broadcast_safe_event_emitted: false,
3048-
channel_ready_event_emitted: false,
3048+
initial_channel_ready_event_emitted: false,
30493049

30503050
channel_keys_id,
30513051

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

32823282
channel_pending_event_emitted: false,
32833283
funding_tx_broadcast_safe_event_emitted: false,
3284-
channel_ready_event_emitted: false,
3284+
initial_channel_ready_event_emitted: false,
32853285

32863286
channel_keys_id,
32873287

@@ -3715,14 +3715,14 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
37153715
self.channel_pending_event_emitted = true;
37163716
}
37173717

3718-
// Checks whether we should emit a `ChannelReady` event.
3719-
pub(crate) fn should_emit_channel_ready_event(&mut self) -> bool {
3720-
self.is_usable() && !self.channel_ready_event_emitted
3718+
// Checks whether we should emit an initial `ChannelReady` event.
3719+
pub(crate) fn should_emit_initial_channel_ready_event(&mut self) -> bool {
3720+
self.is_usable() && !self.initial_channel_ready_event_emitted
37213721
}
37223722

37233723
// Remembers that we already emitted a `ChannelReady` event.
3724-
pub(crate) fn set_channel_ready_event_emitted(&mut self) {
3725-
self.channel_ready_event_emitted = true;
3724+
pub(crate) fn set_initial_channel_ready_event_emitted(&mut self) {
3725+
self.initial_channel_ready_event_emitted = true;
37263726
}
37273727

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

1119911199
let channel_pending_event_emitted = Some(self.context.channel_pending_event_emitted);
11200-
let channel_ready_event_emitted = Some(self.context.channel_ready_event_emitted);
11200+
let initial_channel_ready_event_emitted = Some(self.context.initial_channel_ready_event_emitted);
1120111201
let funding_tx_broadcast_safe_event_emitted = Some(self.context.funding_tx_broadcast_safe_event_emitted);
1120211202

1120311203
// `user_id` used to be a single u64 value. In order to remain backwards compatible with
@@ -11241,7 +11241,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1124111241
(17, self.context.announcement_sigs_state, required),
1124211242
(19, self.context.latest_inbound_scid_alias, option),
1124311243
(21, self.context.outbound_scid_alias, required),
11244-
(23, channel_ready_event_emitted, option),
11244+
(23, initial_channel_ready_event_emitted, option),
1124511245
(25, user_id_high_opt, option),
1124611246
(27, self.context.channel_keys_id, required),
1124711247
(28, holder_max_accepted_htlcs, option),
@@ -11545,7 +11545,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1154511545
let mut latest_inbound_scid_alias = None;
1154611546
let mut outbound_scid_alias = 0u64;
1154711547
let mut channel_pending_event_emitted = None;
11548-
let mut channel_ready_event_emitted = None;
11548+
let mut initial_channel_ready_event_emitted = None;
1154911549
let mut funding_tx_broadcast_safe_event_emitted = None;
1155011550

1155111551
let mut user_id_high_opt: Option<u64> = None;
@@ -11595,7 +11595,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1159511595
(17, announcement_sigs_state, required),
1159611596
(19, latest_inbound_scid_alias, option),
1159711597
(21, outbound_scid_alias, required),
11598-
(23, channel_ready_event_emitted, option),
11598+
(23, initial_channel_ready_event_emitted, option),
1159911599
(25, user_id_high_opt, option),
1160011600
(27, channel_keys_id, required),
1160111601
(28, holder_max_accepted_htlcs, option),
@@ -11894,7 +11894,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1189411894

1189511895
funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
1189611896
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
11897-
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
11897+
initial_channel_ready_event_emitted: initial_channel_ready_event_emitted.unwrap_or(true),
1189811898

1189911899
channel_keys_id,
1190011900

lightning/src/ln/channelmanager.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3217,17 +3217,17 @@ macro_rules! emit_channel_pending_event {
32173217
}
32183218
}
32193219

3220-
macro_rules! emit_channel_ready_event {
3220+
macro_rules! emit_initial_channel_ready_event {
32213221
($locked_events: expr, $channel: expr) => {
3222-
if $channel.context.should_emit_channel_ready_event() {
3222+
if $channel.context.should_emit_initial_channel_ready_event() {
32233223
debug_assert!($channel.context.channel_pending_event_emitted());
32243224
$locked_events.push_back((events::Event::ChannelReady {
32253225
channel_id: $channel.context.channel_id(),
32263226
user_channel_id: $channel.context.get_user_id(),
32273227
counterparty_node_id: $channel.context.get_counterparty_node_id(),
32283228
channel_type: $channel.funding.get_channel_type().clone(),
32293229
}, None));
3230-
$channel.context.set_channel_ready_event_emitted();
3230+
$channel.context.set_initial_channel_ready_event_emitted();
32313231
}
32323232
}
32333233
}
@@ -7768,7 +7768,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
77687768
{
77697769
let mut pending_events = self.pending_events.lock().unwrap();
77707770
emit_channel_pending_event!(pending_events, channel);
7771-
emit_channel_ready_event!(pending_events, channel);
7771+
emit_initial_channel_ready_event!(pending_events, channel);
77727772
}
77737773

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

87228722
{
87238723
let mut pending_events = self.pending_events.lock().unwrap();
8724-
emit_channel_ready_event!(pending_events, chan);
8724+
emit_initial_channel_ready_event!(pending_events, chan);
87258725
}
87268726

87278727
Ok(())
@@ -9657,6 +9657,14 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
96579657
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
96589658
insert_short_channel_id!(short_to_chan_info, chan);
96599659

9660+
let mut pending_events = self.pending_events.lock().unwrap();
9661+
pending_events.push_back((events::Event::ChannelReady {
9662+
channel_id: chan.context.channel_id(),
9663+
user_channel_id: chan.context.get_user_id(),
9664+
counterparty_node_id: chan.context.get_counterparty_node_id(),
9665+
channel_type: chan.funding.get_channel_type().clone(),
9666+
}, None));
9667+
96609668
log_trace!(logger, "Sending announcement_signatures for channel {}", chan.context.channel_id());
96619669
peer_state.pending_msg_events.push(MessageSendEvent::SendAnnouncementSignatures {
96629670
node_id: counterparty_node_id.clone(),
@@ -11807,6 +11815,14 @@ where
1180711815
if announcement_sigs.is_some() {
1180811816
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
1180911817
insert_short_channel_id!(short_to_chan_info, funded_channel);
11818+
11819+
let mut pending_events = self.pending_events.lock().unwrap();
11820+
pending_events.push_back((events::Event::ChannelReady {
11821+
channel_id: funded_channel.context.channel_id(),
11822+
user_channel_id: funded_channel.context.get_user_id(),
11823+
counterparty_node_id: funded_channel.context.get_counterparty_node_id(),
11824+
channel_type: funded_channel.funding.get_channel_type().clone(),
11825+
}, None));
1181011826
}
1181111827

1181211828
pending_msg_events.push(MessageSendEvent::SendSpliceLocked {
@@ -11819,7 +11835,7 @@ where
1181911835

1182011836
{
1182111837
let mut pending_events = self.pending_events.lock().unwrap();
11822-
emit_channel_ready_event!(pending_events, funded_channel);
11838+
emit_initial_channel_ready_event!(pending_events, funded_channel);
1182311839
}
1182411840

1182511841
if let Some(height) = height_opt {

0 commit comments

Comments
 (0)