Expand PaymentClaimable to include all inbound channel IDs for a payment - #3655

Merged
valentinewallace merged 3 commits into
lightningdevkit:mainfrom
shaavan:i2274
May 1, 2025
Merged

Expand PaymentClaimable to include all inbound channel IDs for a payment #3655
valentinewallace merged 3 commits into
lightningdevkit:mainfrom
shaavan:i2274

Conversation

@shaavan

Copy link
Copy Markdown
Member

Resolves#2274

This PR expands PaymentClaimable to include all inbound channel_ids and user_channel_ids associated with a payment.
This update ensures a clearer representation of the channels used, especially for MPP payments.

@ldk-reviews-bot

ldk-reviews-bot commented Mar 8, 2025

Copy link
Copy Markdown

👋 Thanks for assigning @joostjager 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.

@shaavan

Copy link
Copy Markdown
MemberAuthor

@benthecarman

Would also be nice if the same information is available on the PaymentClaimed event too

In the current version, I haven’t included channel_ids and user_channel_ids for PaymentClaimed, as they can be easily derived from the event itself:

let channel_ids = payment_claimed_event.htlcs.iter().map(|htlc| htlc.channel_id).collect();

That said, let me know if you’d still prefer to include channel_ids in PaymentClaimed, and I'd be happy to make that change. Thanks!

@benthecarman

Copy link
Copy Markdown
Contributor

Thanks, @shaavan , that is good enough

Comment threadlightning/src/ln/functional_test_utils.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
@ldk-reviews-bot

Copy link
Copy Markdown

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

@valentinewallace

Copy link
Copy Markdown
Contributor

nit: limit commit subject line in 2nd commit to ~50 characters

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.01 to pr3655.02 (diff):
Addressed @valentinewallace comments

  1. Updated the fields to be Vec<ChannelId>, and Vec<u128>
  2. Updated test utilities to check for all the channels id in events list, for improved test completeness.

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
Comment on lines +1553 to +1557
// legacy field
// (3, via_channel_id, option),
(4, amount_msat, required),
(5, via_user_channel_id, option),
// legacy field
// (5, via_user_channel_id, option),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should still write these fields for the sake of users who downgrade (can always write the first item in the vec). Also would be nice to comment in what version the fields became legacy.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Done! pr3655.03
I’ve updated the writing so that we maintain downgrade support.
Haven’t added a comment yet since I’m not sure what the next version number will be 😅 (would it be 0.1.3?)

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/events/mod.rs
Comment threadlightning/src/events/mod.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.02 to pr3655.03 (diff):
Addressed @valentinewallace comments

Changes:

  1. Expanded Documentation
  2. Properly write the legacy fields to maintain downgrade support.

@valentinewallace

Copy link
Copy Markdown
Contributor

Looks good, feel free to squash! Thanks!

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.03 to pr3655.04 (diff):
Addressed @valentinewallace comments

Changes:

  1. Squash commits.

@codecov

codecovBot commented Mar 15, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 96.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.37%. Comparing base (5bc9ffa) to head (591c5c8).
Report is 180 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/events/mod.rs90.47%0 Missing and 2 partials ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #3655 +/- ##
==========================================
+ Coverage 89.21% 91.37% +2.16% 
==========================================
Files 155 156 +1 Lines 118966 141344 +22378 Branches 118966 141344 +22378 ==========================================
+ Hits 106133 129159 +23026 + Misses 10253 9799 -454 + Partials 2580 2386 -194 

☔ 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.

@shaavanshaavan left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Looks good, feel free to squash! Thanks!

Awesome — thanks a lot for the review, Val! 🚀

Comment threadlightning/src/events/mod.rs
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.04 to pr3655.05 (diff):
Addressed @valentinewallace comments

Changes:

  • Added comment documenting when, and why via_channel_id_legacy, and via_user_channel_id_legacy were deprecated.

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.05 to pr3655.06 (diff):
Addressed @valentinewallace comments

Changes:

  1. Updated documentation to correctly reflect that the vector will be incomplete for HTLC created using versions prior to LDK 0.1.0 or prior.

@valentinewallace
valentinewallace self-requested a review April 4, 2025 17:11
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @valentinewallace! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be good to land after these last tweaks!

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.06 to pr3655.07 (diff):
Addressed @valentinewallace comments

Changes:

  1. Fixed comments to correctly represent for which version and cases the lists would be incomplete.

valentinewallace
valentinewallace previously approved these changes Apr 8, 2025
@jkczyz
jkczyz requested a review from joostjagerApril 10, 2025 17:29

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code looks good, test coverage could probably be improved a bit.

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/functional_tests.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.08 to pr3655.09 (diff):
Addressed @joostjager comments

Changes:

  1. Expanded test, to ensure that all the via_channel_id & via_user_channel_ids are present in PaymentClaimable in multi part payment case.

@valentinewallace

Copy link
Copy Markdown
Contributor

LGTM

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @joostjager! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 2nd Reminder

Hey @joostjager! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Comment threadlightning/src/events/mod.rs Outdated
via_channel_ids: Vec<ChannelId>,
/// The `user_channel_id`(s) corresponding to the channels over which the payment was received.
/// This will be an incomplete vector for MPP payment events created/serialized using LDK version 0.1.0 and prior.
via_user_channel_ids: Vec<u128>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's a bit late now, but would it be better to keep id and user_id together in a tuple? Not sure if there are interpretation issues when both vecs have different lengths?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thanks for bringing this up, Joost! I did consider that, but I wasn’t sure if it would offer a clear advantage. As far as I understand, both lists will always be of equal length since both fields were introduced together in the same version, so mismatched lengths shouldn’t arise.

Also, keeping them separate makes their distinction more explicit and follows the structure we’ve used in earlier LDK versions, where via_channel_id and via_user_channel_id were also separate fields.

That said, I’m open to discussing it further if you think a tuple-based design would still be better here! Would love to hear your thoughts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suppose the tuple leaves less room for questions like these. And maybe the original fields should have been a tuple/struct too. In general, I think it is good to keep the data types as strict as they can be.

But here it doesn't seem to be particular critical. Happy to go along with the other reviewer's view on it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we'd have to have a Vec<(ChannelId, Option<u128>)> since per ClaimablePayment::get_user_channel_ids docs user channel IDs are only always set after 117... Don't have a strong preference here although the option makes the field's API a bit less nice IMO.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The option would be consistent with HTLCPreviousHopData for example

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, isn't it the case that pre-117 data just translates to an empty vec<(..,..)> without requiring the option?

Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
// we test all generated events round-trip:
for event in &collected_events {
let ser = event.encode();
if let Some(deser) = events::Event::read(&mut &ser[..]).expect("event should deserialize") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the None case ok to ignore?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

AFAIU, yes. Some event enums are designed to map to a None value (for example, 0u8, 4u8, and 17u8), so getting an Ok(None) seems to indicate that the event was read successfully and no further checks are needed in this case.

That said, I'd love to hear @valentinewallace's thoughts to confirm if I’m understanding this correctly!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, some events are never written so I believe @shaavan is correct here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So could also continue when ser is None then, and unwrap the read? Not that it is all that important ofc.

@valentinewallacevalentinewallaceApr 28, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ser just returns Ok(()) on success, not an option.. But if you want to rearrange this code somehow, no strong preference here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like ser is just Vec<u8>. So if that is empty, we expect None from read? Maybe that can be used to make it slightly stricter and detect the case where read is unexpectedly returning None.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh right, sorry. It looks like for events where we don't write the actual event, we will still write the type for the event: https://github.com/lightningdevkit/rust-lightning/blob/main/lightning/src/events/mod.rs#L1809 so I don't think we can check if it's empty but we could check if only a u8 was written.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps a too much internal detail then. Can leave this as is as far as I am concerned.

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.09 to pr3655.10 (diff):
Addressed @joostjager comments

Changes:

  1. Add check that the via_channel_ids, and via_user_channel_ids only contains one element for the appropriate cases.

Comment threadlightning/src/ln/channelmanager.rs Outdated

/// Returns the inbound `user_channel_id`s for all HTLCs associated with the payment.
///
/// Note: This list will be incomplete for HTLCs created using LDK version 0.0.117 or prior.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment does seem to suggest that vecs can be different lengths?

@joostjagerjoostjagerApr 28, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@shaavan, @valentinewallace and I chatted about it. Seems something to say for a stronger type, especially because the vecs both map from PrevHopData already. But it's a bit late now also, and not too critical. So leaving up to you to decide.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thanks so much, Joost and Val, for the pointers!
I went ahead and updated the PaymentClaimable field to a via_channel_id_pairs, containing a Vec<(ChannelId, Option<u128>)>, in pr3655.11.

Let me know if it looks good — thanks again!

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.10 to pr3655.11 (diff):
Addressed @valentinewallace, @joostjager comments

Changes:

  1. Update PaymentClaimable field to be an ordered via_channel_id_pairs pair.

@joostjager

Copy link
Copy Markdown
Contributor

@shaavan just a side comment: I really like how you offer diffs to reviewers using pr3655.x branches!

joostjager
joostjager previously approved these changes Apr 29, 2025

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seeing how this worked out, I think vec(tuple) is the right move. Hopefully you feel the same!

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
Comment threadlightning/src/ln/blinded_payment_tests.rs Outdated

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Accidentally approved. Wanted to await your replies first.

These two utilities will be used in following commit to get all the
inbound channel_ids, and user_channel_ids associated with all the
parts of a payment.
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.11 to pr3655.12 (diff):
Addressed @joostjager comments

Changes:

  1. Rename via_channel_id_pairs & get_channel_id_pairs -> inbound_channel_ids
  2. Cleaned up testing.

@shaavan

Copy link
Copy Markdown
MemberAuthor

@shaavan just a side comment: I really like how you offer diffs to reviewers using pr3655.x branches!

Thanks so much, @joostjager — really appreciate you noticing that! :)

Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
Comment threadlightning/src/ln/functional_test_utils.rs Outdated

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM besides a few nits.

Comment threadlightning/src/ln/functional_tests.rs Outdated
shaavan added 2 commits May 1, 2025 20:37
Previously, `channel_id` in `PaymentClaimable` only listed a single
inbound channel, which was misleading for MPP payments arriving via
multiple channels.
To better represent MPP scenarios, this update introduces:
- `via_channel_ids`: A list of all inbound channels used in the payment.
- `via_user_channel_ids`: The corresponding user-defined channel IDs for
each inbound channel.
This change ensures a more accurate representation of multi-path payments
while maintaining backward compatibility.
- Expand testing to ensure proper serialise-deserialise round-trip for
all events.
- Expand a multi-Part payment test to ensure that all the channel ids &
user channel ids are present in the PaymentClaimable event
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.12 to pr3655.13 (diff):
Addressed @joostjager comments

Changes:

  1. Cleaned up tests

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @shaavan! I like the tuple change 👌

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for this contribution. Great work and excellent communication.

@valentinewallace
valentinewallace merged commit 29a6383 into lightningdevkit:mainMay 1, 2025
Sign up for freeto 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.

PaymentClaimable lists inbound channel id

5 participants

@shaavan@ldk-reviews-bot@benthecarman@valentinewallace@joostjager
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Expand PaymentClaimable to include all inbound channel IDs for a payment - #3655

