Skip to content
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

Add payment metadata to payment request (feature 48) #912

Merged
merged 1 commit into from
Jan 3, 2022

Conversation

joostjager
Copy link
Collaborator

@joostjager joostjager commented Sep 21, 2021

This PR adds a new field to bolt11 invoices for payment metadata. Senders are supposed to carry over this data to a tlv field to provide context for stateless invoice applications.

More background on stateless invoices: https://lists.linuxfoundation.org/pipermail/lightning-dev/2021-September/003236.html

Please attach comments to the most appropriate line of the diff, so that discussions remain threaded and can eventually be resolved. We all know what PRs look like with too many top level comments.

11-payment-encoding.md Outdated Show resolved Hide resolved
@t-bast
Copy link
Collaborator

t-bast commented Sep 24, 2021

Interestingly, this will come for free with route blinding: #765
We introduce a recipient_secret in a payload that is encrypted for the recipient-only, and lets it avoid having to store data to validate a blinded route. That field can hold arbitrary data, so it does also enable your use-case.

@joostjager joostjager changed the title Add payment metadata to payment request Add payment metadata to payment request (feature 48) Sep 28, 2021
09-features.md Outdated Show resolved Hide resolved
04-onion-routing.md Outdated Show resolved Hide resolved
@rustyrussell
Copy link
Collaborator

So, @joostjager pointed out that you could just use "beer" and mix with an internal secret; the metadata doesn't need to be a UUID.

