Skip to content

Commit 430585a

Browse files
committed
f - use ChannelReady instead of SpliceLocked event
1 parent 36c6245 commit 430585a

File tree

3 files changed

+29
-82
lines changed

3 files changed

+29
-82
lines changed

lightning/src/events/mod.rs

+7-60
Original file line numberDiff line numberDiff line change
@@ -1293,10 +1293,13 @@ pub enum Event {
12931293
/// Will be `None` for channels created prior to LDK version 0.0.122.
12941294
channel_type: Option<ChannelTypeFeatures>,
12951295
},
1296-
/// Used to indicate that a channel with the given `channel_id` is ready to
1297-
/// be used. This event is emitted either when the funding transaction has been confirmed
1298-
/// on-chain, or, in case of a 0conf channel, when both parties have confirmed the channel
1299-
/// establishment.
1296+
/// Used to indicate that a channel with the given `channel_id` is ready to be used. This event
1297+
/// is emitted when
1298+
/// - the initial funding transaction has been confirmed on-chain to an acceptable depth
1299+
/// according to both parties (i.e., `channel_ready` messages were exchanged),
1300+
/// - a splice funding transaction has been confirmed on-chain to an acceptable depth according
1301+
/// to both parties (i.e., `splice_locked` messages were exchanged), or,
1302+
/// - in case of a 0conf channel, when both parties have confirmed the channel establishment.
13001303
///
13011304
/// # Failure Behavior and Persistence
13021305
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
@@ -1318,31 +1321,6 @@ pub enum Event {
13181321
/// The features that this channel will operate with.
13191322
channel_type: ChannelTypeFeatures,
13201323
},
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-
/// The features that this channel will operate with.
1344-
channel_type: ChannelTypeFeatures,
1345-
},
13461324
/// Used to indicate that a channel that got past the initial handshake with the given `channel_id` is in the
13471325
/// process of closure. This includes previously opened channels, and channels that time out from not being funded.
13481326
///
@@ -1867,15 +1845,6 @@ impl Writeable for Event {
18671845
(8, former_temporary_channel_id, required),
18681846
});
18691847
},
1870-
&Event::SpliceLocked { ref channel_id, ref user_channel_id, ref counterparty_node_id, ref channel_type } => {
1871-
45u8.write(writer)?;
1872-
write_tlv_fields!(writer, {
1873-
(0, channel_id, required),
1874-
(2, user_channel_id, required),
1875-
(4, counterparty_node_id, required),
1876-
(6, channel_type, required),
1877-
});
1878-
},
18791848
// Note that, going forward, all new events must only write data inside of
18801849
// `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
18811850
// data via `write_tlv_fields`.
@@ -2392,28 +2361,6 @@ impl MaybeReadable for Event {
23922361
former_temporary_channel_id: former_temporary_channel_id.0.unwrap(),
23932362
}))
23942363
},
2395-
45u8 => {
2396-
let mut f = || {
2397-
let mut channel_id = ChannelId::new_zero();
2398-
let mut user_channel_id: u128 = 0;
2399-
let mut counterparty_node_id = RequiredWrapper(None);
2400-
let mut channel_type = RequiredWrapper(None);
2401-
read_tlv_fields!(reader, {
2402-
(0, channel_id, required),
2403-
(2, user_channel_id, required),
2404-
(4, counterparty_node_id, required),
2405-
(6, channel_type, required),
2406-
});
2407-
2408-
Ok(Some(Event::SpliceLocked {
2409-
channel_id,
2410-
user_channel_id,
2411-
counterparty_node_id: counterparty_node_id.0.unwrap(),
2412-
channel_type: channel_type.0.unwrap()
2413-
}))
2414-
};
2415-
f()
2416-
},
24172364
// Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
24182365
// Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
24192366
// reads.

lightning/src/ln/channel.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -2135,8 +2135,8 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
21352135
// We track whether we already emitted a `FundingTxBroadcastSafe` event.
21362136
funding_tx_broadcast_safe_event_emitted: bool,
21372137

2138-
// We track whether we already emitted a `ChannelReady` event.
2139-
channel_ready_event_emitted: bool,
2138+
// We track whether we already emitted an initial `ChannelReady` event.
2139+
initial_channel_ready_event_emitted: bool,
21402140

21412141
/// Some if we initiated to shut down the channel.
21422142
local_initiated_shutdown: Option<()>,
@@ -2944,7 +2944,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
29442944

29452945
channel_pending_event_emitted: false,
29462946
funding_tx_broadcast_safe_event_emitted: false,
2947-
channel_ready_event_emitted: false,
2947+
initial_channel_ready_event_emitted: false,
29482948

29492949
channel_keys_id,
29502950

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

31813181
channel_pending_event_emitted: false,
31823182
funding_tx_broadcast_safe_event_emitted: false,
3183-
channel_ready_event_emitted: false,
3183+
initial_channel_ready_event_emitted: false,
31843184

31853185
channel_keys_id,
31863186

@@ -3590,14 +3590,14 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
35903590
self.channel_pending_event_emitted = true;
35913591
}
35923592

3593-
// Checks whether we should emit a `ChannelReady` event.
3594-
pub(crate) fn should_emit_channel_ready_event(&mut self) -> bool {
3595-
self.is_usable() && !self.channel_ready_event_emitted
3593+
// Checks whether we should emit an initial `ChannelReady` event.
3594+
pub(crate) fn should_emit_initial_channel_ready_event(&mut self) -> bool {
3595+
self.is_usable() && !self.initial_channel_ready_event_emitted
35963596
}
35973597

35983598
// Remembers that we already emitted a `ChannelReady` event.
3599-
pub(crate) fn set_channel_ready_event_emitted(&mut self) {
3600-
self.channel_ready_event_emitted = true;
3599+
pub(crate) fn set_initial_channel_ready_event_emitted(&mut self) {
3600+
self.initial_channel_ready_event_emitted = true;
36013601
}
36023602

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

1107911079
let channel_pending_event_emitted = Some(self.context.channel_pending_event_emitted);
11080-
let channel_ready_event_emitted = Some(self.context.channel_ready_event_emitted);
11080+
let initial_channel_ready_event_emitted = Some(self.context.initial_channel_ready_event_emitted);
1108111081
let funding_tx_broadcast_safe_event_emitted = Some(self.context.funding_tx_broadcast_safe_event_emitted);
1108211082

1108311083
// `user_id` used to be a single u64 value. In order to remain backwards compatible with
@@ -11121,7 +11121,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1112111121
(17, self.context.announcement_sigs_state, required),
1112211122
(19, self.context.latest_inbound_scid_alias, option),
1112311123
(21, self.context.outbound_scid_alias, required),
11124-
(23, channel_ready_event_emitted, option),
11124+
(23, initial_channel_ready_event_emitted, option),
1112511125
(25, user_id_high_opt, option),
1112611126
(27, self.context.channel_keys_id, required),
1112711127
(28, holder_max_accepted_htlcs, option),
@@ -11408,7 +11408,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1140811408
let mut latest_inbound_scid_alias = None;
1140911409
let mut outbound_scid_alias = 0u64;
1141011410
let mut channel_pending_event_emitted = None;
11411-
let mut channel_ready_event_emitted = None;
11411+
let mut initial_channel_ready_event_emitted = None;
1141211412
let mut funding_tx_broadcast_safe_event_emitted = None;
1141311413

1141411414
let mut user_id_high_opt: Option<u64> = None;
@@ -11458,7 +11458,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1145811458
(17, announcement_sigs_state, required),
1145911459
(19, latest_inbound_scid_alias, option),
1146011460
(21, outbound_scid_alias, required),
11461-
(23, channel_ready_event_emitted, option),
11461+
(23, initial_channel_ready_event_emitted, option),
1146211462
(25, user_id_high_opt, option),
1146311463
(27, channel_keys_id, required),
1146411464
(28, holder_max_accepted_htlcs, option),
@@ -11753,7 +11753,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1175311753

1175411754
funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
1175511755
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
11756-
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
11756+
initial_channel_ready_event_emitted: initial_channel_ready_event_emitted.unwrap_or(true),
1175711757

1175811758
channel_keys_id,
1175911759

lightning/src/ln/channelmanager.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -3193,17 +3193,17 @@ macro_rules! emit_channel_pending_event {
31933193
}
31943194
}
31953195

3196-
macro_rules! emit_channel_ready_event {
3196+
macro_rules! emit_initial_channel_ready_event {
31973197
($locked_events: expr, $channel: expr) => {
3198-
if $channel.context.should_emit_channel_ready_event() {
3198+
if $channel.context.should_emit_initial_channel_ready_event() {
31993199
debug_assert!($channel.context.channel_pending_event_emitted());
32003200
$locked_events.push_back((events::Event::ChannelReady {
32013201
channel_id: $channel.context.channel_id(),
32023202
user_channel_id: $channel.context.get_user_id(),
32033203
counterparty_node_id: $channel.context.get_counterparty_node_id(),
32043204
channel_type: $channel.funding.get_channel_type().clone(),
32053205
}, None));
3206-
$channel.context.set_channel_ready_event_emitted();
3206+
$channel.context.set_initial_channel_ready_event_emitted();
32073207
}
32083208
}
32093209
}
@@ -7751,7 +7751,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
77517751
{
77527752
let mut pending_events = self.pending_events.lock().unwrap();
77537753
emit_channel_pending_event!(pending_events, channel);
7754-
emit_channel_ready_event!(pending_events, channel);
7754+
emit_initial_channel_ready_event!(pending_events, channel);
77557755
}
77567756

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

87058705
{
87068706
let mut pending_events = self.pending_events.lock().unwrap();
8707-
emit_channel_ready_event!(pending_events, chan);
8707+
emit_initial_channel_ready_event!(pending_events, chan);
87088708
}
87098709

87108710
Ok(())
@@ -9641,7 +9641,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
96419641
insert_short_channel_id!(short_to_chan_info, chan);
96429642

96439643
let mut pending_events = self.pending_events.lock().unwrap();
9644-
pending_events.push_back((events::Event::SpliceLocked {
9644+
pending_events.push_back((events::Event::ChannelReady {
96459645
channel_id: chan.context.channel_id(),
96469646
user_channel_id: chan.context.get_user_id(),
96479647
counterparty_node_id: chan.context.get_counterparty_node_id(),
@@ -11788,7 +11788,7 @@ where
1178811788
insert_short_channel_id!(short_to_chan_info, funded_channel);
1178911789

1179011790
let mut pending_events = self.pending_events.lock().unwrap();
11791-
pending_events.push_back((events::Event::SpliceLocked {
11791+
pending_events.push_back((events::Event::ChannelReady {
1179211792
channel_id: funded_channel.context.channel_id(),
1179311793
user_channel_id: funded_channel.context.get_user_id(),
1179411794
counterparty_node_id: funded_channel.context.get_counterparty_node_id(),
@@ -11806,7 +11806,7 @@ where
1180611806

1180711807
{
1180811808
let mut pending_events = self.pending_events.lock().unwrap();
11809-
emit_channel_ready_event!(pending_events, funded_channel);
11809+
emit_initial_channel_ready_event!(pending_events, funded_channel);
1181011810
}
1181111811

1181211812
if let Some(height) = height_opt {

0 commit comments

Comments
 (0)