Skip to content

Commit 5c90b06

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 aa4718b commit 5c90b06

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.
@@ -11632,7 +11632,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1163211632
{ Some(self.context.holder_max_htlc_value_in_flight_msat) } else { None };
1163311633

1163411634
let channel_pending_event_emitted = Some(self.context.channel_pending_event_emitted);
11635-
let channel_ready_event_emitted = Some(self.context.channel_ready_event_emitted);
11635+
let initial_channel_ready_event_emitted = Some(self.context.initial_channel_ready_event_emitted);
1163611636
let funding_tx_broadcast_safe_event_emitted = Some(self.context.funding_tx_broadcast_safe_event_emitted);
1163711637

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

1198911989
let mut user_id_high_opt: Option<u64> = None;
@@ -12038,7 +12038,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1203812038
(17, announcement_sigs_state, required),
1203912039
(19, latest_inbound_scid_alias, option),
1204012040
(21, outbound_scid_alias, required),
12041-
(23, channel_ready_event_emitted, option),
12041+
(23, initial_channel_ready_event_emitted, option),
1204212042
(25, user_id_high_opt, option),
1204312043
(27, channel_keys_id, required),
1204412044
(28, holder_max_accepted_htlcs, option),
@@ -12338,7 +12338,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1233812338

1233912339
funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
1234012340
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
12341-
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
12341+
initial_channel_ready_event_emitted: initial_channel_ready_event_emitted.unwrap_or(true),
1234212342

1234312343
channel_keys_id,
1234412344

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(())
@@ -10035,6 +10035,14 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1003510035
if !chan.has_pending_splice() {
1003610036
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
1003710037
insert_short_channel_id!(short_to_chan_info, chan);
10038+
10039+
let mut pending_events = self.pending_events.lock().unwrap();
10040+
pending_events.push_back((events::Event::ChannelReady {
10041+
channel_id: chan.context.channel_id(),
10042+
user_channel_id: chan.context.get_user_id(),
10043+
counterparty_node_id: chan.context.get_counterparty_node_id(),
10044+
channel_type: chan.funding.get_channel_type().clone(),
10045+
}, None));
1003810046
}
1003910047

1004010048
if let Some(announcement_sigs) = announcement_sigs_opt {
@@ -12104,6 +12112,14 @@ where
1210412112
if !funded_channel.has_pending_splice() {
1210512113
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
1210612114
insert_short_channel_id!(short_to_chan_info, funded_channel);
12115+
12116+
let mut pending_events = self.pending_events.lock().unwrap();
12117+
pending_events.push_back((events::Event::ChannelReady {
12118+
channel_id: funded_channel.context.channel_id(),
12119+
user_channel_id: funded_channel.context.get_user_id(),
12120+
counterparty_node_id: funded_channel.context.get_counterparty_node_id(),
12121+
channel_type: funded_channel.funding.get_channel_type().clone(),
12122+
}, None));
1210712123
}
1210812124

1210912125
pending_msg_events.push(MessageSendEvent::SendSpliceLocked {
@@ -12116,7 +12132,7 @@ where
1211612132

1211712133
{
1211812134
let mut pending_events = self.pending_events.lock().unwrap();
12119-
emit_channel_ready_event!(pending_events, funded_channel);
12135+
emit_initial_channel_ready_event!(pending_events, funded_channel);
1212012136
}
1212112137

1212212138
if let Some(height) = height_opt {

0 commit comments

Comments
 (0)