In general, however, this is not robust: you would not know if you have issued two such invoices simultaneously (if you did it serially, it's OK, since presumably you remember successfully-paid invoices, and could check for clashes).

And, if it serves as a UUID, it also serves as a payment secret?

@joostjager
Copy link
Collaborator Author

So, @joostjager pointed out that you could just use "beer" and mix with an internal secret; the metadata doesn't need to be a UUID.

In general, however, this is not robust: you would not know if you have issued two such invoices simultaneously (if you did it serially, it's OK, since presumably you remember successfully-paid invoices, and could check for clashes).

I suggested to indeed use "beer" but also append the payment address before mixing with the internal secret. So this should keep invoices apart.

Copy link
Collaborator

@t-bast t-bast left a comment

Choose a reason for hiding this comment

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

ACK once the pending comments are fixed.

I think we can (should?) integrate sender-side support ASAP, because it's trivial (just grab a field in the invoice, put it in the onion). Then after XXX months (when we see that senders have actually added support) we'll be able to leverage it on the recipient side.

11-payment-encoding.md Outdated Show resolved Hide resolved
@joostjager
Copy link
Collaborator Author

I think we can (should?) integrate sender-side support ASAP, because it's trivial (just grab a field in the invoice, put it in the onion). Then after XXX months (when we see that senders have actually added support) we'll be able to leverage it on the recipient side.

Agreed. It takes time for this change to actually land in wallet software.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Agreed, lets get payer-side support for this sooner rather than later.

Copy link
Collaborator

@t-bast t-bast left a comment

Choose a reason for hiding this comment

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

I have a draft PR ready on the eclair side if you want to do cross-compatibility tests: ACINQ/eclair#2063

@@ -263,6 +263,9 @@ It is formatted according to the Type-Length-Value format defined in [BOLT #1](0
2. data:
* [`32*byte`:`payment_secret`]
* [`tu64`:`total_msat`]
1. type: 10 (`payment_metadata`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Route blinding already uses types 10 and 12, would it be possible to update this PR to use type 14 for payment_metadata?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, it looks like AMP is using 14 already. Shall we move to 16 then?

Copy link
Collaborator

Choose a reason for hiding this comment

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

What about AMP updating to another field? It's not documented that they use 14, not even in #658 AFAICT...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Haha, that is not a q for me to answer 🍿

To be consequent, I think we should use 10 then?

Copy link
Collaborator

Choose a reason for hiding this comment

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

To be consequent, I think we should use 10 then?

Not quite, route blinding has documented that it uses 10 and 12 (for 6+ months) and already has two implementations' ACKs and cross-compatibility successfully tested (even before payment_metadata, so it does take precedence). AMP has no spec and only one implementation...

Your call, you can either update to 16 here or ask lnd folks. In all cases using 14 for AMP without specifying it anywhere is reckless, it just creates a big risk that another feature will ship across multiple implementations and use 14 for something else which will be a huge pain to update. Until specified, AMP should use a TLV in the high range to avoid running into this kind of compatibility problems.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let's update to 16 so that we are unblocked.

Tagging @Roasbeef here for comment on AMP.

11-payment-encoding.md Outdated Show resolved Hide resolved
@@ -235,6 +238,9 @@ by which the description is served is as-yet unspecified and will
probably be transport dependent. The `h` format could change in the future,
by changing the length, so readers ignore it if it's not 256 bits.

The `m` field allows metadata to be attached to the payment. This supports
applications where the recipient doesn't keep any context for the payment.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is more a rationale for how this field could be used, but i can see other use cases as well (split PoS and recipient, ...). I'd personally prefer having these separate from the prescriptive text.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But this part is already inside the rationale section, isn't it? So it should be ok? Or do you mean that you don't want something as concrete here, and would rather have a separate doc (a spark?) explain how the payment_metadata field can be used for invoices not stored in a local DB?

Copy link
Collaborator

@t-bast t-bast left a comment

Choose a reason for hiding this comment

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

ACK 41962a7

@@ -216,7 +218,8 @@ A reader:
- MUST use that as [`payment_secret`](04-onion-routing.md#tlv_payload-payload-format)
- if the `c` field (`min_final_cltv_expiry`) is not provided:
- MUST use an expiry delta of at least 18 when making the payment

- if an `m` field is provided:
- MUST use that as [`payment_metadata`](04-onion-routing.md#tlv_payload-payload-format)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: please add an empty line between this and ### Rationale

Copy link
Collaborator

@t-bast t-bast left a comment

Choose a reason for hiding this comment

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

ACK 2ab3a9f

@rustyrussell
Copy link
Collaborator

Ack 2ab3a9f

@joostjager
Copy link
Collaborator Author

joostjager commented Jan 3, 2022

Carried out interop test lnd->eclair, that works too.

@TheBlueMatt TheBlueMatt merged commit f6c4d76 into lightning:master Jan 3, 2022
Copy link
Contributor

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

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

ack 2ab3a9f

with latency, sorry :)

t-bast added a commit to ACINQ/eclair that referenced this pull request Jan 10, 2022
* Filter init, node and invoice features

We should explicitly filter features based on where they can be included
(`init`, `node_announcement` or `invoice`) as specified in Bolt 9.

* Add support for sending `payment_metadata`

Whenever we find a payment metadata field in an invoice, we send it in
the onion payload for the final recipient.

* Include `payment_metadata` in all invoices

We include a payment metadata in every invoice we generate. This lets us
see whether our payers support it or not, which is important data to have
before we make it mandatory and use it for storage-less invoices.

See lightning/bolts#912 for reference.
t-bast added a commit to ACINQ/lightning-kmp that referenced this pull request Feb 7, 2022
Add support for lightning/bolts#912

Whenever we find a payment metadata field in an invoice, we send it in
the onion payload for the final recipient.

We include a payment metadata in every invoice we generate. This lets us
see whether our payers support it or not, which is important data to have
before we make it mandatory and use it for storage-less invoices.
t-bast added a commit to ACINQ/lightning-kmp that referenced this pull request Feb 8, 2022
* Filter init, node and invoice features

We should explicitly filter features based on where they can be included
(`init`, `node_announcement` or `invoice`) as specified in Bolt 9.

We also introduce the option_payment_metadata feature which helps our
test cases since it's only allowed in invoices.

* Refactor onion to dedicated namespace

This commit doesn't contain any logic, it simply prefixes some classes
to make it obvious that they are payment-related, rename files and
moves some classes.

We will update the payment onion, so it was a good time to do this small
refactoring which will also be necessary for onion messages.

* Add support for option_payment_metadata

Add support for lightning/bolts#912

Whenever we find a payment metadata field in an invoice, we send it in
the onion payload for the final recipient.

We include a payment metadata in every invoice we generate. This lets us
see whether our payers support it or not, which is important data to have
before we make it mandatory and use it for storage-less invoices.
rustyrussell added a commit to rustyrussell/lightning that referenced this pull request Mar 11, 2022
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: `pay` (and decode, etc) supports bolt11 payment_metadata a-la lightning/bolts#912
rustyrussell added a commit to rustyrussell/lightning that referenced this pull request Mar 12, 2022
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: `pay` (and decode, etc) supports bolt11 payment_metadata a-la lightning/bolts#912
rustyrussell added a commit to rustyrussell/lightning that referenced this pull request Mar 12, 2022
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: `pay` (and decode, etc) supports bolt11 payment_metadata a-la lightning/bolts#912
rustyrussell added a commit to rustyrussell/lightning that referenced this pull request Mar 22, 2022
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: `pay` (and decode, etc) supports bolt11 payment_metadata a-la lightning/bolts#912
rustyrussell added a commit to rustyrussell/lightning that referenced this pull request Mar 24, 2022
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: `pay` (and decode, etc) supports bolt11 payment_metadata a-la lightning/bolts#912
@jb55 jb55 mentioned this pull request Mar 24, 2022
rustyrussell added a commit to rustyrussell/lightning that referenced this pull request Mar 25, 2022
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: `pay` (and decode, etc) supports bolt11 payment_metadata a-la lightning/bolts#912
rustyrussell added a commit to rustyrussell/lightning that referenced this pull request Mar 28, 2022
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: `pay` (and decode, etc) supports bolt11 payment_metadata a-la lightning/bolts#912
rustyrussell added a commit to rustyrussell/lightning that referenced this pull request Mar 29, 2022
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: `pay` (and decode, etc) supports bolt11 payment_metadata a-la lightning/bolts#912
rustyrussell added a commit to rustyrussell/lightning that referenced this pull request Mar 30, 2022
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: `pay` (and decode, etc) supports bolt11 payment_metadata a-la lightning/bolts#912
rustyrussell added a commit to rustyrussell/lightning that referenced this pull request Mar 30, 2022
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: `pay` (and decode, etc) supports bolt11 payment_metadata a-la lightning/bolts#912
rustyrussell added a commit to rustyrussell/lightning that referenced this pull request Mar 31, 2022
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: `pay` (and decode, etc) supports bolt11 payment_metadata a-la lightning/bolts#912
rustyrussell added a commit to rustyrussell/lightning that referenced this pull request Apr 1, 2022
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: `pay` (and decode, etc) supports bolt11 payment_metadata a-la lightning/bolts#912
rustyrussell added a commit to ElementsProject/lightning that referenced this pull request Apr 1, 2022
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: `pay` (and decode, etc) supports bolt11 payment_metadata a-la lightning/bolts#912
@joostjager
Copy link
Collaborator Author

@t-bast I vaguely remember that you planned to add marker metadata to all invoices generated in your systems, to be able to gauge the uptake of the payment metadata feature. Did you do that in the end, and if yes, can you share how it is going?

@t-bast
Copy link
Collaborator

t-bast commented Dec 21, 2022

This was added in eclair and phoenix, but it doesn't give us a very easy way of measuring support. Only the phoenix recipient knows whether the sender included the payment metadata and this information isn't shared with our node. Our node doesn't issue invoices so we don't have any data about that.

This would be more interesting to measure at big hubs that acts as receiver nodes: Wallet of Satoshi, Muun and the likes. Those nodes are generating a lot of invoices and receiving payments and can better measure what percentage of senders do include the metadata.

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.

None yet

8 participants