Skip to content

Commit 8b0ac01

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 9455aaf commit 8b0ac01

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
@@ -2440,8 +2440,8 @@ where
24402440
// We track whether we already emitted a `FundingTxBroadcastSafe` event.
24412441
funding_tx_broadcast_safe_event_emitted: bool,
24422442

2443-
// We track whether we already emitted a `ChannelReady` event.
2444-
channel_ready_event_emitted: bool,
2443+
// We track whether we already emitted an initial `ChannelReady` event.
2444+
initial_channel_ready_event_emitted: bool,
24452445

24462446
/// Some if we initiated to shut down the channel.
24472447
local_initiated_shutdown: Option<()>,
@@ -3288,7 +3288,7 @@ where
32883288

32893289
channel_pending_event_emitted: false,
32903290
funding_tx_broadcast_safe_event_emitted: false,
3291-
channel_ready_event_emitted: false,
3291+
initial_channel_ready_event_emitted: false,
32923292

32933293
channel_keys_id,
32943294

@@ -3531,7 +3531,7 @@ where
35313531

35323532
channel_pending_event_emitted: false,
35333533
funding_tx_broadcast_safe_event_emitted: false,
3534-
channel_ready_event_emitted: false,
3534+
initial_channel_ready_event_emitted: false,
35353535

35363536
channel_keys_id,
35373537

@@ -3959,14 +3959,14 @@ where
39593959
self.channel_pending_event_emitted = true;
39603960
}
39613961