Merged
valentinewallace merged 3 commits into
lightningdevkit:mainfrom
shaavan:i2274
May 1, 2025
Merged

Expand PaymentClaimable to include all inbound channel IDs for a payment #3655
valentinewallace merged 3 commits into
lightningdevkit:mainfrom
shaavan:i2274

Conversation

@shaavan

Copy link
Copy Markdown
Member

Resolves#2274

This PR expands PaymentClaimable to include all inbound channel_ids and user_channel_ids associated with a payment.
This update ensures a clearer representation of the channels used, especially for MPP payments.

@ldk-reviews-bot

ldk-reviews-bot commented Mar 8, 2025

Copy link
Copy Markdown

👋 Thanks for assigning @joostjager 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.

@shaavan

Copy link
Copy Markdown
MemberAuthor

@benthecarman

Would also be nice if the same information is available on the PaymentClaimed event too

In the current version, I haven’t included channel_ids and user_channel_ids for PaymentClaimed, as they can be easily derived from the event itself:

let channel_ids = payment_claimed_event.htlcs.iter().map(|htlc| htlc.channel_id).collect();

That said, let me know if you’d still prefer to include channel_ids in PaymentClaimed, and I'd be happy to make that change. Thanks!

@benthecarman

Copy link
Copy Markdown
Contributor

Thanks, @shaavan , that is good enough

Comment threadlightning/src/ln/functional_test_utils.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
@ldk-reviews-bot

Copy link
Copy Markdown

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

@valentinewallace

Copy link
Copy Markdown
Contributor

nit: limit commit subject line in 2nd commit to ~50 characters

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.01 to pr3655.02 (diff):
Addressed @valentinewallace comments

  1. Updated the fields to be Vec<ChannelId>, and Vec<u128>
  2. Updated test utilities to check for all the channels id in events list, for improved test completeness.

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
Comment on lines +1553 to +1557
// legacy field
// (3, via_channel_id, option),
(4, amount_msat, required),
(5, via_user_channel_id, option),
// legacy field
// (5, via_user_channel_id, option),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should still write these fields for the sake of users who downgrade (can always write the first item in the vec). Also would be nice to comment in what version the fields became legacy.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Done! pr3655.03
I’ve updated the writing so that we maintain downgrade support.
Haven’t added a comment yet since I’m not sure what the next version number will be 😅 (would it be 0.1.3?)

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/events/mod.rs
Comment threadlightning/src/events/mod.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.02 to pr3655.03 (diff):
Addressed @valentinewallace comments

Changes:

  1. Expanded Documentation
  2. Properly write the legacy fields to maintain downgrade support.

@valentinewallace

Copy link
Copy Markdown
Contributor

Looks good, feel free to squash! Thanks!

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.03 to pr3655.04 (diff):
Addressed @valentinewallace comments

Changes:

  1. Squash commits.

@codecov

codecovBot commented Mar 15, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 96.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.37%. Comparing base (5bc9ffa) to head (591c5c8).
Report is 180 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/events/mod.rs90.47%0 Missing and 2 partials ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #3655 +/- ##
==========================================
+ Coverage 89.21% 91.37% +2.16% 
==========================================
Files 155 156 +1 Lines 118966 141344 +22378 Branches 118966 141344 +22378 ==========================================
+ Hits 106133 129159 +23026 + Misses 10253 9799 -454 + Partials 2580 2386 -194 

☔ 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.

@shaavanshaavan left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Looks good, feel free to squash! Thanks!

Awesome — thanks a lot for the review, Val! 🚀

Comment threadlightning/src/events/mod.rs
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.04 to pr3655.05 (diff):
Addressed @valentinewallace comments

Changes:

  • Added comment documenting when, and why via_channel_id_legacy, and via_user_channel_id_legacy were deprecated.

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.05 to pr3655.06 (diff):
Addressed @valentinewallace comments

Changes:

  1. Updated documentation to correctly reflect that the vector will be incomplete for HTLC created using versions prior to LDK 0.1.0 or prior.

@valentinewallace
valentinewallace self-requested a review April 4, 2025 17:11
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @valentinewallace! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be good to land after these last tweaks!

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.06 to pr3655.07 (diff):
Addressed @valentinewallace comments

Changes:

  1. Fixed comments to correctly represent for which version and cases the lists would be incomplete.

valentinewallace
valentinewallace previously approved these changes Apr 8, 2025
@jkczyz
jkczyz requested a review from joostjagerApril 10, 2025 17:29

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code looks good, test coverage could probably be improved a bit.

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/functional_tests.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.08 to pr3655.09 (diff):
Addressed @joostjager comments

Changes:

  1. Expanded test, to ensure that all the via_channel_id & via_user_channel_ids are present in PaymentClaimable in multi part payment case.

@valentinewallace

Copy link
Copy Markdown
Contributor

LGTM

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @joostjager! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 2nd Reminder

Hey @joostjager! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Comment threadlightning/src/events/mod.rs Outdated
via_channel_ids: Vec<ChannelId>,
/// The `user_channel_id`(s) corresponding to the channels over which the payment was received.
/// This will be an incomplete vector for MPP payment events created/serialized using LDK version 0.1.0 and prior.
via_user_channel_ids: Vec<u128>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's a bit late now, but would it be better to keep id and user_id together in a tuple? Not sure if there are interpretation issues when both vecs have different lengths?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thanks for bringing this up, Joost! I did consider that, but I wasn’t sure if it would offer a clear advantage. As far as I understand, both lists will always be of equal length since both fields were introduced together in the same version, so mismatched lengths shouldn’t arise.

Also, keeping them separate makes their distinction more explicit and follows the structure we’ve used in earlier LDK versions, where via_channel_id and via_user_channel_id were also separate fields.

That said, I’m open to discussing it further if you think a tuple-based design would still be better here! Would love to hear your thoughts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suppose the tuple leaves less room for questions like these. And maybe the original fields should have been a tuple/struct too. In general, I think it is good to keep the data types as strict as they can be.

But here it doesn't seem to be particular critical. Happy to go along with the other reviewer's view on it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we'd have to have a Vec<(ChannelId, Option<u128>)> since per ClaimablePayment::get_user_channel_ids docs user channel IDs are only always set after 117... Don't have a strong preference here although the option makes the field's API a bit less nice IMO.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The option would be consistent with HTLCPreviousHopData for example

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, isn't it the case that pre-117 data just translates to an empty vec<(..,..)> without requiring the option?

Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
// we test all generated events round-trip:
for event in &collected_events {
let ser = event.encode();
if let Some(deser) = events::Event::read(&mut &ser[..]).expect("event should deserialize") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the None case ok to ignore?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

AFAIU, yes. Some event enums are designed to map to a None value (for example, 0u8, 4u8, and 17u8), so getting an Ok(None) seems to indicate that the event was read successfully and no further checks are needed in this case.

That said, I'd love to hear @valentinewallace's thoughts to confirm if I’m understanding this correctly!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, some events are never written so I believe @shaavan is correct here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So could also continue when ser is None then, and unwrap the read? Not that it is all that important ofc.

@valentinewallacevalentinewallaceApr 28, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ser just returns Ok(()) on success, not an option.. But if you want to rearrange this code somehow, no strong preference here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like ser is just Vec<u8>. So if that is empty, we expect None from read? Maybe that can be used to make it slightly stricter and detect the case where read is unexpectedly returning None.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh right, sorry. It looks like for events where we don't write the actual event, we will still write the type for the event: https://github.com/lightningdevkit/rust-lightning/blob/main/lightning/src/events/mod.rs#L1809 so I don't think we can check if it's empty but we could check if only a u8 was written.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps a too much internal detail then. Can leave this as is as far as I am concerned.

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.09 to pr3655.10 (diff):
Addressed @joostjager comments

Changes:

  1. Add check that the via_channel_ids, and via_user_channel_ids only contains one element for the appropriate cases.

Comment threadlightning/src/ln/channelmanager.rs Outdated

/// Returns the inbound `user_channel_id`s for all HTLCs associated with the payment.
///
/// Note: This list will be incomplete for HTLCs created using LDK version 0.0.117 or prior.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment does seem to suggest that vecs can be different lengths?

@joostjagerjoostjagerApr 28, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@shaavan, @valentinewallace and I chatted about it. Seems something to say for a stronger type, especially because the vecs both map from PrevHopData already. But it's a bit late now also, and not too critical. So leaving up to you to decide.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thanks so much, Joost and Val, for the pointers!
I went ahead and updated the PaymentClaimable field to a via_channel_id_pairs, containing a Vec<(ChannelId, Option<u128>)>, in pr3655.11.

Let me know if it looks good — thanks again!

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.10 to pr3655.11 (diff):
Addressed @valentinewallace, @joostjager comments

Changes:

  1. Update PaymentClaimable field to be an ordered via_channel_id_pairs pair.

@joostjager

Copy link
Copy Markdown
Contributor

@shaavan just a side comment: I really like how you offer diffs to reviewers using pr3655.x branches!

joostjager
joostjager previously approved these changes Apr 29, 2025

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seeing how this worked out, I think vec(tuple) is the right move. Hopefully you feel the same!

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
Comment threadlightning/src/ln/blinded_payment_tests.rs Outdated

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Accidentally approved. Wanted to await your replies first.

These two utilities will be used in following commit to get all the
inbound channel_ids, and user_channel_ids associated with all the
parts of a payment.
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.11 to pr3655.12 (diff):
Addressed @joostjager comments

Changes:

  1. Rename via_channel_id_pairs & get_channel_id_pairs -> inbound_channel_ids
  2. Cleaned up testing.

@shaavan

Copy link
Copy Markdown
MemberAuthor

@shaavan just a side comment: I really like how you offer diffs to reviewers using pr3655.x branches!

Thanks so much, @joostjager — really appreciate you noticing that! :)

Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
Comment threadlightning/src/ln/functional_test_utils.rs Outdated

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM besides a few nits.

Comment threadlightning/src/ln/functional_tests.rs Outdated
shaavan added 2 commits May 1, 2025 20:37
Previously, `channel_id` in `PaymentClaimable` only listed a single
inbound channel, which was misleading for MPP payments arriving via
multiple channels.
To better represent MPP scenarios, this update introduces:
- `via_channel_ids`: A list of all inbound channels used in the payment.
- `via_user_channel_ids`: The corresponding user-defined channel IDs for
each inbound channel.
This change ensures a more accurate representation of multi-path payments
while maintaining backward compatibility.
- Expand testing to ensure proper serialise-deserialise round-trip for
all events.
- Expand a multi-Part payment test to ensure that all the channel ids &
user channel ids are present in the PaymentClaimable event
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.12 to pr3655.13 (diff):
Addressed @joostjager comments

Changes:

  1. Cleaned up tests

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @shaavan! I like the tuple change 👌

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for this contribution. Great work and excellent communication.

@valentinewallace
valentinewallace merged commit 29a6383 into lightningdevkit:mainMay 1, 2025
Sign up for freeto 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.

PaymentClaimable lists inbound channel id

5 participants

@shaavan@ldk-reviews-bot@benthecarman@valentinewallace@joostjager
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Expand PaymentClaimable to include all inbound channel IDs for a payment - #3655

