Skip to content

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.

When `OutboundPayments` calls the provided `Router` to fetch a
`Route` it passes a `RouteParameters` with a specific max-fee. Here
we validate that the `Route` returned sticks to the limits
provided, and also that it meets the MPP rules of not having any
single MPP part which can be removed while still meeting the
desired payment amount.
In some uses of LDK we need the ability to send HTLCs for only a
portion of some larger MPP payment. This allows payers to make
single payments which spend funds from multiple wallets, which may
be important for ecash wallets holding funds in multiple mints or
graduated wallets which hold funds across a trusted wallet and a
self-custodial wallet.

In order to allow for this, we need to separate the concept of the
payment amount from the onion MPP amount. Here we start this
process by adding a `total_mpp_amount_msat` field to
`RecipientOnionFields` (which is the appropriate place for a field
describing something in the recipient onion).

We currently always assert that it is equal to the existing fields,
but will relax this in the coming commit(s).

We also start including a payment preimage on probe attempts,
which appears to have been the intent of the code, but which did
not work correctly.

The bulk of the test updates were done by Claude.
In some uses of LDK we need the ability to send HTLCs for only a
portion of some larger MPP payment. This allows payers to make
single payments which spend funds from multiple wallets, which may
be important for ecash wallets holding funds in multiple mints or
graduated wallets which hold funds across a trusted wallet and a
self-custodial wallet.

In the previous commit we added a new field to
`RecipientOnionFields` to describe the total value of an MPP
payment. Here we start using this field when building onions,
dropping existing arguments to onion-building methods.
In some uses of LDK we need the ability to send HTLCs for only a
portion of some larger MPP payment. This allows payers to make
single payments which spend funds from multiple wallets, which may
be important for ecash wallets holding funds in multiple mints or
graduated wallets which hold funds across a trusted wallet and a
self-custodial wallet.

In the previous commits we moved the total-MPP-value we set in
onions from being manually passed through onion-building to passing
it via `RecipientOnionFields`. This introduced a subtle bug, though
 - payments which are retried will get a fresh
`RecipientOnionFields` built from the data in
`PendingOutboundPayment::Retryable`, losing any custom
total-MPP-value settings and causing retries to fail.

Here we fix this by storing the total-MPP-value directly in
`PendingOutboundPayment::Retryable`.
In some uses of LDK we need the ability to send HTLCs for only a
portion of some larger MPP payment. This allows payers to make
single payments which spend funds from multiple wallets, which may
be important for ecash wallets holding funds in multiple mints or
graduated wallets which hold funds across a trusted wallet and a
self-custodial wallet.

In the previous few commits we added support for making these
kinds of payments when using the payment methods which explicitly
accepted a `RecipientOnionFields`. Here we also add support for
such payments made via the `pay_for_bolt11_invoice` method,
utilizing the new `OptionalBolt11PaymentParams` to hide the
parameter from most calls.

Test mostly by Claude
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 TheBlueMatt force-pushed the 2026-02-trampoline-cltv-consistency branch from 5d10f6b to 610dc33 Compare February 10, 2026 13:08
@TheBlueMatt
Copy link
Collaborator Author

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

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