Skip to content

Use HTLC CLTV instead of onion CLTV values for payment claim timer#4402

Open
TheBlueMatt wants to merge 6 commits intolightningdevkit:mainfrom
TheBlueMatt:2026-02-trampoline-cltv-consistency
Open

Use HTLC CLTV instead of onion CLTV values for payment claim timer#4402
TheBlueMatt wants to merge 6 commits intolightningdevkit:mainfrom
TheBlueMatt:2026-02-trampoline-cltv-consistency

Conversation

@TheBlueMatt
Copy link
Collaborator

When we receive an HTLC as a part of a claim, we validate that the
CLTV on the HTLC is >= the CLTV that the sender requested we
receive, but then we use the CLTV value that the sender requested
we receive as the deadline to claim the HTLC anyway.

This isn't generally all that interesting (they're always the same
unless the previous-hop node gave us "free CLTV"), but for
trampoline payments where we're both a trampoline hop and the
blinded intro point and the recipient, it means we end up allowing
ourselves less claim time than we actually have.

Instead, here, we just use the actual HTLC CLTV deadline.

Somewhat annoyingly built on #4373 because I needed to use some of the test infra that was built there and also now its hard to rebase :(

cc @carlaKC

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Feb 9, 2026

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

@TheBlueMatt TheBlueMatt requested a review from carlaKC February 9, 2026 02:04
Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

Rebased trampoline work on this and all's good except one assert that's in conflict with the instructions in TrampolineHop's docs. test_update_add_htlc_bolt2_sender_cltv_expiry_too_high also unhappy.

Removing that, everything I have passes with these changes and it saves me a few commits fixing up onion building 🧹

} else {
cur_cltv
};
let cltv = hop.cltv_expiry_delta().saturating_add(cur_cltv);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can move this inside the if idx == 0 branch because we're only using it for final hops.
Perhaps also rename to outgoing_cltv_value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Went with declared_incoming_cltv since that felt much closer to what its actually being used for.

@ldk-reviews-bot
Copy link

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

@TheBlueMatt
Copy link
Collaborator Author

Fixed the broken assertion and one broken test and rebased, thanks!

carlaKC
carlaKC previously approved these changes Feb 10, 2026
Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

fixups lgtm!

When we receive an HTLC as a part of a claim, we validate that the
CLTV on the HTLC is >= the CLTV that the sender requested we
receive, but then we use the CLTV value that the sender requested
we receive as the deadline to claim the HTLC anyway.

This isn't generally all that interesting (they're always the same
unless the previous-hop node gave us "free CLTV"), but for
trampoline payments where we're both a trampoline hop and the
blinded intro point and the recipient, it means we end up allowing
ourselves less claim time than we actually have.

Instead, here, we just use the actual HTLC CLTV deadline.
The docs for `RouteHop::cltv_expiry_delta` claim that it includes
any trampoline hops, but the way we actually implemented onion
building it did not.

Because the docs described a simpler and more backwards-compatible
API, we update the onion-building logic to match rather than
updating the docs.
Now that we've cleaned up trampoline CLTV building and added
`Path::total_cltv_expiry_delta`, we can use both to do some basic
validation of CLTV values on blinded tails in
`Route::debug_assert_route_meets_params`
Now that we are consistently using the
`RouteHop::cltv_expiry_delta` as the last hop's starting CLTV
rather than summing trampoline hops, `starting_htlc_offset` is a
bit confusing - its actually always the current block height. Thus,
here we rename it.
@TheBlueMatt
Copy link
Collaborator Author

Rebased, fixed rustfmt, and squashed.

@ldk-reviews-bot
Copy link

✅ Added second reviewer: @joostjager

@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

❌ Patch coverage is 80.26316% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.88%. Comparing base (df57978) to head (e39437d).
⚠️ Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/routing/router.rs 60.60% 13 Missing ⚠️
lightning/src/ln/onion_utils.rs 93.10% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4402      +/-   ##
==========================================
- Coverage   85.89%   85.88%   -0.02%     
==========================================
  Files         159      159              
  Lines      104402   104448      +46     
  Branches   104402   104448      +46     
==========================================
+ Hits        89681    89706      +25     
- Misses      12216    12235      +19     
- Partials     2505     2507       +2     
Flag Coverage Δ
tests 85.88% <80.26%> (-0.02%) ⬇️

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

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

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

Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

Thanks for cleaning this up, saves me some commits down the line!

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