Merged
valentinewallace merged 3 commits into
lightningdevkit:mainfrom
shaavan:i2274
May 1, 2025
Merged

Expand PaymentClaimable to include all inbound channel IDs for a payment #3655
valentinewallace merged 3 commits into
lightningdevkit:mainfrom
shaavan:i2274

Conversation

@shaavan

Copy link
Copy Markdown
Member

Resolves#2274

This PR expands PaymentClaimable to include all inbound channel_ids and user_channel_ids associated with a payment.
This update ensures a clearer representation of the channels used, especially for MPP payments.

@ldk-reviews-bot

ldk-reviews-bot commented Mar 8, 2025

Copy link
Copy Markdown

👋 Thanks for assigning @joostjager 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.

@shaavan

Copy link
Copy Markdown
MemberAuthor

@benthecarman

Would also be nice if the same information is available on the PaymentClaimed event too

In the current version, I haven’t included channel_ids and user_channel_ids for PaymentClaimed, as they can be easily derived from the event itself:

let channel_ids = payment_claimed_event.htlcs.iter().map(|htlc| htlc.channel_id).collect();

That said, let me know if you’d still prefer to include channel_ids in PaymentClaimed, and I'd be happy to make that change. Thanks!

@benthecarman

Copy link
Copy Markdown
Contributor

Thanks, @shaavan , that is good enough

Comment threadlightning/src/ln/functional_test_utils.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
@ldk-reviews-bot

Copy link
Copy Markdown

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

@valentinewallace

Copy link
Copy Markdown
Contributor

nit: limit commit subject line in 2nd commit to ~50 characters

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.01 to pr3655.02 (diff):
Addressed @valentinewallace comments

  1. Updated the fields to be Vec<ChannelId>, and Vec<u128>
  2. Updated test utilities to check for all the channels id in events list, for improved test completeness.

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
Comment on lines +1553 to +1557
// legacy field
// (3, via_channel_id, option),
(4, amount_msat, required),
(5, via_user_channel_id, option),
// legacy field
// (5, via_user_channel_id, option),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should still write these fields for the sake of users who downgrade (can always write the first item in the vec). Also would be nice to comment in what version the fields became legacy.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Done! pr3655.03
I’ve updated the writing so that we maintain downgrade support.
Haven’t added a comment yet since I’m not sure what the next version number will be 😅 (would it be 0.1.3?)

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/events/mod.rs
Comment threadlightning/src/events/mod.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.02 to pr3655.03 (diff):
Addressed @valentinewallace comments

Changes:

  1. Expanded Documentation
  2. Properly write the legacy fields to maintain downgrade support.

@valentinewallace

Copy link
Copy Markdown
Contributor

Looks good, feel free to squash! Thanks!

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.03 to pr3655.04 (diff):
Addressed @valentinewallace comments

Changes:

  1. Squash commits.

@codecov

codecovBot commented Mar 15, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 96.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.37%. Comparing base (5bc9ffa) to head (591c5c8).
Report is 180 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/events/mod.rs90.47%0 Missing and 2 partials ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #3655 +/- ##
==========================================
+ Coverage 89.21% 91.37% +2.16% 
==========================================
Files 155 156 +1 Lines 118966 141344 +22378 Branches 118966 141344 +22378 ==========================================
+ Hits 106133 129159 +23026 + Misses 10253 9799 -454 + Partials 2580 2386 -194 

☔ 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.

@shaavanshaavan left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Looks good, feel free to squash! Thanks!

Awesome — thanks a lot for the review, Val! 🚀

Comment threadlightning/src/events/mod.rs
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.04 to pr3655.05 (diff):
Addressed @valentinewallace comments

Changes:

  • Added comment documenting when, and why via_channel_id_legacy, and via_user_channel_id_legacy were deprecated.

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.05 to pr3655.06 (diff):
Addressed @valentinewallace comments

Changes:

  1. Updated documentation to correctly reflect that the vector will be incomplete for HTLC created using versions prior to LDK 0.1.0 or prior.

@valentinewallace
valentinewallace self-requested a review April 4, 2025 17:11
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @valentinewallace! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be good to land after these last tweaks!

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.06 to pr3655.07 (diff):
Addressed @valentinewallace comments

Changes:

  1. Fixed comments to correctly represent for which version and cases the lists would be incomplete.

valentinewallace
valentinewallace previously approved these changes Apr 8, 2025
@jkczyz
jkczyz requested a review from joostjagerApril 10, 2025 17:29

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code looks good, test coverage could probably be improved a bit.

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/functional_tests.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.08 to pr3655.09 (diff):
Addressed @joostjager comments

Changes:

  1. Expanded test, to ensure that all the via_channel_id & via_user_channel_ids are present in PaymentClaimable in multi part payment case.

@valentinewallace

Copy link
Copy Markdown
Contributor

LGTM

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @joostjager! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 2nd Reminder

Hey @joostjager! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Comment threadlightning/src/events/mod.rs Outdated
via_channel_ids: Vec<ChannelId>,
/// The `user_channel_id`(s) corresponding to the channels over which the payment was received.
/// This will be an incomplete vector for MPP payment events created/serialized using LDK version 0.1.0 and prior.
via_user_channel_ids: Vec<u128>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's a bit late now, but would it be better to keep id and user_id together in a tuple? Not sure if there are interpretation issues when both vecs have different lengths?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thanks for bringing this up, Joost! I did consider that, but I wasn’t sure if it would offer a clear advantage. As far as I understand, both lists will always be of equal length since both fields were introduced together in the same version, so mismatched lengths shouldn’t arise.

Also, keeping them separate makes their distinction more explicit and follows the structure we’ve used in earlier LDK versions, where via_channel_id and via_user_channel_id were also separate fields.

That said, I’m open to discussing it further if you think a tuple-based design would still be better here! Would love to hear your thoughts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suppose the tuple leaves less room for questions like these. And maybe the original fields should have been a tuple/struct too. In general, I think it is good to keep the data types as strict as they can be.

But here it doesn't seem to be particular critical. Happy to go along with the other reviewer's view on it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we'd have to have a Vec<(ChannelId, Option<u128>)> since per ClaimablePayment::get_user_channel_ids docs user channel IDs are only always set after 117... Don't have a strong preference here although the option makes the field's API a bit less nice IMO.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The option would be consistent with HTLCPreviousHopData for example

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, isn't it the case that pre-117 data just translates to an empty vec<(..,..)> without requiring the option?

Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
// we test all generated events round-trip:
for event in &collected_events {
let ser = event.encode();
if let Some(deser) = events::Event::read(&mut &ser[..]).expect("event should deserialize") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the None case ok to ignore?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

AFAIU, yes. Some event enums are designed to map to a None value (for example, 0u8, 4u8, and 17u8), so getting an Ok(None) seems to indicate that the event was read successfully and no further checks are needed in this case.

That said, I'd love to hear @valentinewallace's thoughts to confirm if I’m understanding this correctly!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, some events are never written so I believe @shaavan is correct here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So could also continue when ser is None then, and unwrap the read? Not that it is all that important ofc.

@valentinewallacevalentinewallaceApr 28, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ser just returns Ok(()) on success, not an option.. But if you want to rearrange this code somehow, no strong preference here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like ser is just Vec<u8>. So if that is empty, we expect None from read? Maybe that can be used to make it slightly stricter and detect the case where read is unexpectedly returning None.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh right, sorry. It looks like for events where we don't write the actual event, we will still write the type for the event: https://github.com/lightningdevkit/rust-lightning/blob/main/lightning/src/events/mod.rs#L1809 so I don't think we can check if it's empty but we could check if only a u8 was written.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps a too much internal detail then. Can leave this as is as far as I am concerned.

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.09 to pr3655.10 (diff):
Addressed @joostjager comments

Changes:

  1. Add check that the via_channel_ids, and via_user_channel_ids only contains one element for the appropriate cases.

Comment threadlightning/src/ln/channelmanager.rs Outdated

/// Returns the inbound `user_channel_id`s for all HTLCs associated with the payment.
///
/// Note: This list will be incomplete for HTLCs created using LDK version 0.0.117 or prior.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment does seem to suggest that vecs can be different lengths?

@joostjagerjoostjagerApr 28, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@shaavan, @valentinewallace and I chatted about it. Seems something to say for a stronger type, especially because the vecs both map from PrevHopData already. But it's a bit late now also, and not too critical. So leaving up to you to decide.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thanks so much, Joost and Val, for the pointers!
I went ahead and updated the PaymentClaimable field to a via_channel_id_pairs, containing a Vec<(ChannelId, Option<u128>)>, in pr3655.11.

Let me know if it looks good — thanks again!

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.10 to pr3655.11 (diff):
Addressed @valentinewallace, @joostjager comments

Changes:

  1. Update PaymentClaimable field to be an ordered via_channel_id_pairs pair.

@joostjager

Copy link
Copy Markdown
Contributor

@shaavan just a side comment: I really like how you offer diffs to reviewers using pr3655.x branches!

joostjager
joostjager previously approved these changes Apr 29, 2025

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seeing how this worked out, I think vec(tuple) is the right move. Hopefully you feel the same!

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
Comment threadlightning/src/ln/blinded_payment_tests.rs Outdated

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Accidentally approved. Wanted to await your replies first.

These two utilities will be used in following commit to get all the
inbound channel_ids, and user_channel_ids associated with all the
parts of a payment.
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.11 to pr3655.12 (diff):
Addressed @joostjager comments

Changes:

  1. Rename via_channel_id_pairs & get_channel_id_pairs -> inbound_channel_ids
  2. Cleaned up testing.

@shaavan

Copy link
Copy Markdown
MemberAuthor

@shaavan just a side comment: I really like how you offer diffs to reviewers using pr3655.x branches!

Thanks so much, @joostjager — really appreciate you noticing that! :)

Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
Comment threadlightning/src/ln/functional_test_utils.rs Outdated

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM besides a few nits.

Comment threadlightning/src/ln/functional_tests.rs Outdated
shaavan added 2 commits May 1, 2025 20:37
Previously, `channel_id` in `PaymentClaimable` only listed a single
inbound channel, which was misleading for MPP payments arriving via
multiple channels.
To better represent MPP scenarios, this update introduces:
- `via_channel_ids`: A list of all inbound channels used in the payment.
- `via_user_channel_ids`: The corresponding user-defined channel IDs for
each inbound channel.
This change ensures a more accurate representation of multi-path payments
while maintaining backward compatibility.
- Expand testing to ensure proper serialise-deserialise round-trip for
all events.
- Expand a multi-Part payment test to ensure that all the channel ids &
user channel ids are present in the PaymentClaimable event
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.12 to pr3655.13 (diff):
Addressed @joostjager comments

Changes:

  1. Cleaned up tests

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @shaavan! I like the tuple change 👌

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for this contribution. Great work and excellent communication.

@valentinewallace
valentinewallace merged commit 29a6383 into lightningdevkit:mainMay 1, 2025
Sign up for freeto 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.

PaymentClaimable lists inbound channel id

5 participants

@shaavan@ldk-reviews-bot@benthecarman@valentinewallace@joostjager
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Expand PaymentClaimable to include all inbound channel IDs for a payment - #3655

