Skip to content

Commit ac11095

Browse files
committed
Make counterparty_node_id non-optional on ChannelReady and ChannelClosed event
We no longer need to maintain backwards compatibility with LDK Node v0.1.0, so we can make this a required field and avoid propagating the Option through the API.
1 parent cb8619d commit ac11095

4 files changed

Lines changed: 28 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# Pending
2+
3+
## Serialization Compatibility
4+
- The `counterparty_node_id` field of the `ChannelReady` and `ChannelClosed` events is now
5+
required. Events persisted by LDK Node v0.1.0 and prior that are missing this field will
6+
fail to deserialize.
7+
18
# 0.7.0 - Dec. 3, 2025
29
This seventh minor release introduces numerous new features, bug fixes, and API improvements. In particular, it adds support for channel Splicing, Async Payments, as well as sourcing chain data from a Bitcoin Core REST backend.
310

src/event.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,7 @@ pub enum Event {
248248
/// The `user_channel_id` of the channel.
249249
user_channel_id: UserChannelId,
250250
/// The `node_id` of the channel counterparty.
251-
///
252-
/// This will be `None` for events serialized by LDK Node v0.1.0 and prior.
253-
counterparty_node_id: Option<PublicKey>,
251+
counterparty_node_id: PublicKey,
254252
/// The outpoint of the channel's funding transaction.
255253
///
256254
/// This represents the channel's current funding output, which may change when the
@@ -267,9 +265,7 @@ pub enum Event {
267265
/// The `user_channel_id` of the channel.
268266
user_channel_id: UserChannelId,
269267
/// The `node_id` of the channel counterparty.
270-
///
271-
/// This will be `None` for events serialized by LDK Node v0.1.0 and prior.
272-
counterparty_node_id: Option<PublicKey>,
268+
counterparty_node_id: PublicKey,
273269
/// This will be `None` for events serialized by LDK Node v0.2.1 and prior.
274270
reason: Option<ClosureReason>,
275271
/// The channel's capacity in satoshis.
@@ -330,7 +326,7 @@ impl_writeable_tlv_based_enum!(Event,
330326
},
331327
(3, ChannelReady) => {
332328
(0, channel_id, required),
333-
(1, counterparty_node_id, option),
329+
(1, counterparty_node_id, required),
334330
(2, user_channel_id, required),
335331
(3, funding_txo, option),
336332
},
@@ -343,7 +339,7 @@ impl_writeable_tlv_based_enum!(Event,
343339
},
344340
(5, ChannelClosed) => {
345341
(0, channel_id, required),
346-
(1, counterparty_node_id, option),
342+
(1, counterparty_node_id, required),
347343
(2, user_channel_id, required),
348344
(3, reason, upgradable_option),
349345
(5, channel_capacity_sats, option),
@@ -1624,7 +1620,7 @@ where
16241620
let event = Event::ChannelReady {
16251621
channel_id,
16261622
user_channel_id: UserChannelId(user_channel_id),
1627-
counterparty_node_id: Some(counterparty_node_id),
1623+
counterparty_node_id,
16281624
funding_txo,
16291625
};
16301626
match self.event_queue.add_event(event).await {
@@ -1685,7 +1681,8 @@ where
16851681
let event = Event::ChannelClosed {
16861682
channel_id,
16871683
user_channel_id,
1688-
counterparty_node_id,
1684+
counterparty_node_id: counterparty_node_id
1685+
.expect("counterparty_node_id must be set for closed channels"),
16891686
reason: Some(reason),
16901687
channel_capacity_sats,
16911688
channel_funding_txo: funding_txo,
@@ -1993,6 +1990,7 @@ mod tests {
19931990
use std::sync::atomic::{AtomicU16, Ordering};
19941991
use std::time::Duration;
19951992

1993+
use bitcoin::secp256k1::{Secp256k1, SecretKey};
19961994
use lightning::util::test_utils::TestLogger;
19971995

19981996
use super::*;
@@ -2006,10 +2004,13 @@ mod tests {
20062004
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
20072005
assert_eq!(event_queue.next_event(), None);
20082006

2007+
let secp = Secp256k1::new();
2008+
let counterparty_node_id =
2009+
PublicKey::from_secret_key(&secp, &SecretKey::from_slice(&[1u8; 32]).unwrap());
20092010
let expected_event = Event::ChannelReady {
20102011
channel_id: ChannelId([23u8; 32]),
20112012
user_channel_id: UserChannelId(2323),
2012-
counterparty_node_id: None,
2013+
counterparty_node_id,
20132014
funding_txo: None,
20142015
};
20152016
event_queue.add_event(expected_event.clone()).await.unwrap();
@@ -2044,10 +2045,13 @@ mod tests {
20442045
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
20452046
assert_eq!(event_queue.next_event(), None);
20462047

2048+
let secp = Secp256k1::new();
2049+
let counterparty_node_id =
2050+
PublicKey::from_secret_key(&secp, &SecretKey::from_slice(&[1u8; 32]).unwrap());
20472051
let expected_event = Event::ChannelReady {
20482052
channel_id: ChannelId([23u8; 32]),
20492053
user_channel_id: UserChannelId(2323),
2050-
counterparty_node_id: None,
2054+
counterparty_node_id,
20512055
funding_txo: None,
20522056
};
20532057

tests/common/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ macro_rules! expect_channel_ready_event {
130130
match event {
131131
ref e @ Event::ChannelReady { user_channel_id, counterparty_node_id, .. } => {
132132
println!("{} got event {:?}", $node.node_id(), e);
133-
assert_eq!(counterparty_node_id, Some($counterparty_node_id));
133+
assert_eq!(counterparty_node_id, $counterparty_node_id);
134134
$node.event_handled().unwrap();
135135
user_channel_id
136136
},
@@ -167,8 +167,7 @@ macro_rules! expect_channel_ready_events {
167167
}
168168
}
169169
assert!(
170-
ids.contains(&Some($counterparty_node_id_a))
171-
&& ids.contains(&Some($counterparty_node_id_b)),
170+
ids.contains(&$counterparty_node_id_a) && ids.contains(&$counterparty_node_id_b),
172171
"Expected ChannelReady events from {:?} and {:?}, but got {:?}",
173172
$counterparty_node_id_a,
174173
$counterparty_node_id_b,

tests/reorg_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ proptest! {
112112
let next_node = nodes.get((i + 1) % nodes.len()).unwrap();
113113
let prev_node = nodes.get((i + nodes.len() - 1) % nodes.len()).unwrap();
114114

115-
assert!(user_channels.get(&Some(next_node.node_id())) != None);
116-
assert!(user_channels.get(&Some(prev_node.node_id())) != None);
115+
assert!(user_channels.get(&next_node.node_id()) != None);
116+
assert!(user_channels.get(&prev_node.node_id()) != None);
117117

118118
let user_channel_id =
119-
user_channels.get(&Some(next_node.node_id())).expect("Missing user channel for node");
119+
user_channels.get(&next_node.node_id()).expect("Missing user channel for node");
120120
node_channels_id.insert(node.node_id(), *user_channel_id);
121121
}
122122

0 commit comments

Comments
 (0)