Skip to content

Commit 34558a4

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 55c9014 commit 34558a4

4 files changed

Lines changed: 26 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
- Users of the VSS storage backend must upgrade their VSS server to at least version
77
`v0.1.0-alpha.0` before upgrading LDK Node.
88

9+
## Serialization Compatibility
10+
- The `counterparty_node_id` field of the `ChannelReady` and `ChannelClosed` events is now
11+
required. Events persisted by LDK Node v0.1.0 and prior that are missing this field will
12+
fail to deserialize.
13+
914
# 0.7.0 - Dec. 3, 2025
1015
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.
1116

src/event.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,7 @@ pub enum Event {
249249
/// The `user_channel_id` of the channel.
250250
user_channel_id: UserChannelId,
251251
/// The `node_id` of the channel counterparty.
252-
///
253-
/// This will be `None` for events serialized by LDK Node v0.1.0 and prior.
254-
counterparty_node_id: Option<PublicKey>,
252+
counterparty_node_id: PublicKey,
255253
/// The outpoint of the channel's funding transaction.
256254
///
257255
/// This represents the channel's current funding output, which may change when the
@@ -268,9 +266,7 @@ pub enum Event {
268266
/// The `user_channel_id` of the channel.
269267
user_channel_id: UserChannelId,
270268
/// The `node_id` of the channel counterparty.
271-
///
272-
/// This will be `None` for events serialized by LDK Node v0.1.0 and prior.
273-
counterparty_node_id: Option<PublicKey>,
269+
counterparty_node_id: PublicKey,
274270
/// This will be `None` for events serialized by LDK Node v0.2.1 and prior.
275271
reason: Option<ClosureReason>,
276272
/// 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),
@@ -1652,7 +1648,7 @@ where
16521648
let event = Event::ChannelReady {
16531649
channel_id,
16541650
user_channel_id: UserChannelId(user_channel_id),
1655-
counterparty_node_id: Some(counterparty_node_id),
1651+
counterparty_node_id,
16561652
funding_txo,
16571653
};
16581654
match self.event_queue.add_event(event).await {
@@ -1719,7 +1715,8 @@ where
17191715
let event = Event::ChannelClosed {
17201716
channel_id,
17211717
user_channel_id,
1722-
counterparty_node_id,
1718+
counterparty_node_id: counterparty_node_id
1719+
.expect("counterparty_node_id must be set for closed channels"),
17231720
reason: Some(reason),
17241721
channel_capacity_sats,
17251722
channel_funding_txo: funding_txo,
@@ -2020,6 +2017,7 @@ mod tests {
20202017
use std::sync::atomic::{AtomicU16, Ordering};
20212018
use std::time::Duration;
20222019

2020+
use bitcoin::secp256k1::{Secp256k1, SecretKey};
20232021
use lightning::util::test_utils::TestLogger;
20242022

20252023
use super::*;
@@ -2083,10 +2081,13 @@ mod tests {
20832081
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
20842082
assert_eq!(event_queue.next_event(), None);
20852083

2084+
let secp = Secp256k1::new();
2085+
let counterparty_node_id =
2086+
PublicKey::from_secret_key(&secp, &SecretKey::from_slice(&[1u8; 32]).unwrap());
20862087
let expected_event = Event::ChannelReady {
20872088
channel_id: ChannelId([23u8; 32]),
20882089
user_channel_id: UserChannelId(2323),
2089-
counterparty_node_id: None,
2090+
counterparty_node_id,
20902091
funding_txo: None,
20912092
};
20922093
event_queue.add_event(expected_event.clone()).await.unwrap();
@@ -2121,10 +2122,13 @@ mod tests {
21212122
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
21222123
assert_eq!(event_queue.next_event(), None);
21232124

2125+
let secp = Secp256k1::new();
2126+
let counterparty_node_id =
2127+
PublicKey::from_secret_key(&secp, &SecretKey::from_slice(&[1u8; 32]).unwrap());
21242128
let expected_event = Event::ChannelReady {
21252129
channel_id: ChannelId([23u8; 32]),
21262130
user_channel_id: UserChannelId(2323),
2127-
counterparty_node_id: None,
2131+
counterparty_node_id,
21282132
funding_txo: None,
21292133
};
21302134

tests/common/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ macro_rules! expect_channel_ready_event {
133133
match event {
134134
ref e @ Event::ChannelReady { user_channel_id, counterparty_node_id, .. } => {
135135
println!("{} got event {:?}", $node.node_id(), e);
136-
assert_eq!(counterparty_node_id, Some($counterparty_node_id));
136+
assert_eq!(counterparty_node_id, $counterparty_node_id);
137137
$node.event_handled().unwrap();
138138
user_channel_id
139139
},
@@ -170,8 +170,7 @@ macro_rules! expect_channel_ready_events {
170170
}
171171
}
172172
assert!(
173-
ids.contains(&Some($counterparty_node_id_a))
174-
&& ids.contains(&Some($counterparty_node_id_b)),
173+
ids.contains(&$counterparty_node_id_a) && ids.contains(&$counterparty_node_id_b),
175174
"Expected ChannelReady events from {:?} and {:?}, but got {:?}",
176175
$counterparty_node_id_a,
177176
$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)