Merged
valentinewallace merged 3 commits into
lightningdevkit:mainfrom
shaavan:i2274
May 1, 2025
Merged

Expand PaymentClaimable to include all inbound channel IDs for a payment #3655
valentinewallace merged 3 commits into
lightningdevkit:mainfrom
shaavan:i2274

Conversation

@shaavan

Copy link
Copy Markdown
Member

Resolves#2274

This PR expands PaymentClaimable to include all inbound channel_ids and user_channel_ids associated with a payment.
This update ensures a clearer representation of the channels used, especially for MPP payments.

@ldk-reviews-bot

ldk-reviews-bot commented Mar 8, 2025

Copy link
Copy Markdown

👋 Thanks for assigning @joostjager 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.

@shaavan

Copy link
Copy Markdown
MemberAuthor

@benthecarman

Would also be nice if the same information is available on the PaymentClaimed event too

In the current version, I haven’t included channel_ids and user_channel_ids for PaymentClaimed, as they can be easily derived from the event itself:

let channel_ids = payment_claimed_event.htlcs.iter().map(|htlc| htlc.channel_id).collect();

That said, let me know if you’d still prefer to include channel_ids in PaymentClaimed, and I'd be happy to make that change. Thanks!

@benthecarman

Copy link
Copy Markdown
Contributor

Thanks, @shaavan , that is good enough

Comment threadlightning/src/ln/functional_test_utils.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
@ldk-reviews-bot

Copy link
Copy Markdown

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

@valentinewallace

Copy link
Copy Markdown
Contributor

nit: limit commit subject line in 2nd commit to ~50 characters

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.01 to pr3655.02 (diff):
Addressed @valentinewallace comments

  1. Updated the fields to be Vec<ChannelId>, and Vec<u128>
  2. Updated test utilities to check for all the channels id in events list, for improved test completeness.

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
Comment on lines +1553 to +1557
// legacy field
// (3, via_channel_id, option),
(4, amount_msat, required),
(5, via_user_channel_id, option),
// legacy field
// (5, via_user_channel_id, option),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should still write these fields for the sake of users who downgrade (can always write the first item in the vec). Also would be nice to comment in what version the fields became legacy.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Done! pr3655.03
I’ve updated the writing so that we maintain downgrade support.
Haven’t added a comment yet since I’m not sure what the next version number will be 😅 (would it be 0.1.3?)

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/events/mod.rs
Comment threadlightning/src/events/mod.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.02 to pr3655.03 (diff):
Addressed @valentinewallace comments

Changes:

  1. Expanded Documentation
  2. Properly write the legacy fields to maintain downgrade support.

@valentinewallace

Copy link
Copy Markdown
Contributor

Looks good, feel free to squash! Thanks!

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.03 to pr3655.04 (diff):
Addressed @valentinewallace comments

Changes:

  1. Squash commits.

@codecov

codecovBot commented Mar 15, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 96.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.37%. Comparing base (5bc9ffa) to head (591c5c8).
Report is 180 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/events/mod.rs90.47%0 Missing and 2 partials ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #3655 +/- ##
==========================================
+ Coverage 89.21% 91.37% +2.16% 
==========================================
Files 155 156 +1 Lines 118966 141344 +22378 Branches 118966 141344 +22378 ==========================================
+ Hits 106133 129159 +23026 + Misses 10253 9799 -454 + Partials 2580 2386 -194 

☔ 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.

@shaavanshaavan left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Looks good, feel free to squash! Thanks!

Awesome — thanks a lot for the review, Val! 🚀

Comment threadlightning/src/events/mod.rs
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.04 to pr3655.05 (diff):
Addressed @valentinewallace comments

Changes:

  • Added comment documenting when, and why via_channel_id_legacy, and via_user_channel_id_legacy were deprecated.

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.05 to pr3655.06 (diff):
Addressed @valentinewallace comments

Changes:

  1. Updated documentation to correctly reflect that the vector will be incomplete for HTLC created using versions prior to LDK 0.1.0 or prior.

@valentinewallace
valentinewallace self-requested a review April 4, 2025 17:11
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @valentinewallace! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be good to land after these last tweaks!

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.06 to pr3655.07 (diff):
Addressed @valentinewallace comments

Changes:

  1. Fixed comments to correctly represent for which version and cases the lists would be incomplete.

valentinewallace
valentinewallace previously approved these changes Apr 8, 2025
@jkczyz
jkczyz requested a review from joostjagerApril 10, 2025 17:29

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code looks good, test coverage could probably be improved a bit.

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/functional_tests.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.08 to pr3655.09 (diff):
Addressed @joostjager comments

Changes:

  1. Expanded test, to ensure that all the via_channel_id & via_user_channel_ids are present in PaymentClaimable in multi part payment case.

@valentinewallace

Copy link
Copy Markdown
Contributor

LGTM

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @joostjager! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 2nd Reminder

Hey @joostjager! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Comment threadlightning/src/events/mod.rs Outdated
via_channel_ids: Vec<ChannelId>,
/// The `user_channel_id`(s) corresponding to the channels over which the payment was received.
/// This will be an incomplete vector for MPP payment events created/serialized using LDK version 0.1.0 and prior.
via_user_channel_ids: Vec<u128>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's a bit late now, but would it be better to keep id and user_id together in a tuple? Not sure if there are interpretation issues when both vecs have different lengths?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thanks for bringing this up, Joost! I did consider that, but I wasn’t sure if it would offer a clear advantage. As far as I understand, both lists will always be of equal length since both fields were introduced together in the same version, so mismatched lengths shouldn’t arise.

Also, keeping them separate makes their distinction more explicit and follows the structure we’ve used in earlier LDK versions, where via_channel_id and via_user_channel_id were also separate fields.

That said, I’m open to discussing it further if you think a tuple-based design would still be better here! Would love to hear your thoughts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suppose the tuple leaves less room for questions like these. And maybe the original fields should have been a tuple/struct too. In general, I think it is good to keep the data types as strict as they can be.

But here it doesn't seem to be particular critical. Happy to go along with the other reviewer's view on it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we'd have to have a Vec<(ChannelId, Option<u128>)> since per ClaimablePayment::get_user_channel_ids docs user channel IDs are only always set after 117... Don't have a strong preference here although the option makes the field's API a bit less nice IMO.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The option would be consistent with HTLCPreviousHopData for example

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, isn't it the case that pre-117 data just translates to an empty vec<(..,..)> without requiring the option?

Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
// we test all generated events round-trip:
for event in &collected_events {
let ser = event.encode();
if let Some(deser) = events::Event::read(&mut &ser[..]).expect("event should deserialize") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the None case ok to ignore?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

AFAIU, yes. Some event enums are designed to map to a None value (for example, 0u8, 4u8, and 17u8), so getting an Ok(None) seems to indicate that the event was read successfully and no further checks are needed in this case.

That said, I'd love to hear @valentinewallace's thoughts to confirm if I’m understanding this correctly!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, some events are never written so I believe @shaavan is correct here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So could also continue when ser is None then, and unwrap the read? Not that it is all that important ofc.

@valentinewallacevalentinewallaceApr 28, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ser just returns Ok(()) on success, not an option.. But if you want to rearrange this code somehow, no strong preference here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like ser is just Vec<u8>. So if that is empty, we expect None from read? Maybe that can be used to make it slightly stricter and detect the case where read is unexpectedly returning None.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh right, sorry. It looks like for events where we don't write the actual event, we will still write the type for the event: https://github.com/lightningdevkit/rust-lightning/blob/main/lightning/src/events/mod.rs#L1809 so I don't think we can check if it's empty but we could check if only a u8 was written.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps a too much internal detail then. Can leave this as is as far as I am concerned.

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.09 to pr3655.10 (diff):
Addressed @joostjager comments

Changes:

  1. Add check that the via_channel_ids, and via_user_channel_ids only contains one element for the appropriate cases.

Comment threadlightning/src/ln/channelmanager.rs Outdated

/// Returns the inbound `user_channel_id`s for all HTLCs associated with the payment.
///
/// Note: This list will be incomplete for HTLCs created using LDK version 0.0.117 or prior.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment does seem to suggest that vecs can be different lengths?

@joostjagerjoostjagerApr 28, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@shaavan, @valentinewallace and I chatted about it. Seems something to say for a stronger type, especially because the vecs both map from PrevHopData already. But it's a bit late now also, and not too critical. So leaving up to you to decide.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thanks so much, Joost and Val, for the pointers!
I went ahead and updated the PaymentClaimable field to a via_channel_id_pairs, containing a Vec<(ChannelId, Option<u128>)>, in pr3655.11.

Let me know if it looks good — thanks again!

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.10 to pr3655.11 (diff):
Addressed @valentinewallace, @joostjager comments

Changes:

  1. Update PaymentClaimable field to be an ordered via_channel_id_pairs pair.

@joostjager

Copy link
Copy Markdown
Contributor

@shaavan just a side comment: I really like how you offer diffs to reviewers using pr3655.x branches!

joostjager
joostjager previously approved these changes Apr 29, 2025

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seeing how this worked out, I think vec(tuple) is the right move. Hopefully you feel the same!

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
Comment threadlightning/src/ln/blinded_payment_tests.rs Outdated

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Accidentally approved. Wanted to await your replies first.

These two utilities will be used in following commit to get all the
inbound channel_ids, and user_channel_ids associated with all the
parts of a payment.
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.11 to pr3655.12 (diff):
Addressed @joostjager comments

Changes:

  1. Rename via_channel_id_pairs & get_channel_id_pairs -> inbound_channel_ids
  2. Cleaned up testing.

@shaavan

Copy link
Copy Markdown
MemberAuthor

@shaavan just a side comment: I really like how you offer diffs to reviewers using pr3655.x branches!

Thanks so much, @joostjager — really appreciate you noticing that! :)

Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
Comment threadlightning/src/ln/functional_test_utils.rs Outdated

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM besides a few nits.

Comment threadlightning/src/ln/functional_tests.rs Outdated
shaavan added 2 commits May 1, 2025 20:37
Previously, `channel_id` in `PaymentClaimable` only listed a single
inbound channel, which was misleading for MPP payments arriving via
multiple channels.
To better represent MPP scenarios, this update introduces:
- `via_channel_ids`: A list of all inbound channels used in the payment.
- `via_user_channel_ids`: The corresponding user-defined channel IDs for
each inbound channel.
This change ensures a more accurate representation of multi-path payments
while maintaining backward compatibility.
- Expand testing to ensure proper serialise-deserialise round-trip for
all events.
- Expand a multi-Part payment test to ensure that all the channel ids &
user channel ids are present in the PaymentClaimable event
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.12 to pr3655.13 (diff):
Addressed @joostjager comments

Changes:

  1. Cleaned up tests

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @shaavan! I like the tuple change 👌

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for this contribution. Great work and excellent communication.

@valentinewallace
valentinewallace merged commit 29a6383 into lightningdevkit:mainMay 1, 2025
Sign up for freeto 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.

PaymentClaimable lists inbound channel id

5 participants

@shaavan@ldk-reviews-bot@benthecarman@valentinewallace@joostjager
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Expand PaymentClaimable to include all inbound channel IDs for a payment - #3655

