Skip to content

Commit 2ae8938

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 ef178be commit 2ae8938

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

2280-
// We track whether we already emitted a `ChannelReady` event.
2281-
channel_ready_event_emitted: bool,
2280+
// We track whether we already emitted an initial `ChannelReady` event.
2281+
initial_channel_ready_event_emitted: bool,
22822282

22832283
/// Some if we initiated to shut down the channel.
22842284
local_initiated_shutdown: Option<()>,
@@ -3091,7 +3091,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
30913091

30923092
channel_pending_event_emitted: false,
30933093
funding_tx_broadcast_safe_event_emitted: false,
3094-
channel_ready_event_emitted: false,
3094+
initial_channel_ready_event_emitted: false,
30953095

30963096
channel_keys_id,
30973097

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

33273327
channel_pending_event_emitted: false,
33283328
funding_tx_broadcast_safe_event_emitted: false,
3329-
channel_ready_event_emitted: false,
3329+
initial_channel_ready_event_emitted: false,
33303330

33313331
channel_keys_id,
33323332

@@ -3759,14 +3759,14 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
37593759
self.channel_pending_event_emitted = true;
37603760
}
37613761

3762-
// Checks whether we should emit a `ChannelReady` event.
3763-
pub(crate) fn should_emit_channel_ready_event(&mut self) -> bool {
3764-
self.is_usable() && !self.channel_ready_event_emitted
3762+
// Checks whether we should emit an initial `ChannelReady` event.
3763+
pub(crate) fn should_emit_initial_channel_ready_event(&mut self) -> bool {
3764+
self.is_usable() && !self.initial_channel_ready_event_emitted
37653765
}
37663766

37673767
// Remembers that we already emitted a `ChannelReady` event.
3768-
pub(crate) fn set_channel_ready_event_emitted(&mut self) {
3769-
self.channel_ready_event_emitted = true;
3768+
pub(crate) fn set_initial_channel_ready_event_emitted(&mut self) {
3769+
self.initial_channel_ready_event_emitted = true;
37703770
}
37713771

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

1139511395
let channel_pending_event_emitted = Some(self.context.channel_pending_event_emitted);
11396-
let channel_ready_event_emitted = Some(self.context.channel_ready_event_emitted);
11396+
let initial_channel_ready_event_emitted = Some(self.context.initial_channel_ready_event_emitted);
1139711397
let funding_tx_broadcast_safe_event_emitted = Some(self.context.funding_tx_broadcast_safe_event_emitted);
1139811398

1139911399
// `user_id` used to be a single u64 value. In order to remain backwards compatible with
@@ -11437,7 +11437,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1143711437
(17, self.context.announcement_sigs_state, required),
1143811438
(19, self.context.latest_inbound_scid_alias, option),
1143911439
(21, self.context.outbound_scid_alias, required),
11440-
(23, channel_ready_event_emitted, option),
11440+
(23, initial_channel_ready_event_emitted, option),
1144111441
(25, user_id_high_opt, option),
1144211442
(27, self.context.channel_keys_id, required),
1144311443
(28, holder_max_accepted_htlcs, option),
@@ -11743,7 +11743,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1174311743
let mut latest_inbound_scid_alias = None;
1174411744
let mut outbound_scid_alias = 0u64;
1174511745
let mut channel_pending_event_emitted = None;
11746-
let mut channel_ready_event_emitted = None;
11746+
let mut initial_channel_ready_event_emitted = None;
1174711747
let mut funding_tx_broadcast_safe_event_emitted = None;
1174811748

1174911749
let mut user_id_high_opt: Option<u64> = None;
@@ -11796,7 +11796,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1179611796
(17, announcement_sigs_state, required),
1179711797
(19, latest_inbound_scid_alias, option),
1179811798
(21, outbound_scid_alias, required),
11799-
(23, channel_ready_event_emitted, option),
11799+
(23, initial_channel_ready_event_emitted, option),
1180011800
(25, user_id_high_opt, option),
1180111801
(27, channel_keys_id, required),
1180211802
(28, holder_max_accepted_htlcs, option),
@@ -12094,7 +12094,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1209412094

1209512095
funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
1209612096
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
12097-
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
12097+
initial_channel_ready_event_emitted: initial_channel_ready_event_emitted.unwrap_or(true),
1209812098

1209912099
channel_keys_id,
1210012100

lightning/src/ln/channelmanager.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3227,17 +3227,17 @@ macro_rules! emit_channel_pending_event {
32273227
}
32283228
}
32293229

3230-
macro_rules! emit_channel_ready_event {
3230+
macro_rules! emit_initial_channel_ready_event {
32313231
($locked_events: expr, $channel: expr) => {
3232-
if $channel.context.should_emit_channel_ready_event() {
3232+
if $channel.context.should_emit_initial_channel_ready_event() {
32333233
debug_assert!($channel.context.channel_pending_event_emitted());
32343234
$locked_events.push_back((events::Event::ChannelReady {
32353235
channel_id: $channel.context.channel_id(),
32363236
user_channel_id: $channel.context.get_user_id(),
32373237
counterparty_node_id: $channel.context.get_counterparty_node_id(),
32383238
channel_type: $channel.funding.get_channel_type().clone(),
32393239
}, None));
3240-
$channel.context.set_channel_ready_event_emitted();
3240+
$channel.context.set_initial_channel_ready_event_emitted();
32413241
}
32423242
}
32433243
}
@@ -7785,7 +7785,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
77857785
{
77867786
let mut pending_events = self.pending_events.lock().unwrap();
77877787
emit_channel_pending_event!(pending_events, channel);
7788-
emit_channel_ready_event!(pending_events, channel);
7788+
emit_initial_channel_ready_event!(pending_events, channel);
77897789
}
77907790

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

87398739
{
87408740
let mut pending_events = self.pending_events.lock().unwrap();
8741-
emit_channel_ready_event!(pending_events, chan);
8741+
emit_initial_channel_ready_event!(pending_events, chan);
87428742
}
87438743

87448744
Ok(())
@@ -9675,6 +9675,14 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
96759675
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
96769676
insert_short_channel_id!(short_to_chan_info, chan);
96779677

9678+
let mut pending_events = self.pending_events.lock().unwrap();
9679+
pending_events.push_back((events::Event::ChannelReady {
9680+
channel_id: chan.context.channel_id(),
9681+
user_channel_id: chan.context.get_user_id(),
9682+
counterparty_node_id: chan.context.get_counterparty_node_id(),
9683+
channel_type: chan.funding.get_channel_type().clone(),
9684+
}, None));
9685+
96789686
log_trace!(logger, "Sending announcement_signatures for channel {}", chan.context.channel_id());
96799687
peer_state.pending_msg_events.push(MessageSendEvent::SendAnnouncementSignatures {
96809688
node_id: counterparty_node_id.clone(),
@@ -11848,6 +11856,14 @@ where
1184811856
if announcement_sigs.is_some() {
1184911857
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
1185011858
insert_short_channel_id!(short_to_chan_info, funded_channel);
11859+
11860+
let mut pending_events = self.pending_events.lock().unwrap();
11861+
pending_events.push_back((events::Event::ChannelReady {
11862+
channel_id: funded_channel.context.channel_id(),
11863+
user_channel_id: funded_channel.context.get_user_id(),
11864+
counterparty_node_id: funded_channel.context.get_counterparty_node_id(),
11865+
channel_type: funded_channel.funding.get_channel_type().clone(),
11866+
}, None));
1185111867
}
1185211868

1185311869
pending_msg_events.push(MessageSendEvent::SendSpliceLocked {
@@ -11860,7 +11876,7 @@ where
1186011876

1186111877
{
1186211878
let mut pending_events = self.pending_events.lock().unwrap();
11863-
emit_channel_ready_event!(pending_events, funded_channel);
11879+
emit_initial_channel_ready_event!(pending_events, funded_channel);
1186411880
}
1186511881

1186611882
if let Some(height) = height_opt {

0 commit comments

Comments
 (0)