Skip to content

Commit 1960f50

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 0e1539e commit 1960f50

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 {
@@ -1691,7 +1687,8 @@ where
16911687
let event = Event::ChannelClosed {
16921688
channel_id,
16931689
user_channel_id,
1694-
counterparty_node_id,
1690+
counterparty_node_id: counterparty_node_id
1691+
.expect("counterparty_node_id must be set for closed channels"),
16951692
reason: Some(reason),
16961693
channel_capacity_sats,
16971694
channel_funding_txo: funding_txo,
@@ -1999,6 +1996,7 @@ mod tests {
19991996
use std::sync::atomic::{AtomicU16, Ordering};
20001997
use std::time::Duration;
20011998

1999+
use bitcoin::secp256k1::{Secp256k1, SecretKey};
20022000
use lightning::util::test_utils::TestLogger;
20032001

20042002
use super::*;
@@ -2012,10 +2010,13 @@ mod tests {
20122010
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
20132011
assert_eq!(event_queue.next_event(), None);
20142012

2013+
let secp = Secp256k1::new();
2014+
let counterparty_node_id =
2015+
PublicKey::from_secret_key(&secp, &SecretKey::from_slice(&[1u8; 32]).unwrap());
20152016
let expected_event = Event::ChannelReady {
20162017
channel_id: ChannelId([23u8; 32]),
20172018
user_channel_id: UserChannelId(2323),
2018-
counterparty_node_id: None,
2019+
counterparty_node_id,
20192020
funding_txo: None,
20202021
};
20212022
event_queue.add_event(expected_event.clone()).await.unwrap();
@@ -2050,10 +2051,13 @@ mod tests {
20502051
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
20512052
assert_eq!(event_queue.next_event(), None);
20522053

2054+
let secp = Secp256k1::new();
2055+
let counterparty_node_id =
2056+
PublicKey::from_secret_key(&secp, &SecretKey::from_slice(&[1u8; 32]).unwrap());
20532057
let expected_event = Event::ChannelReady {
20542058
channel_id: ChannelId([23u8; 32]),
20552059
user_channel_id: UserChannelId(2323),
2056-
counterparty_node_id: None,
2060+
counterparty_node_id,
20572061
funding_txo: None,
20582062
};
20592063

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)