Merged
valentinewallace merged 3 commits into
lightningdevkit:mainfrom
shaavan:i2274
May 1, 2025
Merged

Expand PaymentClaimable to include all inbound channel IDs for a payment #3655
valentinewallace merged 3 commits into
lightningdevkit:mainfrom
shaavan:i2274

Conversation

@shaavan

Copy link
Copy Markdown
Member

Resolves#2274

This PR expands PaymentClaimable to include all inbound channel_ids and user_channel_ids associated with a payment.
This update ensures a clearer representation of the channels used, especially for MPP payments.

@ldk-reviews-bot

ldk-reviews-bot commented Mar 8, 2025

Copy link
Copy Markdown

👋 Thanks for assigning @joostjager 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.

@shaavan

Copy link
Copy Markdown
MemberAuthor

@benthecarman

Would also be nice if the same information is available on the PaymentClaimed event too

In the current version, I haven’t included channel_ids and user_channel_ids for PaymentClaimed, as they can be easily derived from the event itself:

let channel_ids = payment_claimed_event.htlcs.iter().map(|htlc| htlc.channel_id).collect();

That said, let me know if you’d still prefer to include channel_ids in PaymentClaimed, and I'd be happy to make that change. Thanks!

@benthecarman

Copy link
Copy Markdown
Contributor

Thanks, @shaavan , that is good enough

Comment threadlightning/src/ln/functional_test_utils.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
@ldk-reviews-bot

Copy link
Copy Markdown

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

@valentinewallace

Copy link
Copy Markdown
Contributor

nit: limit commit subject line in 2nd commit to ~50 characters

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.01 to pr3655.02 (diff):
Addressed @valentinewallace comments

  1. Updated the fields to be Vec<ChannelId>, and Vec<u128>
  2. Updated test utilities to check for all the channels id in events list, for improved test completeness.

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
Comment on lines +1553 to +1557
// legacy field
// (3, via_channel_id, option),
(4, amount_msat, required),
(5, via_user_channel_id, option),
// legacy field
// (5, via_user_channel_id, option),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should still write these fields for the sake of users who downgrade (can always write the first item in the vec). Also would be nice to comment in what version the fields became legacy.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Done! pr3655.03
I’ve updated the writing so that we maintain downgrade support.
Haven’t added a comment yet since I’m not sure what the next version number will be 😅 (would it be 0.1.3?)

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/events/mod.rs
Comment threadlightning/src/events/mod.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.02 to pr3655.03 (diff):
Addressed @valentinewallace comments

Changes:

  1. Expanded Documentation
  2. Properly write the legacy fields to maintain downgrade support.

@valentinewallace

Copy link
Copy Markdown
Contributor

Looks good, feel free to squash! Thanks!

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.03 to pr3655.04 (diff):
Addressed @valentinewallace comments

Changes:

  1. Squash commits.

@codecov

codecovBot commented Mar 15, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 96.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.37%. Comparing base (5bc9ffa) to head (591c5c8).
Report is 180 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/events/mod.rs90.47%0 Missing and 2 partials ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #3655 +/- ##
==========================================
+ Coverage 89.21% 91.37% +2.16% 
==========================================
Files 155 156 +1 Lines 118966 141344 +22378 Branches 118966 141344 +22378 ==========================================
+ Hits 106133 129159 +23026 + Misses 10253 9799 -454 + Partials 2580 2386 -194 

☔ 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.

@shaavanshaavan left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Looks good, feel free to squash! Thanks!

Awesome — thanks a lot for the review, Val! 🚀

Comment threadlightning/src/events/mod.rs
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.04 to pr3655.05 (diff):
Addressed @valentinewallace comments

Changes:

  • Added comment documenting when, and why via_channel_id_legacy, and via_user_channel_id_legacy were deprecated.

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.05 to pr3655.06 (diff):
Addressed @valentinewallace comments

Changes:

  1. Updated documentation to correctly reflect that the vector will be incomplete for HTLC created using versions prior to LDK 0.1.0 or prior.

@valentinewallace
valentinewallace self-requested a review April 4, 2025 17:11
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @valentinewallace! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be good to land after these last tweaks!

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.06 to pr3655.07 (diff):
Addressed @valentinewallace comments

Changes:

  1. Fixed comments to correctly represent for which version and cases the lists would be incomplete.

valentinewallace
valentinewallace previously approved these changes Apr 8, 2025
@jkczyz
jkczyz requested a review from joostjagerApril 10, 2025 17:29

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code looks good, test coverage could probably be improved a bit.

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/functional_tests.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.08 to pr3655.09 (diff):
Addressed @joostjager comments

Changes:

  1. Expanded test, to ensure that all the via_channel_id & via_user_channel_ids are present in PaymentClaimable in multi part payment case.

@valentinewallace

Copy link
Copy Markdown
Contributor

LGTM

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @joostjager! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 2nd Reminder

Hey @joostjager! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Comment threadlightning/src/events/mod.rs Outdated
via_channel_ids: Vec<ChannelId>,
/// The `user_channel_id`(s) corresponding to the channels over which the payment was received.
/// This will be an incomplete vector for MPP payment events created/serialized using LDK version 0.1.0 and prior.
via_user_channel_ids: Vec<u128>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's a bit late now, but would it be better to keep id and user_id together in a tuple? Not sure if there are interpretation issues when both vecs have different lengths?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thanks for bringing this up, Joost! I did consider that, but I wasn’t sure if it would offer a clear advantage. As far as I understand, both lists will always be of equal length since both fields were introduced together in the same version, so mismatched lengths shouldn’t arise.

Also, keeping them separate makes their distinction more explicit and follows the structure we’ve used in earlier LDK versions, where via_channel_id and via_user_channel_id were also separate fields.

That said, I’m open to discussing it further if you think a tuple-based design would still be better here! Would love to hear your thoughts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suppose the tuple leaves less room for questions like these. And maybe the original fields should have been a tuple/struct too. In general, I think it is good to keep the data types as strict as they can be.

But here it doesn't seem to be particular critical. Happy to go along with the other reviewer's view on it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we'd have to have a Vec<(ChannelId, Option<u128>)> since per ClaimablePayment::get_user_channel_ids docs user channel IDs are only always set after 117... Don't have a strong preference here although the option makes the field's API a bit less nice IMO.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The option would be consistent with HTLCPreviousHopData for example

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, isn't it the case that pre-117 data just translates to an empty vec<(..,..)> without requiring the option?

Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
// we test all generated events round-trip:
for event in &collected_events {
let ser = event.encode();
if let Some(deser) = events::Event::read(&mut &ser[..]).expect("event should deserialize") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the None case ok to ignore?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

AFAIU, yes. Some event enums are designed to map to a None value (for example, 0u8, 4u8, and 17u8), so getting an Ok(None) seems to indicate that the event was read successfully and no further checks are needed in this case.

That said, I'd love to hear @valentinewallace's thoughts to confirm if I’m understanding this correctly!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, some events are never written so I believe @shaavan is correct here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So could also continue when ser is None then, and unwrap the read? Not that it is all that important ofc.

@valentinewallacevalentinewallaceApr 28, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ser just returns Ok(()) on success, not an option.. But if you want to rearrange this code somehow, no strong preference here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like ser is just Vec<u8>. So if that is empty, we expect None from read? Maybe that can be used to make it slightly stricter and detect the case where read is unexpectedly returning None.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh right, sorry. It looks like for events where we don't write the actual event, we will still write the type for the event: https://github.com/lightningdevkit/rust-lightning/blob/main/lightning/src/events/mod.rs#L1809 so I don't think we can check if it's empty but we could check if only a u8 was written.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps a too much internal detail then. Can leave this as is as far as I am concerned.

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.09 to pr3655.10 (diff):
Addressed @joostjager comments

Changes:

  1. Add check that the via_channel_ids, and via_user_channel_ids only contains one element for the appropriate cases.

Comment threadlightning/src/ln/channelmanager.rs Outdated

/// Returns the inbound `user_channel_id`s for all HTLCs associated with the payment.
///
/// Note: This list will be incomplete for HTLCs created using LDK version 0.0.117 or prior.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment does seem to suggest that vecs can be different lengths?

@joostjagerjoostjagerApr 28, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@shaavan, @valentinewallace and I chatted about it. Seems something to say for a stronger type, especially because the vecs both map from PrevHopData already. But it's a bit late now also, and not too critical. So leaving up to you to decide.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thanks so much, Joost and Val, for the pointers!
I went ahead and updated the PaymentClaimable field to a via_channel_id_pairs, containing a Vec<(ChannelId, Option<u128>)>, in pr3655.11.

Let me know if it looks good — thanks again!

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.10 to pr3655.11 (diff):
Addressed @valentinewallace, @joostjager comments

Changes:

  1. Update PaymentClaimable field to be an ordered via_channel_id_pairs pair.

@joostjager

Copy link
Copy Markdown
Contributor

@shaavan just a side comment: I really like how you offer diffs to reviewers using pr3655.x branches!

joostjager
joostjager previously approved these changes Apr 29, 2025

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seeing how this worked out, I think vec(tuple) is the right move. Hopefully you feel the same!

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
Comment threadlightning/src/ln/blinded_payment_tests.rs Outdated

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Accidentally approved. Wanted to await your replies first.

These two utilities will be used in following commit to get all the
inbound channel_ids, and user_channel_ids associated with all the
parts of a payment.
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.11 to pr3655.12 (diff):
Addressed @joostjager comments

Changes:

  1. Rename via_channel_id_pairs & get_channel_id_pairs -> inbound_channel_ids
  2. Cleaned up testing.

@shaavan

Copy link
Copy Markdown
MemberAuthor

@shaavan just a side comment: I really like how you offer diffs to reviewers using pr3655.x branches!

Thanks so much, @joostjager — really appreciate you noticing that! :)

Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
Comment threadlightning/src/ln/functional_test_utils.rs Outdated

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM besides a few nits.

Comment threadlightning/src/ln/functional_tests.rs Outdated
shaavan added 2 commits May 1, 2025 20:37
Previously, `channel_id` in `PaymentClaimable` only listed a single
inbound channel, which was misleading for MPP payments arriving via
multiple channels.
To better represent MPP scenarios, this update introduces:
- `via_channel_ids`: A list of all inbound channels used in the payment.
- `via_user_channel_ids`: The corresponding user-defined channel IDs for
each inbound channel.
This change ensures a more accurate representation of multi-path payments
while maintaining backward compatibility.
- Expand testing to ensure proper serialise-deserialise round-trip for
all events.
- Expand a multi-Part payment test to ensure that all the channel ids &
user channel ids are present in the PaymentClaimable event
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.12 to pr3655.13 (diff):
Addressed @joostjager comments

Changes:

  1. Cleaned up tests

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @shaavan! I like the tuple change 👌

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for this contribution. Great work and excellent communication.

@valentinewallace
valentinewallace merged commit 29a6383 into lightningdevkit:mainMay 1, 2025
Sign up for freeto 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.

PaymentClaimable lists inbound channel id

5 participants

@shaavan@ldk-reviews-bot@benthecarman@valentinewallace@joostjager
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Expand PaymentClaimable to include all inbound channel IDs for a payment - #3655

