Skip to content

Conversation

a-mpch
Copy link
Contributor

@a-mpch a-mpch commented Aug 25, 2025

This PR is on top of #3983 is part of the split-up of #3976

Main focus of this PR is to add a TrampolineForward variant to HTLCSource enum, then we extract most logic to be re-used and then implement the places where we require it.

After this PR only left is the implementation of finding path and forward the HTLCs and adding tests for all reamaining "to do" statements

@ldk-reviews-bot
Copy link

👋 Hi! I see this is a draft PR.
I'll wait to assign reviewers until you mark it as ready for review.
Just convert it out of draft status when you're ready for review!

Copy link

codecov bot commented Aug 25, 2025

Codecov Report

❌ Patch coverage is 85.77348% with 103 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.72%. Comparing base (381416a) to head (9268af2).
⚠️ Report is 110 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/channelmanager.rs 81.33% 48 Missing and 8 partials ⚠️
lightning/src/ln/onion_payment.rs 59.67% 25 Missing ⚠️
lightning/src/ln/blinded_payment_tests.rs 95.49% 12 Missing and 4 partials ⚠️
lightning/src/ln/onion_utils.rs 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4027      +/-   ##
==========================================
- Coverage   88.94%   88.72%   -0.22%     
==========================================
  Files         174      175       +1     
  Lines      124575   128464    +3889     
  Branches   124575   128464    +3889     
==========================================
+ Hits       110797   113979    +3182     
- Misses      11278    11919     +641     
- Partials     2500     2566      +66     
Flag Coverage Δ
fuzzing 21.69% <24.10%> (-0.50%) ⬇️
tests 88.55% <85.77%> (-0.21%) ⬇️

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.

valentinewallace and others added 15 commits August 26, 2025 12:41
This simplifies the code and makes it more straightforward to test unblinded
trampoline receives where we need to compute the trampoline session_priv when
manually creating the inner onion. (The trampoline onion needs to be manually
created because LDK does not natively support sending to unblinded trampolines,
just receiving.)
No need to construct unused blinded hop data or hardcode session privs/prng
seeds.
Previously, this test purported to test for a successful and a failing payment
to a single-hop blinded path containing one trampoline node. However, to induce
the failure the test was manually reconstructing the trampoline onion in a
complicated way that encoded the final onion payload as a receive, when for its
purposes it would be simplier for the recipient to just fail the payment
backwards.

In order to not regress in test coverage, the failure method the test was
previously using is re-added in the next commit as a dedicated test.

XXX this new test surfaced a bug that needs to be fixed
This re-adds test coverage for a case that was removed in the previous commit.
This commit adds three new local htlc failure error reasons:
`TemporaryTrampolineFailure`, `TrampolineFeeOrExpiryInsufficient`,
and `UnknownNextTrampoline` for trampoline payment forwarding failures.
We add a `check_trampoline_constraints` similar to
`check_blinded_path_constraints` that compares the Trampoline onion's amount
and CLTV values to the limitations imposed by the outer onion.

Also, we add and modify the following tests:
- Modified the unblinded receive to validate when receiving amount less than
expected.
- Modified test with wrong CLTV parameters that now fails with new enforcement
of CLTV limits.
- Add unblinded and blinded receive tests that forces trampoline onion's CLTV to
be greater than the outer onion packet.

Note that there are some TODOs to be fixed in following commits as we need
the full trampoline forwarding feature to effectively test all cases.

Co-authored-by: Arik Sosman <[email protected]>
Add new HTLCSource::TrampolineForward variant to track trampoline routing
information. Implement hash trait and serialization for the new variant.
In order to reduce code duplication for trampoline routing support,
this commit extracts the following heper methods.
 - `get_htlc_failure_from_blinded_failure_forward`: builds htlc
forward info with error details.
 - `fail_htlc_backwards_from_forward`: handles failure propagation.
Move `HTLCSource::PreviousHopData` claiming logic into
`claim_funds_from_previous_hop_internal` to prepare for trampoline
routing reuse.
Implement failure propagation for `HTLCSource::TrampolineForward`
by iterating through previous hop data and failing each HTLC with
`TemporaryTrampolineFailure`. Note that testing should be
implemented when trampoline forward is completed.
Implement payment claiming for `HTLCSource::TrampolineForward` by
iterating through previous hop data and claiming funds for each
HTLC. Note that testing should be implemented when trampoline
forwarding is completed.
Move recovery logic for `HTLCSource::PreviousHopData` into
`channel_monitor_recovery_internal` to prepare for trampoline
forward reuse.
Implement channel monitor recovery for trampoline forwards
iterating over all hop data and updating pending forwards.
The previously existing `HTLCDestination` do not map nicely to the
failure vent of a Trampoline forward, so we introduce a new variant to
fill the gap.

Co-authored-by: Arik Sosman <[email protected]>
@a-mpch a-mpch force-pushed the 2025-08-trampoline-forwarding-pt2 branch from 9268af2 to 04d9053 Compare August 29, 2025 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants