Skip to content

Commit b0f037b

Browse files
committed
Add counterparty_node_id to TrackedSpendableOutput
This adds an optional `counterparty_node_id` field to `TrackedSpendableOutput` and updates the `track_spendable_outputs` method signatures on both `OutputSweeper` and `OutputSweeperSync` to accept this new parameter. The field uses TLV type 3 (odd) for backwards compatibility. When reading outputs tracked with LDK 0.2 and prior, this field will be `None`. Co-Authored-By: HAL 9000
1 parent e9e5ffe commit b0f037b

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

lightning-background-processor/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3110,10 +3110,16 @@ mod tests {
31103110
let event =
31113111
receiver.recv_timeout(EVENT_DEADLINE).expect("Events not handled within deadline");
31123112
match event {
3113-
Event::SpendableOutputs { outputs, channel_id, counterparty_node_id: _ } => {
3113+
Event::SpendableOutputs { outputs, channel_id, counterparty_node_id } => {
31143114
nodes[0]
31153115
.sweeper
3116-
.track_spendable_outputs(outputs, channel_id, false, Some(153))
3116+
.track_spendable_outputs(
3117+
outputs,
3118+
channel_id,
3119+
counterparty_node_id,
3120+
false,
3121+
Some(153),
3122+
)
31173123
.unwrap();
31183124
},
31193125
_ => panic!("Unexpected event: {:?}", event),

lightning/src/util/sweep.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::{log_debug, log_error};
3232

3333
use bitcoin::block::Header;
3434
use bitcoin::locktime::absolute::LockTime;
35-
use bitcoin::secp256k1::Secp256k1;
35+
use bitcoin::secp256k1::{PublicKey, Secp256k1};
3636
use bitcoin::{BlockHash, ScriptBuf, Transaction, Txid};
3737

3838
use core::future::Future;
@@ -55,6 +55,13 @@ pub struct TrackedSpendableOutput {
5555
///
5656
/// Will be `None` if no `channel_id` was given to [`OutputSweeper::track_spendable_outputs`]
5757
pub channel_id: Option<ChannelId>,
58+
/// The `node_id` of the channel counterparty.
59+
///
60+
/// Will be `None` if no `counterparty_node_id` was given to
61+
/// [`OutputSweeper::track_spendable_outputs`].
62+
///
63+
/// This will be `None` for outputs tracked with LDK 0.2 and prior.
64+
pub counterparty_node_id: Option<PublicKey>,
5865
/// The current status of the output spend.
5966
pub status: OutputSpendStatus,
6067
}
@@ -93,6 +100,7 @@ impl TrackedSpendableOutput {
93100
impl_writeable_tlv_based!(TrackedSpendableOutput, {
94101
(0, descriptor, required),
95102
(2, channel_id, option),
103+
(3, counterparty_node_id, option),
96104
(4, status, required),
97105
});
98106

@@ -413,7 +421,8 @@ where
413421
/// [`Event::SpendableOutputs`]: crate::events::Event::SpendableOutputs
414422
pub async fn track_spendable_outputs(
415423
&self, output_descriptors: Vec<SpendableOutputDescriptor>, channel_id: Option<ChannelId>,
416-
exclude_static_outputs: bool, delay_until_height: Option<u32>,
424+
counterparty_node_id: Option<PublicKey>, exclude_static_outputs: bool,
425+
delay_until_height: Option<u32>,
417426
) -> Result<(), ()> {
418427
let mut relevant_descriptors = output_descriptors
419428
.into_iter()
@@ -432,6 +441,7 @@ where
432441
let output_info = TrackedSpendableOutput {
433442
descriptor,
434443
channel_id,
444+
counterparty_node_id,
435445
status: OutputSpendStatus::PendingInitialBroadcast {
436446
delayed_until_height: delay_until_height,
437447
},
@@ -1010,11 +1020,13 @@ where
10101020
/// [`Event::SpendableOutputs`]: crate::events::Event::SpendableOutputs
10111021
pub fn track_spendable_outputs(
10121022
&self, output_descriptors: Vec<SpendableOutputDescriptor>, channel_id: Option<ChannelId>,
1013-
exclude_static_outputs: bool, delay_until_height: Option<u32>,
1023+
counterparty_node_id: Option<PublicKey>, exclude_static_outputs: bool,
1024+
delay_until_height: Option<u32>,
10141025
) -> Result<(), ()> {
10151026
let mut fut = pin!(self.sweeper.track_spendable_outputs(
10161027
output_descriptors,
10171028
channel_id,
1029+
counterparty_node_id,
10181030
exclude_static_outputs,
10191031
delay_until_height,
10201032
));

0 commit comments

Comments
 (0)