Merged
valentinewallace merged 3 commits into
lightningdevkit:mainfrom
shaavan:i2274
May 1, 2025
Merged

Expand PaymentClaimable to include all inbound channel IDs for a payment #3655
valentinewallace merged 3 commits into
lightningdevkit:mainfrom
shaavan:i2274

Conversation

@shaavan

Copy link
Copy Markdown
Member

Resolves#2274

This PR expands PaymentClaimable to include all inbound channel_ids and user_channel_ids associated with a payment.
This update ensures a clearer representation of the channels used, especially for MPP payments.

@ldk-reviews-bot

ldk-reviews-bot commented Mar 8, 2025

Copy link
Copy Markdown

👋 Thanks for assigning @joostjager 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.

@shaavan

Copy link
Copy Markdown
MemberAuthor

@benthecarman

Would also be nice if the same information is available on the PaymentClaimed event too

In the current version, I haven’t included channel_ids and user_channel_ids for PaymentClaimed, as they can be easily derived from the event itself:

let channel_ids = payment_claimed_event.htlcs.iter().map(|htlc| htlc.channel_id).collect();

That said, let me know if you’d still prefer to include channel_ids in PaymentClaimed, and I'd be happy to make that change. Thanks!

@benthecarman

Copy link
Copy Markdown
Contributor

Thanks, @shaavan , that is good enough

Comment threadlightning/src/ln/functional_test_utils.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
@ldk-reviews-bot

Copy link
Copy Markdown

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

@valentinewallace

Copy link
Copy Markdown
Contributor

nit: limit commit subject line in 2nd commit to ~50 characters

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.01 to pr3655.02 (diff):
Addressed @valentinewallace comments

  1. Updated the fields to be Vec<ChannelId>, and Vec<u128>
  2. Updated test utilities to check for all the channels id in events list, for improved test completeness.

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
Comment on lines +1553 to +1557
// legacy field
// (3, via_channel_id, option),
(4, amount_msat, required),
(5, via_user_channel_id, option),
// legacy field
// (5, via_user_channel_id, option),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should still write these fields for the sake of users who downgrade (can always write the first item in the vec). Also would be nice to comment in what version the fields became legacy.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Done! pr3655.03
I’ve updated the writing so that we maintain downgrade support.
Haven’t added a comment yet since I’m not sure what the next version number will be 😅 (would it be 0.1.3?)

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/events/mod.rs
Comment threadlightning/src/events/mod.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.02 to pr3655.03 (diff):
Addressed @valentinewallace comments

Changes:

  1. Expanded Documentation
  2. Properly write the legacy fields to maintain downgrade support.

@valentinewallace

Copy link
Copy Markdown
Contributor

Looks good, feel free to squash! Thanks!

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.03 to pr3655.04 (diff):
Addressed @valentinewallace comments

Changes:

  1. Squash commits.

@codecov

codecovBot commented Mar 15, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 96.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.37%. Comparing base (5bc9ffa) to head (591c5c8).
Report is 180 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/events/mod.rs90.47%0 Missing and 2 partials ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #3655 +/- ##
==========================================
+ Coverage 89.21% 91.37% +2.16% 
==========================================
Files 155 156 +1 Lines 118966 141344 +22378 Branches 118966 141344 +22378 ==========================================
+ Hits 106133 129159 +23026 + Misses 10253 9799 -454 + Partials 2580 2386 -194 

☔ 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.

@shaavanshaavan left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Looks good, feel free to squash! Thanks!

Awesome — thanks a lot for the review, Val! 🚀

Comment threadlightning/src/events/mod.rs
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.04 to pr3655.05 (diff):
Addressed @valentinewallace comments

Changes:

  • Added comment documenting when, and why via_channel_id_legacy, and via_user_channel_id_legacy were deprecated.

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.05 to pr3655.06 (diff):
Addressed @valentinewallace comments

Changes:

  1. Updated documentation to correctly reflect that the vector will be incomplete for HTLC created using versions prior to LDK 0.1.0 or prior.

@valentinewallace
valentinewallace self-requested a review April 4, 2025 17:11
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @valentinewallace! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be good to land after these last tweaks!

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.06 to pr3655.07 (diff):
Addressed @valentinewallace comments

Changes:

  1. Fixed comments to correctly represent for which version and cases the lists would be incomplete.

valentinewallace
valentinewallace previously approved these changes Apr 8, 2025
@jkczyz
jkczyz requested a review from joostjagerApril 10, 2025 17:29

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code looks good, test coverage could probably be improved a bit.

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/functional_tests.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.08 to pr3655.09 (diff):
Addressed @joostjager comments

Changes:

  1. Expanded test, to ensure that all the via_channel_id & via_user_channel_ids are present in PaymentClaimable in multi part payment case.

@valentinewallace

Copy link
Copy Markdown
Contributor

LGTM

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @joostjager! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 2nd Reminder

Hey @joostjager! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Comment threadlightning/src/events/mod.rs Outdated
via_channel_ids: Vec<ChannelId>,
/// The `user_channel_id`(s) corresponding to the channels over which the payment was received.
/// This will be an incomplete vector for MPP payment events created/serialized using LDK version 0.1.0 and prior.
via_user_channel_ids: Vec<u128>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's a bit late now, but would it be better to keep id and user_id together in a tuple? Not sure if there are interpretation issues when both vecs have different lengths?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thanks for bringing this up, Joost! I did consider that, but I wasn’t sure if it would offer a clear advantage. As far as I understand, both lists will always be of equal length since both fields were introduced together in the same version, so mismatched lengths shouldn’t arise.

Also, keeping them separate makes their distinction more explicit and follows the structure we’ve used in earlier LDK versions, where via_channel_id and via_user_channel_id were also separate fields.

That said, I’m open to discussing it further if you think a tuple-based design would still be better here! Would love to hear your thoughts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suppose the tuple leaves less room for questions like these. And maybe the original fields should have been a tuple/struct too. In general, I think it is good to keep the data types as strict as they can be.

But here it doesn't seem to be particular critical. Happy to go along with the other reviewer's view on it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we'd have to have a Vec<(ChannelId, Option<u128>)> since per ClaimablePayment::get_user_channel_ids docs user channel IDs are only always set after 117... Don't have a strong preference here although the option makes the field's API a bit less nice IMO.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The option would be consistent with HTLCPreviousHopData for example

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, isn't it the case that pre-117 data just translates to an empty vec<(..,..)> without requiring the option?

Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
// we test all generated events round-trip:
for event in &collected_events {
let ser = event.encode();
if let Some(deser) = events::Event::read(&mut &ser[..]).expect("event should deserialize") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the None case ok to ignore?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

AFAIU, yes. Some event enums are designed to map to a None value (for example, 0u8, 4u8, and 17u8), so getting an Ok(None) seems to indicate that the event was read successfully and no further checks are needed in this case.

That said, I'd love to hear @valentinewallace's thoughts to confirm if I’m understanding this correctly!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, some events are never written so I believe @shaavan is correct here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So could also continue when ser is None then, and unwrap the read? Not that it is all that important ofc.

@valentinewallacevalentinewallaceApr 28, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ser just returns Ok(()) on success, not an option.. But if you want to rearrange this code somehow, no strong preference here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like ser is just Vec<u8>. So if that is empty, we expect None from read? Maybe that can be used to make it slightly stricter and detect the case where read is unexpectedly returning None.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh right, sorry. It looks like for events where we don't write the actual event, we will still write the type for the event: https://github.com/lightningdevkit/rust-lightning/blob/main/lightning/src/events/mod.rs#L1809 so I don't think we can check if it's empty but we could check if only a u8 was written.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps a too much internal detail then. Can leave this as is as far as I am concerned.

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.09 to pr3655.10 (diff):
Addressed @joostjager comments

Changes:

  1. Add check that the via_channel_ids, and via_user_channel_ids only contains one element for the appropriate cases.

Comment threadlightning/src/ln/channelmanager.rs Outdated

/// Returns the inbound `user_channel_id`s for all HTLCs associated with the payment.
///
/// Note: This list will be incomplete for HTLCs created using LDK version 0.0.117 or prior.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment does seem to suggest that vecs can be different lengths?

@joostjagerjoostjagerApr 28, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@shaavan, @valentinewallace and I chatted about it. Seems something to say for a stronger type, especially because the vecs both map from PrevHopData already. But it's a bit late now also, and not too critical. So leaving up to you to decide.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thanks so much, Joost and Val, for the pointers!
I went ahead and updated the PaymentClaimable field to a via_channel_id_pairs, containing a Vec<(ChannelId, Option<u128>)>, in pr3655.11.

Let me know if it looks good — thanks again!

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.10 to pr3655.11 (diff):
Addressed @valentinewallace, @joostjager comments

Changes:

  1. Update PaymentClaimable field to be an ordered via_channel_id_pairs pair.

@joostjager

Copy link
Copy Markdown
Contributor

@shaavan just a side comment: I really like how you offer diffs to reviewers using pr3655.x branches!

joostjager
joostjager previously approved these changes Apr 29, 2025

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seeing how this worked out, I think vec(tuple) is the right move. Hopefully you feel the same!

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
Comment threadlightning/src/ln/blinded_payment_tests.rs Outdated

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Accidentally approved. Wanted to await your replies first.

These two utilities will be used in following commit to get all the
inbound channel_ids, and user_channel_ids associated with all the
parts of a payment.
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.11 to pr3655.12 (diff):
Addressed @joostjager comments

Changes:

  1. Rename via_channel_id_pairs & get_channel_id_pairs -> inbound_channel_ids
  2. Cleaned up testing.

@shaavan

Copy link
Copy Markdown
MemberAuthor

@shaavan just a side comment: I really like how you offer diffs to reviewers using pr3655.x branches!

Thanks so much, @joostjager — really appreciate you noticing that! :)

Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
Comment threadlightning/src/ln/functional_test_utils.rs Outdated

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM besides a few nits.

Comment threadlightning/src/ln/functional_tests.rs Outdated
shaavan added 2 commits May 1, 2025 20:37
Previously, `channel_id` in `PaymentClaimable` only listed a single
inbound channel, which was misleading for MPP payments arriving via
multiple channels.
To better represent MPP scenarios, this update introduces:
- `via_channel_ids`: A list of all inbound channels used in the payment.
- `via_user_channel_ids`: The corresponding user-defined channel IDs for
each inbound channel.
This change ensures a more accurate representation of multi-path payments
while maintaining backward compatibility.
- Expand testing to ensure proper serialise-deserialise round-trip for
all events.
- Expand a multi-Part payment test to ensure that all the channel ids &
user channel ids are present in the PaymentClaimable event
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.12 to pr3655.13 (diff):
Addressed @joostjager comments

Changes:

  1. Cleaned up tests

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @shaavan! I like the tuple change 👌

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for this contribution. Great work and excellent communication.

@valentinewallace
valentinewallace merged commit 29a6383 into lightningdevkit:mainMay 1, 2025
Sign up for freeto 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.

PaymentClaimable lists inbound channel id

5 participants

@shaavan@ldk-reviews-bot@benthecarman@valentinewallace@joostjager
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Expand PaymentClaimable to include all inbound channel IDs for a payment - #3655

Merged
valentinewallace merged 3 commits into
lightningdevkit:mainfrom
shaavan:i2274
May 1, 2025
Merged

Expand PaymentClaimable to include all inbound channel IDs for a payment #3655
valentinewallace merged 3 commits into
lightningdevkit:mainfrom
shaavan:i2274

Conversation

@shaavan

Copy link
Copy Markdown
Member

Resolves#2274

This PR expands PaymentClaimable to include all inbound channel_ids and user_channel_ids associated with a payment.
This update ensures a clearer representation of the channels used, especially for MPP payments.

@ldk-reviews-bot

ldk-reviews-bot commented Mar 8, 2025

Copy link
Copy Markdown

👋 Thanks for assigning @joostjager 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.

@shaavan

Copy link
Copy Markdown
MemberAuthor

@benthecarman

Would also be nice if the same information is available on the PaymentClaimed event too

In the current version, I haven’t included channel_ids and user_channel_ids for PaymentClaimed, as they can be easily derived from the event itself:

let channel_ids = payment_claimed_event.htlcs.iter().map(|htlc| htlc.channel_id).collect();

That said, let me know if you’d still prefer to include channel_ids in PaymentClaimed, and I'd be happy to make that change. Thanks!

@benthecarman

Copy link
Copy Markdown
Contributor

Thanks, @shaavan , that is good enough

Comment threadlightning/src/ln/functional_test_utils.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
@ldk-reviews-bot

Copy link
Copy Markdown

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

@valentinewallace

Copy link
Copy Markdown
Contributor

nit: limit commit subject line in 2nd commit to ~50 characters

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.01 to pr3655.02 (diff):
Addressed @valentinewallace comments

  1. Updated the fields to be Vec<ChannelId>, and Vec<u128>
  2. Updated test utilities to check for all the channels id in events list, for improved test completeness.

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
Comment on lines +1553 to +1557
// legacy field
// (3, via_channel_id, option),
(4, amount_msat, required),
(5, via_user_channel_id, option),
// legacy field
// (5, via_user_channel_id, option),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should still write these fields for the sake of users who downgrade (can always write the first item in the vec). Also would be nice to comment in what version the fields became legacy.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Done! pr3655.03
I’ve updated the writing so that we maintain downgrade support.
Haven’t added a comment yet since I’m not sure what the next version number will be 😅 (would it be 0.1.3?)

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/events/mod.rs
Comment threadlightning/src/events/mod.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.02 to pr3655.03 (diff):
Addressed @valentinewallace comments

Changes:

  1. Expanded Documentation
  2. Properly write the legacy fields to maintain downgrade support.

@valentinewallace

Copy link
Copy Markdown
Contributor

Looks good, feel free to squash! Thanks!

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.03 to pr3655.04 (diff):
Addressed @valentinewallace comments

Changes:

  1. Squash commits.

@codecov

codecovBot commented Mar 15, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 96.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.37%. Comparing base (5bc9ffa) to head (591c5c8).
Report is 180 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/events/mod.rs90.47%0 Missing and 2 partials ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #3655 +/- ##
==========================================
+ Coverage 89.21% 91.37% +2.16% 
==========================================
Files 155 156 +1 Lines 118966 141344 +22378 Branches 118966 141344 +22378 ==========================================
+ Hits 106133 129159 +23026 + Misses 10253 9799 -454 + Partials 2580 2386 -194 

☔ 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.

@shaavanshaavan left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Looks good, feel free to squash! Thanks!

Awesome — thanks a lot for the review, Val! 🚀

Comment threadlightning/src/events/mod.rs
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.04 to pr3655.05 (diff):
Addressed @valentinewallace comments

Changes:

  • Added comment documenting when, and why via_channel_id_legacy, and via_user_channel_id_legacy were deprecated.

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.05 to pr3655.06 (diff):
Addressed @valentinewallace comments

Changes:

  1. Updated documentation to correctly reflect that the vector will be incomplete for HTLC created using versions prior to LDK 0.1.0 or prior.

@valentinewallace
valentinewallace self-requested a review April 4, 2025 17:11
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @valentinewallace! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be good to land after these last tweaks!

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.06 to pr3655.07 (diff):
Addressed @valentinewallace comments

Changes:

  1. Fixed comments to correctly represent for which version and cases the lists would be incomplete.

valentinewallace
valentinewallace previously approved these changes Apr 8, 2025
@jkczyz
jkczyz requested a review from joostjagerApril 10, 2025 17:29

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code looks good, test coverage could probably be improved a bit.

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/functional_tests.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.08 to pr3655.09 (diff):
Addressed @joostjager comments

Changes:

  1. Expanded test, to ensure that all the via_channel_id & via_user_channel_ids are present in PaymentClaimable in multi part payment case.

@valentinewallace

Copy link
Copy Markdown
Contributor

LGTM

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @joostjager! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 2nd Reminder

Hey @joostjager! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Comment threadlightning/src/events/mod.rs Outdated
via_channel_ids: Vec<ChannelId>,
/// The `user_channel_id`(s) corresponding to the channels over which the payment was received.
/// This will be an incomplete vector for MPP payment events created/serialized using LDK version 0.1.0 and prior.
via_user_channel_ids: Vec<u128>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's a bit late now, but would it be better to keep id and user_id together in a tuple? Not sure if there are interpretation issues when both vecs have different lengths?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thanks for bringing this up, Joost! I did consider that, but I wasn’t sure if it would offer a clear advantage. As far as I understand, both lists will always be of equal length since both fields were introduced together in the same version, so mismatched lengths shouldn’t arise.

Also, keeping them separate makes their distinction more explicit and follows the structure we’ve used in earlier LDK versions, where via_channel_id and via_user_channel_id were also separate fields.

That said, I’m open to discussing it further if you think a tuple-based design would still be better here! Would love to hear your thoughts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suppose the tuple leaves less room for questions like these. And maybe the original fields should have been a tuple/struct too. In general, I think it is good to keep the data types as strict as they can be.

But here it doesn't seem to be particular critical. Happy to go along with the other reviewer's view on it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we'd have to have a Vec<(ChannelId, Option<u128>)> since per ClaimablePayment::get_user_channel_ids docs user channel IDs are only always set after 117... Don't have a strong preference here although the option makes the field's API a bit less nice IMO.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The option would be consistent with HTLCPreviousHopData for example

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, isn't it the case that pre-117 data just translates to an empty vec<(..,..)> without requiring the option?

Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
// we test all generated events round-trip:
for event in &collected_events {
let ser = event.encode();
if let Some(deser) = events::Event::read(&mut &ser[..]).expect("event should deserialize") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the None case ok to ignore?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

AFAIU, yes. Some event enums are designed to map to a None value (for example, 0u8, 4u8, and 17u8), so getting an Ok(None) seems to indicate that the event was read successfully and no further checks are needed in this case.

That said, I'd love to hear @valentinewallace's thoughts to confirm if I’m understanding this correctly!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, some events are never written so I believe @shaavan is correct here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So could also continue when ser is None then, and unwrap the read? Not that it is all that important ofc.

@valentinewallacevalentinewallaceApr 28, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ser just returns Ok(()) on success, not an option.. But if you want to rearrange this code somehow, no strong preference here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like ser is just Vec<u8>. So if that is empty, we expect None from read? Maybe that can be used to make it slightly stricter and detect the case where read is unexpectedly returning None.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh right, sorry. It looks like for events where we don't write the actual event, we will still write the type for the event: https://github.com/lightningdevkit/rust-lightning/blob/main/lightning/src/events/mod.rs#L1809 so I don't think we can check if it's empty but we could check if only a u8 was written.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps a too much internal detail then. Can leave this as is as far as I am concerned.

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.09 to pr3655.10 (diff):
Addressed @joostjager comments

Changes:

  1. Add check that the via_channel_ids, and via_user_channel_ids only contains one element for the appropriate cases.

Comment threadlightning/src/ln/channelmanager.rs Outdated

/// Returns the inbound `user_channel_id`s for all HTLCs associated with the payment.
///
/// Note: This list will be incomplete for HTLCs created using LDK version 0.0.117 or prior.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment does seem to suggest that vecs can be different lengths?

@joostjagerjoostjagerApr 28, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@shaavan, @valentinewallace and I chatted about it. Seems something to say for a stronger type, especially because the vecs both map from PrevHopData already. But it's a bit late now also, and not too critical. So leaving up to you to decide.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thanks so much, Joost and Val, for the pointers!
I went ahead and updated the PaymentClaimable field to a via_channel_id_pairs, containing a Vec<(ChannelId, Option<u128>)>, in pr3655.11.

Let me know if it looks good — thanks again!

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.10 to pr3655.11 (diff):
Addressed @valentinewallace, @joostjager comments

Changes:

  1. Update PaymentClaimable field to be an ordered via_channel_id_pairs pair.

@joostjager

Copy link
Copy Markdown
Contributor

@shaavan just a side comment: I really like how you offer diffs to reviewers using pr3655.x branches!

joostjager
joostjager previously approved these changes Apr 29, 2025

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seeing how this worked out, I think vec(tuple) is the right move. Hopefully you feel the same!

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
Comment threadlightning/src/ln/blinded_payment_tests.rs Outdated

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Accidentally approved. Wanted to await your replies first.

These two utilities will be used in following commit to get all the
inbound channel_ids, and user_channel_ids associated with all the
parts of a payment.
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.11 to pr3655.12 (diff):
Addressed @joostjager comments

Changes:

  1. Rename via_channel_id_pairs & get_channel_id_pairs -> inbound_channel_ids
  2. Cleaned up testing.

@shaavan

Copy link
Copy Markdown
MemberAuthor

@shaavan just a side comment: I really like how you offer diffs to reviewers using pr3655.x branches!

Thanks so much, @joostjager — really appreciate you noticing that! :)

Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
Comment threadlightning/src/ln/functional_test_utils.rs Outdated

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM besides a few nits.

Comment threadlightning/src/ln/functional_tests.rs Outdated
shaavan added 2 commits May 1, 2025 20:37
Previously, `channel_id` in `PaymentClaimable` only listed a single
inbound channel, which was misleading for MPP payments arriving via
multiple channels.
To better represent MPP scenarios, this update introduces:
- `via_channel_ids`: A list of all inbound channels used in the payment.
- `via_user_channel_ids`: The corresponding user-defined channel IDs for
each inbound channel.
This change ensures a more accurate representation of multi-path payments
while maintaining backward compatibility.
- Expand testing to ensure proper serialise-deserialise round-trip for
all events.
- Expand a multi-Part payment test to ensure that all the channel ids &
user channel ids are present in the PaymentClaimable event
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.12 to pr3655.13 (diff):
Addressed @joostjager comments

Changes:

  1. Cleaned up tests

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @shaavan! I like the tuple change 👌

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for this contribution. Great work and excellent communication.

@valentinewallace
valentinewallace merged commit 29a6383 into lightningdevkit:mainMay 1, 2025
Sign up for freeto 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.

PaymentClaimable lists inbound channel id

5 participants

@shaavan@ldk-reviews-bot@benthecarman@valentinewallace@joostjager
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Expand PaymentClaimable to include all inbound channel IDs for a payment - #3655

Merged
valentinewallace merged 3 commits into
lightningdevkit:mainfrom
shaavan:i2274
May 1, 2025
Merged

Expand PaymentClaimable to include all inbound channel IDs for a payment #3655
valentinewallace merged 3 commits into
lightningdevkit:mainfrom
shaavan:i2274

Conversation

@shaavan

Copy link
Copy Markdown
Member

Resolves#2274

This PR expands PaymentClaimable to include all inbound channel_ids and user_channel_ids associated with a payment.
This update ensures a clearer representation of the channels used, especially for MPP payments.

@ldk-reviews-bot

ldk-reviews-bot commented Mar 8, 2025

Copy link
Copy Markdown

👋 Thanks for assigning @joostjager 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.

@shaavan

Copy link
Copy Markdown
MemberAuthor

@benthecarman

Would also be nice if the same information is available on the PaymentClaimed event too

In the current version, I haven’t included channel_ids and user_channel_ids for PaymentClaimed, as they can be easily derived from the event itself:

let channel_ids = payment_claimed_event.htlcs.iter().map(|htlc| htlc.channel_id).collect();

That said, let me know if you’d still prefer to include channel_ids in PaymentClaimed, and I'd be happy to make that change. Thanks!

@benthecarman

Copy link
Copy Markdown
Contributor

Thanks, @shaavan , that is good enough

Comment threadlightning/src/ln/functional_test_utils.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
@ldk-reviews-bot

Copy link
Copy Markdown

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

@valentinewallace

Copy link
Copy Markdown
Contributor

nit: limit commit subject line in 2nd commit to ~50 characters

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.01 to pr3655.02 (diff):
Addressed @valentinewallace comments

  1. Updated the fields to be Vec<ChannelId>, and Vec<u128>
  2. Updated test utilities to check for all the channels id in events list, for improved test completeness.

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
Comment on lines +1553 to +1557
// legacy field
// (3, via_channel_id, option),
(4, amount_msat, required),
(5, via_user_channel_id, option),
// legacy field
// (5, via_user_channel_id, option),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should still write these fields for the sake of users who downgrade (can always write the first item in the vec). Also would be nice to comment in what version the fields became legacy.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Done! pr3655.03
I’ve updated the writing so that we maintain downgrade support.
Haven’t added a comment yet since I’m not sure what the next version number will be 😅 (would it be 0.1.3?)

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/events/mod.rs
Comment threadlightning/src/events/mod.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.02 to pr3655.03 (diff):
Addressed @valentinewallace comments

Changes:

  1. Expanded Documentation
  2. Properly write the legacy fields to maintain downgrade support.

@valentinewallace

Copy link
Copy Markdown
Contributor

Looks good, feel free to squash! Thanks!

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.03 to pr3655.04 (diff):
Addressed @valentinewallace comments

Changes:

  1. Squash commits.

@codecov

codecovBot commented Mar 15, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 96.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.37%. Comparing base (5bc9ffa) to head (591c5c8).
Report is 180 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/events/mod.rs90.47%0 Missing and 2 partials ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #3655 +/- ##
==========================================
+ Coverage 89.21% 91.37% +2.16% 
==========================================
Files 155 156 +1 Lines 118966 141344 +22378 Branches 118966 141344 +22378 ==========================================
+ Hits 106133 129159 +23026 + Misses 10253 9799 -454 + Partials 2580 2386 -194 

☔ 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.

@shaavanshaavan left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Looks good, feel free to squash! Thanks!

Awesome — thanks a lot for the review, Val! 🚀

Comment threadlightning/src/events/mod.rs
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.04 to pr3655.05 (diff):
Addressed @valentinewallace comments

Changes:

  • Added comment documenting when, and why via_channel_id_legacy, and via_user_channel_id_legacy were deprecated.

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.05 to pr3655.06 (diff):
Addressed @valentinewallace comments

Changes:

  1. Updated documentation to correctly reflect that the vector will be incomplete for HTLC created using versions prior to LDK 0.1.0 or prior.

@valentinewallace
valentinewallace self-requested a review April 4, 2025 17:11
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @valentinewallace! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be good to land after these last tweaks!

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.06 to pr3655.07 (diff):
Addressed @valentinewallace comments

Changes:

  1. Fixed comments to correctly represent for which version and cases the lists would be incomplete.

valentinewallace
valentinewallace previously approved these changes Apr 8, 2025
@jkczyz
jkczyz requested a review from joostjagerApril 10, 2025 17:29

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code looks good, test coverage could probably be improved a bit.

Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/functional_tests.rs Outdated
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.08 to pr3655.09 (diff):
Addressed @joostjager comments

Changes:

  1. Expanded test, to ensure that all the via_channel_id & via_user_channel_ids are present in PaymentClaimable in multi part payment case.

@valentinewallace

Copy link
Copy Markdown
Contributor

LGTM

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @joostjager! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 2nd Reminder

Hey @joostjager! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Comment threadlightning/src/events/mod.rs Outdated
via_channel_ids: Vec<ChannelId>,
/// The `user_channel_id`(s) corresponding to the channels over which the payment was received.
/// This will be an incomplete vector for MPP payment events created/serialized using LDK version 0.1.0 and prior.
via_user_channel_ids: Vec<u128>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's a bit late now, but would it be better to keep id and user_id together in a tuple? Not sure if there are interpretation issues when both vecs have different lengths?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thanks for bringing this up, Joost! I did consider that, but I wasn’t sure if it would offer a clear advantage. As far as I understand, both lists will always be of equal length since both fields were introduced together in the same version, so mismatched lengths shouldn’t arise.

Also, keeping them separate makes their distinction more explicit and follows the structure we’ve used in earlier LDK versions, where via_channel_id and via_user_channel_id were also separate fields.

That said, I’m open to discussing it further if you think a tuple-based design would still be better here! Would love to hear your thoughts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suppose the tuple leaves less room for questions like these. And maybe the original fields should have been a tuple/struct too. In general, I think it is good to keep the data types as strict as they can be.

But here it doesn't seem to be particular critical. Happy to go along with the other reviewer's view on it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we'd have to have a Vec<(ChannelId, Option<u128>)> since per ClaimablePayment::get_user_channel_ids docs user channel IDs are only always set after 117... Don't have a strong preference here although the option makes the field's API a bit less nice IMO.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The option would be consistent with HTLCPreviousHopData for example

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, isn't it the case that pre-117 data just translates to an empty vec<(..,..)> without requiring the option?

Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
// we test all generated events round-trip:
for event in &collected_events {
let ser = event.encode();
if let Some(deser) = events::Event::read(&mut &ser[..]).expect("event should deserialize") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the None case ok to ignore?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

AFAIU, yes. Some event enums are designed to map to a None value (for example, 0u8, 4u8, and 17u8), so getting an Ok(None) seems to indicate that the event was read successfully and no further checks are needed in this case.

That said, I'd love to hear @valentinewallace's thoughts to confirm if I’m understanding this correctly!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, some events are never written so I believe @shaavan is correct here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So could also continue when ser is None then, and unwrap the read? Not that it is all that important ofc.

@valentinewallacevalentinewallaceApr 28, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ser just returns Ok(()) on success, not an option.. But if you want to rearrange this code somehow, no strong preference here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like ser is just Vec<u8>. So if that is empty, we expect None from read? Maybe that can be used to make it slightly stricter and detect the case where read is unexpectedly returning None.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh right, sorry. It looks like for events where we don't write the actual event, we will still write the type for the event: https://github.com/lightningdevkit/rust-lightning/blob/main/lightning/src/events/mod.rs#L1809 so I don't think we can check if it's empty but we could check if only a u8 was written.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps a too much internal detail then. Can leave this as is as far as I am concerned.

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.09 to pr3655.10 (diff):
Addressed @joostjager comments

Changes:

  1. Add check that the via_channel_ids, and via_user_channel_ids only contains one element for the appropriate cases.

Comment threadlightning/src/ln/channelmanager.rs Outdated

/// Returns the inbound `user_channel_id`s for all HTLCs associated with the payment.
///
/// Note: This list will be incomplete for HTLCs created using LDK version 0.0.117 or prior.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment does seem to suggest that vecs can be different lengths?

@joostjagerjoostjagerApr 28, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@shaavan, @valentinewallace and I chatted about it. Seems something to say for a stronger type, especially because the vecs both map from PrevHopData already. But it's a bit late now also, and not too critical. So leaving up to you to decide.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thanks so much, Joost and Val, for the pointers!
I went ahead and updated the PaymentClaimable field to a via_channel_id_pairs, containing a Vec<(ChannelId, Option<u128>)>, in pr3655.11.

Let me know if it looks good — thanks again!

@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.10 to pr3655.11 (diff):
Addressed @valentinewallace, @joostjager comments

Changes:

  1. Update PaymentClaimable field to be an ordered via_channel_id_pairs pair.

@joostjager

Copy link
Copy Markdown
Contributor

@shaavan just a side comment: I really like how you offer diffs to reviewers using pr3655.x branches!

joostjager
joostjager previously approved these changes Apr 29, 2025

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seeing how this worked out, I think vec(tuple) is the right move. Hopefully you feel the same!

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
Comment threadlightning/src/ln/blinded_payment_tests.rs Outdated

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Accidentally approved. Wanted to await your replies first.

These two utilities will be used in following commit to get all the
inbound channel_ids, and user_channel_ids associated with all the
parts of a payment.
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.11 to pr3655.12 (diff):
Addressed @joostjager comments

Changes:

  1. Rename via_channel_id_pairs & get_channel_id_pairs -> inbound_channel_ids
  2. Cleaned up testing.

@shaavan

Copy link
Copy Markdown
MemberAuthor

@shaavan just a side comment: I really like how you offer diffs to reviewers using pr3655.x branches!

Thanks so much, @joostjager — really appreciate you noticing that! :)

Comment threadlightning/src/ln/chanmon_update_fail_tests.rs Outdated
Comment threadlightning/src/ln/functional_test_utils.rs Outdated

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM besides a few nits.

Comment threadlightning/src/ln/functional_tests.rs Outdated
shaavan added 2 commits May 1, 2025 20:37
Previously, `channel_id` in `PaymentClaimable` only listed a single
inbound channel, which was misleading for MPP payments arriving via
multiple channels.
To better represent MPP scenarios, this update introduces:
- `via_channel_ids`: A list of all inbound channels used in the payment.
- `via_user_channel_ids`: The corresponding user-defined channel IDs for
each inbound channel.
This change ensures a more accurate representation of multi-path payments
while maintaining backward compatibility.
- Expand testing to ensure proper serialise-deserialise round-trip for
all events.
- Expand a multi-Part payment test to ensure that all the channel ids &
user channel ids are present in the PaymentClaimable event
@shaavan

Copy link
Copy Markdown
MemberAuthor

Updated frompr3655.12 to pr3655.13 (diff):
Addressed @joostjager comments

Changes:

  1. Cleaned up tests

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @shaavan! I like the tuple change 👌

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for this contribution. Great work and excellent communication.

@valentinewallace
valentinewallace merged commit 29a6383 into lightningdevkit:mainMay 1, 2025
Sign up for freeto 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.

PaymentClaimable lists inbound channel id

5 participants

@shaavan@ldk-reviews-bot@benthecarman@valentinewallace@joostjager