Skip to content

Conversation

@shaavan
Copy link
Member

@shaavan shaavan commented Dec 6, 2025

This PR adds end-to-end support for attaching custom TLVs in both Bolt11 and Bolt12 payment flows, giving callers a consistent way to embed arbitrary metadata into the onion packet. These TLVs can carry anything from richer descriptions to custom authentication cues and application-specific signaling.

What this PR does

1. Adds custom TLV support to pay_for_bolt11_invoice.

Bolt11 already allowed custom TLVs through send_payment, but the more ergonomic pay_for_bolt11_invoice path lacked this capability. This PR brings it to feature parity.

2. Extends Bolt12 payer-facing functions with custom_tlvs.

To support TLVs in Bolt12, the internal payment state now carries user-supplied metadata, and all payer-facing APIs expose a custom_tlvs field accordingly.

Why this matters

Lightning applications often need to pass contextual metadata alongside a payment. Until now, support for this was uneven:

  • Bolt11 only exposed custom TLVs through send_payment, not pay_for_bolt11_invoice.

• Bolt12 had no TLV support at all through send_payment_for_bolt12_invoice or related payer APIs.

This PR unifies the experience across both payment types, providing a uniform and predictable way to attach custom metadata to payments.

Custom TLVs let the payer attach arbitrary data to the onion packet,
enabling everything from richer metadata to custom authentication on
the payee's side.

Until now, this flexibility existed only through `send_payment`. The
simpler `pay_for_bolt11_invoice` API offered no way to pass custom
TLVs, limiting its usefulness in flows that rely on additional context.

This commit adds custom TLV support to `pay_for_bolt11_invoice`,
bringing it to feature parity.
Extends the payment flow test to assert that custom TLVs passed to
`pay_for_bolt11_invoice` are preserved and delivered correctly.
Bolt11 payments now allow attaching custom TLVs to the onion packet,
giving payers a way to pass metadata ranging from descriptions to
custom authentication. Bolt12 lacked an equivalent path, leaving its
outbound flow less extensible.

This commit adds a `custom_tlvs` field to the Bolt12-related
`PendingOutboundPayment` variants, bringing the internal Bolt12
payment state in line with the Bolt11 changes and preparing the
ground for user-facing API support.

A follow-up commit will expose a way for users to set these TLVs.
With internal support for custom TLVs now in place, this commit
extends that capability to all payer-facing entry points, from
`create_refund_builder` to the various `pay_for_offer` functions.

This brings the full Bolt12 payer API in line with the Bolt11 flow
and ensures that callers can attach custom metadata consistently
across all payment flows.
Adds an end-to-end test validating that custom TLVs propagate
correctly through the Bolt12 payer flow.
@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Dec 6, 2025

I've assigned @joostjager 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.

@shaavan
Copy link
Member Author

shaavan commented Dec 6, 2025

cc @jkczyz

@codecov
Copy link

codecov bot commented Dec 6, 2025

Codecov Report

❌ Patch coverage is 91.07143% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.32%. Comparing base (de384ff) to head (ef6edec).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/async_payments_tests.rs 75.38% 16 Missing ⚠️
lightning/src/ln/offers_tests.rs 96.80% 4 Missing ⚠️
lightning/src/ln/outbound_payment.rs 93.02% 1 Missing and 2 partials ⚠️
lightning/src/ln/channelmanager.rs 83.33% 1 Missing ⚠️
lightning/src/ln/invoice_utils.rs 96.29% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4263      +/-   ##
==========================================
- Coverage   89.33%   89.32%   -0.02%     
==========================================
  Files         180      180              
  Lines      139042   139294     +252     
  Branches   139042   139294     +252     
==========================================
+ Hits       124219   124421     +202     
- Misses      12196    12248      +52     
+ Partials     2627     2625       -2     
Flag Coverage Δ
fuzzing 34.99% <0.00%> (-0.98%) ⬇️
tests 88.68% <91.07%> (-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.

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.

2 participants