Skip to content

Commit 3f1fa35

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 00ee78d commit 3f1fa35

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
@@ -2428,8 +2428,8 @@ where
24282428
// We track whether we already emitted a `FundingTxBroadcastSafe` event.
24292429
funding_tx_broadcast_safe_event_emitted: bool,
24302430

2431-
// We track whether we already emitted a `ChannelReady` event.
2432-
channel_ready_event_emitted: bool,
2431+
// We track whether we already emitted an initial `ChannelReady` event.
2432+
initial_channel_ready_event_emitted: bool,
24332433

24342434
/// Some if we initiated to shut down the channel.
24352435
local_initiated_shutdown: Option<()>,
@@ -3272,7 +3272,7 @@ where
32723272

32733273
channel_pending_event_emitted: false,
32743274
funding_tx_broadcast_safe_event_emitted: false,
3275-
channel_ready_event_emitted: false,
3275+
initial_channel_ready_event_emitted: false,
32763276

32773277
channel_keys_id,
32783278

@@ -3515,7 +3515,7 @@ where
35153515

35163516
channel_pending_event_emitted: false,
35173517
funding_tx_broadcast_safe_event_emitted: false,
3518-
channel_ready_event_emitted: false,
3518+
initial_channel_ready_event_emitted: false,
35193519

35203520
channel_keys_id,
35213521

@@ -3945,14 +3945,14 @@ where
39453945
self.channel_pending_event_emitted = true;
39463946
}
39473947

