Skip to content

Commit f3b0989

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 7e32d2a commit f3b0989

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

lightning/src/events/mod.rs

+50
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,29 @@ pub enum Event {
13181318
/// The features that this channel will operate with.
13191319
channel_type: ChannelTypeFeatures,
13201320
},
1321+
/// Used to indicate that a channel with the given `channel_id` has had its funding spliced.
1322+
/// This event is emitted when the splice transaction has been confirmed on-chain to a
1323+
/// sufficient depth by both parties, or, in case of a 0-conf channel, when both parties have
1324+
/// completed negotiation of the splice transaction.
1325+
///
1326+
/// # Failure Behavior and Persistence
1327+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
1328+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
1329+
SpliceLocked {
1330+
/// The `channel_id` of the channel that had its funding spliced.
1331+
channel_id: ChannelId,
1332+
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
1333+
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
1334+
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
1335+
/// `user_channel_id` will be randomized for an inbound channel.
1336+
///
1337+
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
1338+
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1339+
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
1340+
user_channel_id: u128,
1341+
/// The `node_id` of the channel counterparty.
1342+
counterparty_node_id: PublicKey,
1343+
},
13211344
/// Used to indicate that a channel that got past the initial handshake with the given `channel_id` is in the
13221345
/// process of closure. This includes previously opened channels, and channels that time out from not being funded.
13231346
///
@@ -1842,6 +1865,14 @@ impl Writeable for Event {
18421865
(8, former_temporary_channel_id, required),
18431866
});
18441867
},
1868+
&Event::SpliceLocked { ref channel_id, ref user_channel_id, ref counterparty_node_id } => {
1869+
45u8.write(writer)?;
1870+
write_tlv_fields!(writer, {
1871+
(0, channel_id, required),
1872+
(2, user_channel_id, required),
1873+
(4, counterparty_node_id, required),
1874+
});
1875+
},
18451876
// Note that, going forward, all new events must only write data inside of
18461877
// `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
18471878
// data via `write_tlv_fields`.
@@ -2358,6 +2389,25 @@ impl MaybeReadable for Event {
23582389
former_temporary_channel_id: former_temporary_channel_id.0.unwrap(),
23592390
}))
23602391
},
2392+
45u8 => {
2393+
let mut f = || {
2394+
let mut channel_id = ChannelId::new_zero();
2395+
let mut user_channel_id: u128 = 0;
2396+
let mut counterparty_node_id = RequiredWrapper(None);
2397+
read_tlv_fields!(reader, {
2398+
(0, channel_id, required),
2399+
(2, user_channel_id, required),
2400+
(4, counterparty_node_id, required),
2401+
});
2402+
2403+
Ok(Some(Event::SpliceLocked {
2404+
channel_id,
2405+
user_channel_id,
2406+
counterparty_node_id: counterparty_node_id.0.unwrap(),
2407+
}))
2408+
};
2409+
f()
2410+
},
23612411
// Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
23622412
// Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
23632413
// reads.

lightning/src/ln/channelmanager.rs

+14
Original file line numberDiff line numberDiff line change
@@ -9640,6 +9640,13 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
96409640
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
96419641
insert_short_channel_id!(short_to_chan_info, chan);
96429642

9643+
let mut pending_events = self.pending_events.lock().unwrap();
9644+
pending_events.push_back((events::Event::SpliceLocked {
9645+
channel_id: chan.context.channel_id(),
9646+
user_channel_id: chan.context.get_user_id(),
9647+
counterparty_node_id: chan.context.get_counterparty_node_id(),
9648+
}, None));
9649+
96439650
log_trace!(logger, "Sending announcement_signatures for channel {}", chan.context.channel_id());
96449651
peer_state.pending_msg_events.push(MessageSendEvent::SendAnnouncementSignatures {
96459652
node_id: counterparty_node_id.clone(),
@@ -11784,6 +11791,13 @@ where
1178411791
if announcement_sigs.is_some() {
1178511792
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
1178611793
insert_short_channel_id!(short_to_chan_info, funded_channel);
11794+
11795+
let mut pending_events = self.pending_events.lock().unwrap();
11796+
pending_events.push_back((events::Event::SpliceLocked {
11797+
channel_id: funded_channel.context.channel_id(),
11798+
user_channel_id: funded_channel.context.get_user_id(),
11799+
counterparty_node_id: funded_channel.context.get_counterparty_node_id(),
11800+
}, None));
1178711801
}
1178811802

1178911803
pending_msg_events.push(MessageSendEvent::SendSpliceLocked {

0 commit comments

Comments
 (0)