Skip to content

Conversation

@carlaKC
Copy link
Contributor

@carlaKC carlaKC commented Nov 17, 2025

This PR replaces #3983, adding validation of trampoline onions (as compared to the outer onion). It makes some quite significant changes to the tests in the original PR to consolidate blinded and unblinded tests for success/failure scenarios into a single helper (apologies to reviewers who've already looked at the tests, but I think this DRYs it up quite nicely).

While we're here, it also moves rustfmt::skip to a per-function level on blinded_payment_tests.rs and formats the existing test helper that we're modifying in a pre-factor so that the new code can be formatted.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Nov 17, 2025

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

}),
onion_utils::Hop::TrampolineForward { next_trampoline_hop_data, next_trampoline_hop_hmac, new_trampoline_packet_bytes, trampoline_shared_secret, .. } => {
onion_utils::Hop::TrampolineForward { ref outer_hop_data, next_trampoline_hop_data, next_trampoline_hop_hmac, new_trampoline_packet_bytes, trampoline_shared_secret, .. } => {
// TODO: return reason as forward issue, not as receiving issue when forwarding is ready.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not quite clear on what this todo means, still catching up on some context - @a-mpch could you help me out?

@carlaKC carlaKC changed the title 3983 trampoline constraints Enforce Trampoline Constraints (replacement) Nov 17, 2025
@carlaKC
Copy link
Contributor Author

carlaKC commented Nov 17, 2025

Assigning reviewers who looked at the original PR - please free yourself if not appropriate!

@codecov
Copy link

codecov bot commented Nov 17, 2025

Codecov Report

❌ Patch coverage is 92.33129% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.33%. Comparing base (6d9c676) to head (6b5cd30).

Files with missing lines Patch % Lines
lightning/src/ln/onion_payment.rs 70.00% 15 Missing ⚠️
lightning/src/ln/onion_utils.rs 0.00% 6 Missing ⚠️
lightning/src/ln/blinded_payment_tests.rs 98.47% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #4226    +/-   ##
========================================
  Coverage   89.32%   89.33%            
========================================
  Files         180      180            
  Lines      138641   138877   +236     
  Branches   138641   138877   +236     
========================================
+ Hits       123844   124068   +224     
- Misses      12174    12185    +11     
- Partials     2623     2624     +1     
Flag Coverage Δ
fuzzing 35.93% <0.00%> (-0.04%) ⬇️
tests 88.70% <92.33%> (+0.01%) ⬆️

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

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

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

@carlaKC
Copy link
Contributor Author

carlaKC commented Nov 17, 2025

One thing to note about the tests here: we've currently only got coverage for blinded receives checking the constraints (this is what the original PR had). We could also add coverage for blinded forwards in the failure case (can't do for success because we just fail the forwards rn), which would make codecov a bit happier.

I think this is worth doing, but it would mean adding a bit more code to the mega test helper - interested on hearing thoughts on how readable others find it before adding another layer to an already quite dense test! Can also easily be a small follow. up.

@valentinewallace
Copy link
Contributor

valentinewallace commented Nov 18, 2025

Needs rebase :(

I did find the new testing not ideal from a readability PoV at first glance, going to take a closer look in a bit but let me know if you see any obvious ways to improve things. It may be that the nature of what we're testing makes it hard to improve things though.

}

// Creates a replacement onion that is used to produce scenarios that we don't support, specifically
// unblinded receives and invalid payloads.
Copy link
Contributor

Choose a reason for hiding this comment

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

Here and a few other places, I thought we did support unblinded trampoline receives but didn't support unblinded trampoline sends. At least I can't see where we reject them + it seems like we understand how to decode the payload 👀 may be missing something though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Badly worded comment - we don't support creating payloads (sends) with unblinded receives, I'll fix!

onion_utils::Hop::TrampolineForward { next_trampoline_hop_data, next_trampoline_hop_hmac, new_trampoline_packet_bytes, trampoline_shared_secret, .. } => {
onion_utils::Hop::TrampolineForward { ref outer_hop_data, next_trampoline_hop_data, next_trampoline_hop_hmac, new_trampoline_packet_bytes, trampoline_shared_secret, .. } => {
// TODO: return reason as forward issue, not as receiving issue when forwarding is ready.
check_trampoline_onion_constraints(outer_hop_data, next_trampoline_hop_data.outgoing_cltv_value, next_trampoline_hop_data.amt_to_forward)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit confused why we're calling this method here. It only returns IncorrectFinal* errors, which seems like it should only be used for receives and not forwards. I might be missing something from the trampoline spec here? Or do we need a new similar method for forwards that will return some of the new errors, like TrampolineFeeOrExpiryInsufficient, if the cltv/forward amount are mismatching between the inner and outer onion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the todo I'm not so sure about. It seems to me like the approach in the original PR is to add this validation here (even though it's not in the spec) and then remove it when we add more forwarding logic. cc @a-mpch?

I think that we can remove check_trampoline_onion_constraints on the forwarding branches and get to them in subsequent PRs, but just want to make sure I'm not missing context from the original change.

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to check the trampoline constraints in forwarding branches when implementing the forwarding. We can safely remove it and re-added in follow up PRs.

As at this point we don't have implemented this error: https://github.com/lightning/bolts/pull/836/files#diff-ad65f0beaac5cef88f5fd7a8b9ca36cbc5a790f4815b4b50b9ea794a55aaf012R1441

That would be returned here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Going to go ahead with removing the forwarding check and will re-add when we get to more forwarding logic.

@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @tankyleo! 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.

carlaKC and others added 4 commits November 20, 2025 08:47
To allow formatting on new code, move to per-function skips.
Remove skip without fixing up any of the ugly formatting, so that the
diff is a bit more readable in review.
This commit adds three new local htlc failure error reasons:
`TemporaryTrampolineFailure`, `TrampolineFeeOrExpiryInsufficient`,
and `UnknownNextTrampoline` for trampoline payment forwarding failures.
@carlaKC carlaKC force-pushed the 3983-trampoline-constraints branch from b43670e to 531cca6 Compare November 20, 2025 13:50
@carlaKC
Copy link
Contributor Author

carlaKC commented Nov 20, 2025

Rebased + addressed review in fixups, removing validation of trampoline forwards because we'll need a different check/error there anyway.

Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

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

LGTM, feel free to squash!

Tests are added to cover validation of blinded and unblinded trampoline
payloads against their outer onion. These are consolidated with our
existing coverage for successful receives.

Co-authored-by: Arik Sosman <[email protected]>
Co-authored-by: Maurice Poirrier <[email protected]>
@carlaKC carlaKC force-pushed the 3983-trampoline-constraints branch from 136641d to 6b5cd30 Compare November 20, 2025 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants