') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Use HTLC CLTV instead of onion CLTV values for payment claim timer by TheBlueMatt · Pull Request #4402 · lightningdevkit/rust-lightning · GitHub
Skip to content

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

Merged
TheBlueMatt merged 6 commits into
lightningdevkit:mainfrom
TheBlueMatt:2026-02-trampoline-cltv-consistency
Feb 26, 2026
Merged

Use HTLC CLTV instead of onion CLTV values for payment claim timer#4402
TheBlueMatt merged 6 commits into
lightningdevkit:mainfrom
TheBlueMatt:2026-02-trampoline-cltv-consistency

Conversation

@TheBlueMatt

Copy link
Copy Markdown
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

ldk-reviews-bot commented Feb 9, 2026

Copy link
Copy Markdown

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

@carlaKCcarlaKC 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.

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 🧹

Comment threadlightning/src/ln/onion_utils.rs Outdated
} else {
cur_cltv
};
let cltv = hop.cltv_expiry_delta().saturating_add(cur_cltv);

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.

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
Copy Markdown
CollaboratorAuthor

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.

Comment threadlightning/src/ln/onion_utils.rs
Comment threadlightning/src/routing/router.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.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

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

carlaKC
carlaKC previously approved these changes Feb 10, 2026

@carlaKCcarlaKC 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.

fixups lgtm!

@carlaKCcarlaKC mentioned this pull request Feb 12, 2026
5 tasks
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
Copy Markdown
CollaboratorAuthor

Rebased, fixed rustfmt, and squashed.

@ldk-reviews-bot

Copy link
Copy Markdown

✅ Added second reviewer: @joostjager

@codecov

codecovBot commented Feb 24, 2026

Copy link
Copy Markdown

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 37 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/routing/router.rs60.60%13 Missing ⚠️
lightning/src/ln/onion_utils.rs93.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 
FlagCoverage Δ
tests85.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.

@carlaKCcarlaKC 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 for cleaning this up, saves me some commits down the line!

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

Nothing blocking

Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs
Comment threadlightning/src/routing/router.rs
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Will address followups in a followup.

@TheBlueMatt
TheBlueMatt merged commit a6e6676 into lightningdevkit:mainFeb 26, 2026
22 of 41 checks passed
@TheBlueMattTheBlueMatt mentioned this pull request Feb 26, 2026
TheBlueMatt added a commit that referenced this pull request Mar 2, 2026
@joostjagerjoostjager mentioned this pull request Mar 23, 2026
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.

4 participants

@TheBlueMatt@ldk-reviews-bot@joostjager@carlaKC