Skip to content

Include counterpart_node_id in TransactionType#4393

Merged
TheBlueMatt merged 3 commits intolightningdevkit:mainfrom
tnull:2026-02-include-counterparty-node-id
Feb 6, 2026
Merged

Include counterpart_node_id in TransactionType#4393
TheBlueMatt merged 3 commits intolightningdevkit:mainfrom
tnull:2026-02-include-counterparty-node-id

Conversation

@tnull
Copy link
Contributor

@tnull tnull commented Feb 6, 2026

Closes #4391

In #4353 we added a TransactionType that also indicated the ChannelIds associated with the broadcasted transaction. However, as pointed out there, ChannelIds might are always just guranteed to be unique on a per-counterparty basis.

Therefore, we here track the counterparty_node_id side-by-side with the ChannelId, which notably also requires to track it as part of Event::SpendableOutputs and in OutputSweeper.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Feb 6, 2026

👋 Thanks for assigning @wpaulino as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

if let Some(channel_id) = output_info.channel_id {
if !channel_ids.contains(&channel_id) {
channel_ids.push(channel_id);
if let (Some(counterparty_node_id), Some(channel_id)) =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Want to point out that this will result in an empty channels for already-tracked entries on upgrade. We'll need to see how to handle that case downstream I guess. Technically we'd need to make the tracking an Option<PublicKey> but that's just odd.

tnull added 3 commits February 6, 2026 13:25
This adds an optional `counterparty_node_id` field to the
`SpendableOutputs` event, providing users with information about which
channel counterparty the spendable outputs belong to.

The field uses TLV type 3 (odd) for backwards compatibility, meaning
older versions will safely ignore it during deserialization. When
reading events serialized by older LDK versions, this field will be
`None`.

Co-Authored-By: HAL 9000
Signed-off-by: Elias Rohrer <dev@tnull.de>
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
Signed-off-by: Elias Rohrer <dev@tnull.de>
This adds `counterparty_node_id` tracking to all `TransactionType`
variants, enabling downstream users to identify the channel counterparty
associated with each broadcast transaction.

For single-channel variants (`CooperativeClose`, `UnilateralClose`,
`AnchorBump`, `Claim`, `Splice`), the counterparty is stored directly.

For multi-channel variants (`Funding`, `Sweep`), the type now uses
`Vec<(PublicKey, ChannelId)>` to pair each channel with its counterparty.

The `OnchainTxHandler` now stores `counterparty_node_id` and provides a
`set_counterparty_node_id` method for initialization during
deserialization of older data.

Co-Authored-By: HAL 9000
Signed-off-by: Elias Rohrer <dev@tnull.de>
@tnull tnull force-pushed the 2026-02-include-counterparty-node-id branch from ad4cc6c to 56f12c8 Compare February 6, 2026 12:25
.list_channels()
.into_iter()
.any(|cd| cd.channel_id == ch_id && cd.is_channel_ready);
.find(|cd| cd.channel_id == ch_id && cd.is_channel_ready);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might make sense to filter by UCID here as well. Technically channel id isn't unique for 0confs even if is_channel_ready.

@TheBlueMatt TheBlueMatt merged commit 94d1e5e into lightningdevkit:main Feb 6, 2026
17 of 19 checks passed
@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

❌ Patch coverage is 84.46602% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.02%. Comparing base (372ba65) to head (56f12c8).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/channelmanager.rs 60.00% 8 Missing ⚠️
lightning/src/ln/channel.rs 50.00% 5 Missing ⚠️
lightning/src/util/sweep.rs 82.35% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4393      +/-   ##
==========================================
- Coverage   86.04%   86.02%   -0.02%     
==========================================
  Files         156      156              
  Lines      103002   103046      +44     
  Branches   103002   103046      +44     
==========================================
+ Hits        88627    88646      +19     
- Misses      11865    11888      +23     
- Partials     2510     2512       +2     
Flag Coverage Δ
tests 86.02% <84.46%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add counterparty node ids (+ user channel ids) to TransactionType

3 participants