Skip to content

Commit 0f4a8fb

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 8c6e969 commit 0f4a8fb

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

2298-
// We track whether we already emitted a `ChannelReady` event.
2299-
channel_ready_event_emitted: bool,
2298+
// We track whether we already emitted an initial `ChannelReady` event.
2299+
initial_channel_ready_event_emitted: bool,
23002300

23012301
/// Some if we initiated to shut down the channel.
23022302
local_initiated_shutdown: Option<()>,
@@ -3110,7 +3110,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
31103110

31113111
channel_pending_event_emitted: false,
31123112
funding_tx_broadcast_safe_event_emitted: false,
3113-
channel_ready_event_emitted: false,
3113+
initial_channel_ready_event_emitted: false,
31143114

31153115
channel_keys_id,
31163116

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

33533353
channel_pending_event_emitted: false,
33543354
funding_tx_broadcast_safe_event_emitted: false,
3355-
channel_ready_event_emitted: false,
3355+
initial_channel_ready_event_emitted: false,
33563356

33573357
channel_keys_id,
33583358

@@ -3771,14 +3771,14 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
37713771
self.channel_pending_event_emitted = true;
37723772
}
37733773

3774-
// Checks whether we should emit a `ChannelReady` event.
3775-
pub(crate) fn should_emit_channel_ready_event(&mut self) -> bool {
3776-
self.is_usable() && !self.channel_ready_event_emitted
3774+
// Checks whether we should emit an initial `ChannelReady` event.
3775+
pub(crate) fn should_emit_initial_channel_ready_event(&mut self) -> bool {
3776+
self.is_usable() && !self.initial_channel_ready_event_emitted
37773777
}
37783778

37793779
// Remembers that we already emitted a `ChannelReady` event.
3780-
pub(crate) fn set_channel_ready_event_emitted(&mut self) {
3781-
self.channel_ready_event_emitted = true;
3780+
pub(crate) fn set_initial_channel_ready_event_emitted(&mut self) {
3781+
self.initial_channel_ready_event_emitted = true;
37823782
}
37833783

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

1163511635
let channel_pending_event_emitted = Some(self.context.channel_pending_event_emitted);
11636-
let channel_ready_event_emitted = Some(self.context.channel_ready_event_emitted);
11636+
let initial_channel_ready_event_emitted = Some(self.context.initial_channel_ready_event_emitted);
1163711637
let funding_tx_broadcast_safe_event_emitted = Some(self.context.funding_tx_broadcast_safe_event_emitted);
1163811638

1163911639
// `user_id` used to be a single u64 value. In order to remain backwards compatible with
@@ -11677,7 +11677,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1167711677
(17, self.context.announcement_sigs_state, required),
1167811678
(19, self.context.latest_inbound_scid_alias, option),
1167911679
(21, self.context.outbound_scid_alias, required),
11680-
(23, channel_ready_event_emitted, option),
11680+
(23, initial_channel_ready_event_emitted, option),
1168111681
(25, user_id_high_opt, option),
1168211682
(27, self.context.channel_keys_id, required),
1168311683
(28, holder_max_accepted_htlcs, option),
@@ -11984,7 +11984,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1198411984
let mut latest_inbound_scid_alias = None;
1198511985
let mut outbound_scid_alias = 0u64;
1198611986
let mut channel_pending_event_emitted = None;
11987-
let mut channel_ready_event_emitted = None;
11987+
let mut initial_channel_ready_event_emitted = None;
1198811988
let mut funding_tx_broadcast_safe_event_emitted = None;
1198911989

1199011990
let mut user_id_high_opt: Option<u64> = None;
@@ -12039,7 +12039,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1203912039
(17, announcement_sigs_state, required),
1204012040
(19, latest_inbound_scid_alias, option),
1204112041
(21, outbound_scid_alias, required),
12042-
(23, channel_ready_event_emitted, option),
12042+
(23, initial_channel_ready_event_emitted, option),
1204312043
(25, user_id_high_opt, option),
1204412044
(27, channel_keys_id, required),
1204512045
(28, holder_max_accepted_htlcs, option),
@@ -12339,7 +12339,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1233912339

1234012340
funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
1234112341
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
12342-
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
12342+
initial_channel_ready_event_emitted: initial_channel_ready_event_emitted.unwrap_or(true),
1234312343

1234412344
channel_keys_id,
1234512345

lightning/src/ln/channelmanager.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3333,17 +3333,17 @@ macro_rules! emit_channel_pending_event {
33333333
}
33343334

33353335
#[rustfmt::skip]
3336-
macro_rules! emit_channel_ready_event {
3336+
macro_rules! emit_initial_channel_ready_event {
33373337
($locked_events: expr, $channel: expr) => {
3338-
if $channel.context.should_emit_channel_ready_event() {
3338+
if $channel.context.should_emit_initial_channel_ready_event() {
33393339
debug_assert!($channel.context.channel_pending_event_emitted());
33403340
$locked_events.push_back((events::Event::ChannelReady {
33413341
channel_id: $channel.context.channel_id(),
33423342
user_channel_id: $channel.context.get_user_id(),
33433343
counterparty_node_id: $channel.context.get_counterparty_node_id(),
33443344
channel_type: $channel.funding.get_channel_type().clone(),
33453345
}, None));
3346-
$channel.context.set_channel_ready_event_emitted();
3346+
$channel.context.set_initial_channel_ready_event_emitted();
33473347
}
33483348
}
33493349
}
@@ -8062,7 +8062,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
80628062
{
80638063
let mut pending_events = self.pending_events.lock().unwrap();
80648064
emit_channel_pending_event!(pending_events, channel);
8065-
emit_channel_ready_event!(pending_events, channel);
8065+
emit_initial_channel_ready_event!(pending_events, channel);
80668066
}
80678067

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

90759075
{
90769076
let mut pending_events = self.pending_events.lock().unwrap();
9077-
emit_channel_ready_event!(pending_events, chan);
9077+
emit_initial_channel_ready_event!(pending_events, chan);
90789078
}
90799079

90809080
Ok(())
@@ -10042,6 +10042,14 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1004210042
if !chan.has_pending_splice() {
1004310043
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
1004410044
insert_short_channel_id!(short_to_chan_info, chan);
10045+
10046+
let mut pending_events = self.pending_events.lock().unwrap();
10047+
pending_events.push_back((events::Event::ChannelReady {
10048+
channel_id: chan.context.channel_id(),
10049+
user_channel_id: chan.context.get_user_id(),
10050+
counterparty_node_id: chan.context.get_counterparty_node_id(),
10051+
channel_type: chan.funding.get_channel_type().clone(),
10052+
}, None));
1004510053
}
1004610054

1004710055
if let Some(announcement_sigs) = announcement_sigs_opt {
@@ -12111,6 +12119,14 @@ where
1211112119
if !funded_channel.has_pending_splice() {
1211212120
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
1211312121
insert_short_channel_id!(short_to_chan_info, funded_channel);
12122+
12123+
let mut pending_events = self.pending_events.lock().unwrap();
12124+
pending_events.push_back((events::Event::ChannelReady {
12125+
channel_id: funded_channel.context.channel_id(),
12126+
user_channel_id: funded_channel.context.get_user_id(),
12127+
counterparty_node_id: funded_channel.context.get_counterparty_node_id(),
12128+
channel_type: funded_channel.funding.get_channel_type().clone(),
12129+
}, None));
1211412130
}
1211512131

1211612132
pending_msg_events.push(MessageSendEvent::SendSpliceLocked {
@@ -12123,7 +12139,7 @@ where
1212312139

1212412140
{
1212512141
let mut pending_events = self.pending_events.lock().unwrap();
12126-
emit_channel_ready_event!(pending_events, funded_channel);
12142+
emit_initial_channel_ready_event!(pending_events, funded_channel);
1212712143
}
1212812144

1212912145
if let Some(height) = height_opt {

0 commit comments

Comments
 (0)