-
Notifications
You must be signed in to change notification settings - Fork 456
Add a payment_metadata map in blinded * path contexts
#4584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TheBlueMatt
wants to merge
4
commits into
lightningdevkit:main
Choose a base branch
from
TheBlueMatt:2026-04-bolt12-custom-data
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8b1c771
`as_ref()` before wrapping encoded types in writing `option` TLVs
TheBlueMatt 05135ae
Fix typo in `_encode_tlv` leading to confused encoding
TheBlueMatt f4b7ac7
Add a `payment_metadata` map in blinded payment path contexts
TheBlueMatt b8375a7
Add a `payment_metadata` map in BOLT 12 blinded message path ctxs
TheBlueMatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ | |
|
|
||
| //! Data structures and methods for constructing [`BlindedPaymentPath`]s to send a payment over. | ||
|
|
||
| use alloc::collections::BTreeMap; | ||
|
|
||
| use bitcoin::secp256k1::ecdh::SharedSecret; | ||
| use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey}; | ||
|
|
||
|
|
@@ -29,8 +31,8 @@ use crate::types::features::BlindedHopFeatures; | |
| use crate::types::payment::PaymentSecret; | ||
| use crate::types::routing::RoutingFees; | ||
| use crate::util::ser::{ | ||
| FixedLengthReader, HighZeroBytesDroppedBigSize, LengthReadableArgs, Readable, WithoutLength, | ||
| Writeable, Writer, | ||
| BigSizeKeyedMap, FixedLengthReader, HighZeroBytesDroppedBigSize, LengthReadableArgs, Readable, | ||
| WithoutLength, Writeable, Writer, | ||
| }; | ||
|
|
||
| #[allow(unused_imports)] | ||
|
|
@@ -572,6 +574,16 @@ pub enum PaymentContext { | |
| /// [`Refund`]: crate::offers::refund::Refund | ||
| Bolt12Refund(Bolt12RefundContext), | ||
| } | ||
| impl PaymentContext { | ||
| /// Returns the additional payment metadata stored alongside this payment context, if any. | ||
| pub fn payment_metadata(&self) -> Option<&BTreeMap<u64, Vec<u8>>> { | ||
| match self { | ||
| Self::Bolt12Offer(Bolt12OfferContext { payment_metadata, .. }) | ||
| | Self::AsyncBolt12Offer(AsyncBolt12OfferContext { payment_metadata, .. }) | ||
| | Self::Bolt12Refund(Bolt12RefundContext { payment_metadata, .. }) => payment_metadata.as_ref(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Used when writing PaymentContext in Event::PaymentClaimable to avoid cloning. | ||
| pub(crate) enum PaymentContextRef<'a> { | ||
|
|
@@ -594,6 +606,22 @@ pub struct Bolt12OfferContext { | |
| /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest | ||
| /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice | ||
| pub invoice_request: InvoiceRequestFields, | ||
|
|
||
| /// Additional data about this payment which is not used in LDK and can be used for any | ||
| /// purpose. | ||
| /// | ||
| /// This is analogous to the BOLT 11 [`RecipientOnionFields::payment_metadata`] (which is | ||
| /// provided to payers via [`Bolt11Invoice::payment_metadata`]) and can be used any time data | ||
| /// needs to be "stored" by a payment recipient for their own internal use, provided back to | ||
| /// them with the payment. | ||
| /// | ||
|
TheBlueMatt marked this conversation as resolved.
|
||
| /// Note that because this is included in the payment onion, its size must be tightly | ||
| /// constrained. More than a few hundred bytes and the payment will be entirely unpayable (with | ||
| /// limited routing options as size increases). | ||
| /// | ||
| /// [`RecipientOnionFields::payment_metadata`]: crate::ln::outbound_payment::RecipientOnionFields::payment_metadata | ||
| /// [`Bolt11Invoice::payment_metadata`]: lightning_invoice::Bolt11Invoice::payment_metadata | ||
| pub payment_metadata: Option<BTreeMap<u64, Vec<u8>>>, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above: what are we expecting users to set the Shouldn't we rather use a dedicated |
||
| } | ||
|
|
||
| /// The context of a payment made for a static invoice requested from a BOLT 12 [`Offer`]. | ||
|
|
@@ -606,13 +634,45 @@ pub struct AsyncBolt12OfferContext { | |
| /// | ||
| /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest | ||
| pub offer_nonce: Nonce, | ||
|
|
||
| /// Additional data about this payment which is not used in LDK and can be used for any | ||
| /// purpose. | ||
| /// | ||
| /// This is analogous to the BOLT 11 [`RecipientOnionFields::payment_metadata`] (which is | ||
| /// provided to payers via [`Bolt11Invoice::payment_metadata`]) and can be used any time data | ||
| /// needs to be "stored" by a payment recipient for their own internal use, provided back to | ||
| /// them with the payment. | ||
| /// | ||
| /// Note that because this is included in the payment onion, its size must be tightly | ||
| /// constrained. More than a few hundred bytes and the payment will be entirely unpayable (with | ||
| /// limited routing options as size increases). | ||
| /// | ||
| /// [`RecipientOnionFields::payment_metadata`]: crate::ln::outbound_payment::RecipientOnionFields::payment_metadata | ||
| /// [`Bolt11Invoice::payment_metadata`]: lightning_invoice::Bolt11Invoice::payment_metadata | ||
| pub payment_metadata: Option<BTreeMap<u64, Vec<u8>>>, | ||
| } | ||
|
|
||
| /// The context of a payment made for an invoice sent for a BOLT 12 [`Refund`]. | ||
| /// | ||
| /// [`Refund`]: crate::offers::refund::Refund | ||
| #[derive(Clone, Debug, Eq, PartialEq)] | ||
| pub struct Bolt12RefundContext {} | ||
| pub struct Bolt12RefundContext { | ||
| /// Additional data about this payment which is not used in LDK and can be used for any | ||
| /// purpose. | ||
| /// | ||
| /// This is analogous to the BOLT 11 [`RecipientOnionFields::payment_metadata`] (which is | ||
| /// provided to payers via [`Bolt11Invoice::payment_metadata`]) and can be used any time data | ||
| /// needs to be "stored" by a payment recipient for their own internal use, provided back to | ||
| /// them with the payment. | ||
| /// | ||
| /// Note that because this is included in the payment onion, its size must be tightly | ||
| /// constrained. More than a few hundred bytes and the payment will be entirely unpayable (with | ||
| /// limited routing options as size increases). | ||
| /// | ||
| /// [`RecipientOnionFields::payment_metadata`]: crate::ln::outbound_payment::RecipientOnionFields::payment_metadata | ||
| /// [`Bolt11Invoice::payment_metadata`]: lightning_invoice::Bolt11Invoice::payment_metadata | ||
| pub payment_metadata: Option<BTreeMap<u64, Vec<u8>>>, | ||
| } | ||
|
|
||
| impl TryFrom<CounterpartyForwardingInfo> for PaymentRelay { | ||
| type Error = (); | ||
|
|
@@ -1031,14 +1091,18 @@ impl<'a> Writeable for PaymentContextRef<'a> { | |
|
|
||
| impl_writeable_tlv_based!(Bolt12OfferContext, { | ||
| (0, offer_id, required), | ||
| (1, payment_metadata, (option, encoding: (BTreeMap<u64, Vec<u8>>, BigSizeKeyedMap))), | ||
| (2, invoice_request, required), | ||
| }); | ||
|
|
||
| impl_writeable_tlv_based!(AsyncBolt12OfferContext, { | ||
| (0, offer_nonce, required), | ||
| (1, payment_metadata, (option, encoding: (BTreeMap<u64, Vec<u8>>, BigSizeKeyedMap))), | ||
| }); | ||
|
|
||
| impl_writeable_tlv_based!(Bolt12RefundContext, {}); | ||
| impl_writeable_tlv_based!(Bolt12RefundContext, { | ||
| (1, payment_metadata, (option, encoding: (BTreeMap<u64, Vec<u8>>, BigSizeKeyedMap))), | ||
| }); | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
|
|
@@ -1097,7 +1161,9 @@ mod tests { | |
| let recv_tlvs = ReceiveTlvs { | ||
| payment_secret: PaymentSecret([0; 32]), | ||
| payment_constraints: PaymentConstraints { max_cltv_expiry: 0, htlc_minimum_msat: 1 }, | ||
| payment_context: PaymentContext::Bolt12Refund(Bolt12RefundContext {}), | ||
| payment_context: PaymentContext::Bolt12Refund(Bolt12RefundContext { | ||
| payment_metadata: None, | ||
| }), | ||
| }; | ||
| let htlc_maximum_msat = 100_000; | ||
| let blinded_payinfo = | ||
|
|
@@ -1115,7 +1181,9 @@ mod tests { | |
| let recv_tlvs = ReceiveTlvs { | ||
| payment_secret: PaymentSecret([0; 32]), | ||
| payment_constraints: PaymentConstraints { max_cltv_expiry: 0, htlc_minimum_msat: 1 }, | ||
| payment_context: PaymentContext::Bolt12Refund(Bolt12RefundContext {}), | ||
| payment_context: PaymentContext::Bolt12Refund(Bolt12RefundContext { | ||
| payment_metadata: None, | ||
| }), | ||
| }; | ||
| let blinded_payinfo = super::compute_payinfo::<ForwardTlvs>( | ||
| &[], | ||
|
|
@@ -1178,7 +1246,9 @@ mod tests { | |
| let recv_tlvs = ReceiveTlvs { | ||
| payment_secret: PaymentSecret([0; 32]), | ||
| payment_constraints: PaymentConstraints { max_cltv_expiry: 0, htlc_minimum_msat: 3 }, | ||
| payment_context: PaymentContext::Bolt12Refund(Bolt12RefundContext {}), | ||
| payment_context: PaymentContext::Bolt12Refund(Bolt12RefundContext { | ||
| payment_metadata: None, | ||
| }), | ||
| }; | ||
| let htlc_maximum_msat = 100_000; | ||
| let blinded_payinfo = super::compute_payinfo( | ||
|
|
@@ -1238,7 +1308,9 @@ mod tests { | |
| let recv_tlvs = ReceiveTlvs { | ||
| payment_secret: PaymentSecret([0; 32]), | ||
| payment_constraints: PaymentConstraints { max_cltv_expiry: 0, htlc_minimum_msat: 1 }, | ||
| payment_context: PaymentContext::Bolt12Refund(Bolt12RefundContext {}), | ||
| payment_context: PaymentContext::Bolt12Refund(Bolt12RefundContext { | ||
| payment_metadata: None, | ||
| }), | ||
| }; | ||
| let htlc_minimum_msat = 3798; | ||
| assert!(super::compute_payinfo( | ||
|
|
@@ -1309,7 +1381,9 @@ mod tests { | |
| let recv_tlvs = ReceiveTlvs { | ||
| payment_secret: PaymentSecret([0; 32]), | ||
| payment_constraints: PaymentConstraints { max_cltv_expiry: 0, htlc_minimum_msat: 1 }, | ||
| payment_context: PaymentContext::Bolt12Refund(Bolt12RefundContext {}), | ||
| payment_context: PaymentContext::Bolt12Refund(Bolt12RefundContext { | ||
| payment_metadata: None, | ||
| }), | ||
| }; | ||
|
|
||
| let blinded_payinfo = super::compute_payinfo( | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type here needs docs, in particular what the
u64is representing.