3948-
// Checks whether we should emit a `ChannelReady` event.
3949-
pub(crate) fn should_emit_channel_ready_event(&mut self) -> bool {
3950-
self.is_usable() && !self.channel_ready_event_emitted
3948+
// Checks whether we should emit an initial `ChannelReady` event.
3949+
pub(crate) fn should_emit_initial_channel_ready_event(&mut self) -> bool {
3950+
self.is_usable() && !self.initial_channel_ready_event_emitted
39513951
}
39523952

39533953
// Remembers that we already emitted a `ChannelReady` event.
3954-
pub(crate) fn set_channel_ready_event_emitted(&mut self) {
3955-
self.channel_ready_event_emitted = true;
3954+
pub(crate) fn set_initial_channel_ready_event_emitted(&mut self) {
3955+
self.initial_channel_ready_event_emitted = true;
39563956
}
39573957

39583958
// Remembers that we already emitted a `FundingTxBroadcastSafe` event.
@@ -11997,7 +11997,7 @@ where
1199711997
{ Some(self.context.holder_max_htlc_value_in_flight_msat) } else { None };
1199811998

1199911999
let channel_pending_event_emitted = Some(self.context.channel_pending_event_emitted);
12000-
let channel_ready_event_emitted = Some(self.context.channel_ready_event_emitted);
12000+
let initial_channel_ready_event_emitted = Some(self.context.initial_channel_ready_event_emitted);
1200112001
let funding_tx_broadcast_safe_event_emitted = Some(self.context.funding_tx_broadcast_safe_event_emitted);
1200212002

1200312003
// `user_id` used to be a single u64 value. In order to remain backwards compatible with
@@ -12041,7 +12041,7 @@ where
1204112041
(17, self.context.announcement_sigs_state, required),
1204212042
(19, self.context.latest_inbound_scid_alias, option),
1204312043
(21, self.context.outbound_scid_alias, required),
12044-
(23, channel_ready_event_emitted, option),
12044+
(23, initial_channel_ready_event_emitted, option),
1204512045
(25, user_id_high_opt, option),
1204612046
(27, self.context.channel_keys_id, required),
1204712047
(28, holder_max_accepted_htlcs, option),
@@ -12350,7 +12350,7 @@ where
1235012350
let mut latest_inbound_scid_alias = None;
1235112351
let mut outbound_scid_alias = 0u64;
1235212352
let mut channel_pending_event_emitted = None;
12353-
let mut channel_ready_event_emitted = None;
12353+
let mut initial_channel_ready_event_emitted = None;
1235412354
let mut funding_tx_broadcast_safe_event_emitted = None;
1235512355

1235612356
let mut user_id_high_opt: Option<u64> = None;
@@ -12405,7 +12405,7 @@ where
1240512405
(17, announcement_sigs_state, required),
1240612406
(19, latest_inbound_scid_alias, option),
1240712407
(21, outbound_scid_alias, required),
12408-
(23, channel_ready_event_emitted, option),
12408+
(23, initial_channel_ready_event_emitted, option),
1240912409
(25, user_id_high_opt, option),
1241012410
(27, channel_keys_id, required),
1241112411
(28, holder_max_accepted_htlcs, option),
@@ -12705,7 +12705,7 @@ where
1270512705

1270612706
funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
1270712707
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
12708-
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
12708+
initial_channel_ready_event_emitted: initial_channel_ready_event_emitted.unwrap_or(true),
1270912709

1271012710
channel_keys_id,
1271112711

lightning/src/ln/channelmanager.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3342,17 +3342,17 @@ macro_rules! emit_channel_pending_event {
33423342
}
33433343

33443344
#[rustfmt::skip]
3345-
macro_rules! emit_channel_ready_event {
3345+
macro_rules! emit_initial_channel_ready_event {
33463346
($locked_events: expr, $channel: expr) => {
3347-
if $channel.context.should_emit_channel_ready_event() {
3347+
if $channel.context.should_emit_initial_channel_ready_event() {
33483348
debug_assert!($channel.context.channel_pending_event_emitted());
33493349
$locked_events.push_back((events::Event::ChannelReady {
33503350
channel_id: $channel.context.channel_id(),
33513351
user_channel_id: $channel.context.get_user_id(),
33523352
counterparty_node_id: $channel.context.get_counterparty_node_id(),
33533353
channel_type: $channel.funding.get_channel_type().clone(),
33543354
}, None));
3355-
$channel.context.set_channel_ready_event_emitted();
3355+
$channel.context.set_initial_channel_ready_event_emitted();
33563356
}
33573357
}
33583358
}
@@ -8071,7 +8071,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
80718071
{
80728072
let mut pending_events = self.pending_events.lock().unwrap();
80738073
emit_channel_pending_event!(pending_events, channel);
8074-
emit_channel_ready_event!(pending_events, channel);
8074+
emit_initial_channel_ready_event!(pending_events, channel);
80758075
}
80768076

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

90849084
{
90859085
let mut pending_events = self.pending_events.lock().unwrap();
9086-
emit_channel_ready_event!(pending_events, chan);
9086+
emit_initial_channel_ready_event!(pending_events, chan);
90879087
}
90889088

90899089
Ok(())
@@ -10051,6 +10051,14 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1005110051
if !chan.has_pending_splice() {
1005210052
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
1005310053
insert_short_channel_id!(short_to_chan_info, chan);
10054+
10055+
let mut pending_events = self.pending_events.lock().unwrap();
10056+
pending_events.push_back((events::Event::ChannelReady {
10057+
channel_id: chan.context.channel_id(),
10058+
user_channel_id: chan.context.get_user_id(),
10059+
counterparty_node_id: chan.context.get_counterparty_node_id(),
10060+
channel_type: chan.funding.get_channel_type().clone(),
10061+
}, None));
1005410062
}
1005510063

1005610064
if let Some(announcement_sigs) = announcement_sigs_opt {
@@ -12120,6 +12128,14 @@ where
1212012128
if !funded_channel.has_pending_splice() {
1212112129
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
1212212130
insert_short_channel_id!(short_to_chan_info, funded_channel);
12131+
12132+
let mut pending_events = self.pending_events.lock().unwrap();
12133+
pending_events.push_back((events::Event::ChannelReady {
12134+
channel_id: funded_channel.context.channel_id(),
12135+
user_channel_id: funded_channel.context.get_user_id(),
12136+
counterparty_node_id: funded_channel.context.get_counterparty_node_id(),
12137+
channel_type: funded_channel.funding.get_channel_type().clone(),
12138+
}, None));
1212312139
}
1212412140

1212512141
pending_msg_events.push(MessageSendEvent::SendSpliceLocked {
@@ -12132,7 +12148,7 @@ where
1213212148

1213312149
{
1213412150
let mut pending_events = self.pending_events.lock().unwrap();
12135-
emit_channel_ready_event!(pending_events, funded_channel);
12151+
emit_initial_channel_ready_event!(pending_events, funded_channel);
1213612152
}
1213712153

1213812154
if let Some(height) = height_opt {

0 commit comments

Comments
 (0)