3962-
// Checks whether we should emit a `ChannelReady` event.
3963-
pub(crate) fn should_emit_channel_ready_event(&mut self) -> bool {
3964-
self.is_usable() && !self.channel_ready_event_emitted
3962+
// Checks whether we should emit an initial `ChannelReady` event.
3963+
pub(crate) fn should_emit_initial_channel_ready_event(&mut self) -> bool {
3964+
self.is_usable() && !self.initial_channel_ready_event_emitted
39653965
}
39663966

39673967
// Remembers that we already emitted a `ChannelReady` event.
3968-
pub(crate) fn set_channel_ready_event_emitted(&mut self) {
3969-
self.channel_ready_event_emitted = true;
3968+
pub(crate) fn set_initial_channel_ready_event_emitted(&mut self) {
3969+
self.initial_channel_ready_event_emitted = true;
39703970
}
39713971

39723972
// Remembers that we already emitted a `FundingTxBroadcastSafe` event.
@@ -12050,7 +12050,7 @@ where
1205012050
{ Some(self.context.holder_max_htlc_value_in_flight_msat) } else { None };
1205112051

1205212052
let channel_pending_event_emitted = Some(self.context.channel_pending_event_emitted);
12053-
let channel_ready_event_emitted = Some(self.context.channel_ready_event_emitted);
12053+
let initial_channel_ready_event_emitted = Some(self.context.initial_channel_ready_event_emitted);
1205412054
let funding_tx_broadcast_safe_event_emitted = Some(self.context.funding_tx_broadcast_safe_event_emitted);
1205512055

1205612056
// `user_id` used to be a single u64 value. In order to remain backwards compatible with
@@ -12094,7 +12094,7 @@ where
1209412094
(17, self.context.announcement_sigs_state, required),
1209512095
(19, self.context.latest_inbound_scid_alias, option),
1209612096
(21, self.context.outbound_scid_alias, required),
12097-
(23, channel_ready_event_emitted, option),
12097+
(23, initial_channel_ready_event_emitted, option),
1209812098
(25, user_id_high_opt, option),
1209912099
(27, self.context.channel_keys_id, required),
1210012100
(28, holder_max_accepted_htlcs, option),
@@ -12403,7 +12403,7 @@ where
1240312403
let mut latest_inbound_scid_alias = None;
1240412404
let mut outbound_scid_alias = 0u64;
1240512405
let mut channel_pending_event_emitted = None;
12406-
let mut channel_ready_event_emitted = None;
12406+
let mut initial_channel_ready_event_emitted = None;
1240712407
let mut funding_tx_broadcast_safe_event_emitted = None;
1240812408

1240912409
let mut user_id_high_opt: Option<u64> = None;
@@ -12458,7 +12458,7 @@ where
1245812458
(17, announcement_sigs_state, required),
1245912459
(19, latest_inbound_scid_alias, option),
1246012460
(21, outbound_scid_alias, required),
12461-
(23, channel_ready_event_emitted, option),
12461+
(23, initial_channel_ready_event_emitted, option),
1246212462
(25, user_id_high_opt, option),
1246312463
(27, channel_keys_id, required),
1246412464
(28, holder_max_accepted_htlcs, option),
@@ -12758,7 +12758,7 @@ where
1275812758

1275912759
funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
1276012760
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
12761-
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
12761+
initial_channel_ready_event_emitted: initial_channel_ready_event_emitted.unwrap_or(true),
1276212762

1276312763
channel_keys_id,
1276412764

lightning/src/ln/channelmanager.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3355,9 +3355,9 @@ macro_rules! emit_channel_pending_event {
33553355
};
33563356
}
33573357

3358-
macro_rules! emit_channel_ready_event {
3358+
macro_rules! emit_initial_channel_ready_event {
33593359
($locked_events: expr, $channel: expr) => {
3360-
if $channel.context.should_emit_channel_ready_event() {
3360+
if $channel.context.should_emit_initial_channel_ready_event() {
33613361
debug_assert!($channel.context.channel_pending_event_emitted());
33623362
$locked_events.push_back((
33633363
events::Event::ChannelReady {
@@ -3368,7 +3368,7 @@ macro_rules! emit_channel_ready_event {
33683368
},
33693369
None,
33703370
));
3371-
$channel.context.set_channel_ready_event_emitted();
3371+
$channel.context.set_initial_channel_ready_event_emitted();
33723372
}
33733373
};
33743374
}
@@ -8155,7 +8155,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
81558155
{
81568156
let mut pending_events = self.pending_events.lock().unwrap();
81578157
emit_channel_pending_event!(pending_events, channel);
8158-
emit_channel_ready_event!(pending_events, channel);
8158+
emit_initial_channel_ready_event!(pending_events, channel);
81598159
}
81608160

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

91839183
{
91849184
let mut pending_events = self.pending_events.lock().unwrap();
9185-
emit_channel_ready_event!(pending_events, chan);
9185+
emit_initial_channel_ready_event!(pending_events, chan);
91869186
}
91879187

91889188
Ok(())
@@ -10161,6 +10161,14 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1016110161
if !chan.has_pending_splice() {
1016210162
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
1016310163
insert_short_channel_id!(short_to_chan_info, chan);
10164+
10165+
let mut pending_events = self.pending_events.lock().unwrap();
10166+
pending_events.push_back((events::Event::ChannelReady {
10167+
channel_id: chan.context.channel_id(),
10168+
user_channel_id: chan.context.get_user_id(),
10169+
counterparty_node_id: chan.context.get_counterparty_node_id(),
10170+
channel_type: chan.funding.get_channel_type().clone(),
10171+
}, None));
1016410172
}
1016510173

1016610174
if let Some(announcement_sigs) = announcement_sigs_opt {
@@ -12267,6 +12275,14 @@ where
1226712275
if !funded_channel.has_pending_splice() {
1226812276
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
1226912277
insert_short_channel_id!(short_to_chan_info, funded_channel);
12278+
12279+
let mut pending_events = self.pending_events.lock().unwrap();
12280+
pending_events.push_back((events::Event::ChannelReady {
12281+
channel_id: funded_channel.context.channel_id(),
12282+
user_channel_id: funded_channel.context.get_user_id(),
12283+
counterparty_node_id: funded_channel.context.get_counterparty_node_id(),
12284+
channel_type: funded_channel.funding.get_channel_type().clone(),
12285+
}, None));
1227012286
}
1227112287

1227212288
pending_msg_events.push(MessageSendEvent::SendSpliceLocked {
@@ -12279,7 +12295,7 @@ where
1227912295

1228012296
{
1228112297
let mut pending_events = self.pending_events.lock().unwrap();
12282-
emit_channel_ready_event!(pending_events, funded_channel);
12298+
emit_initial_channel_ready_event!(pending_events, funded_channel);
1228312299
}
1228412300

1228512301
if let Some(height) = height_opt {

0 commit comments

Comments
 (0)