Skip to content

Add support for option_payment_metadata#313

Merged
t-bast merged 5 commits intomasterfrom
invoice-payment-metadata
Feb 8, 2022
Merged

Add support for option_payment_metadata#313
t-bast merged 5 commits intomasterfrom
invoice-payment-metadata

Conversation

@t-bast
Copy link
Copy Markdown
Member

@t-bast t-bast commented Dec 9, 2021

Add support for option_payment_metadata as specified in lightning/bolts#912
This feature lets wallets generate "light" invoices without storing them in the local DB until they are paid.

The trick is to simply put the important data (mainly payment_secret and total_amount) in an encrypted blob inside the invoice, and verify its presence and integrity when receiving a payment that contains a payment_metadata field (and insert it in the DB on-the-fly).

This PR only implements support for the sender side, as recipients will only be able to leverage this features once all senders support it.

We do include a payment_metadata in all invoices we generate, which lets us know whether our payers support this feature: this is important data to have before we decide to make it mandatory and actually implement storage-less invoices.

We also take this opportunity to have our first invoice-only feature to implement feature bit filtering, as required by the spec (IN9 flags as specified in bolt 9): see the first commit of the PR.

The second commit does not contain any logic and simply moves data classes around and rename them, it's best reviewed independently.

The third commit contains the actual logic for option_payment_metadata.

@t-bast t-bast force-pushed the invoice-payment-metadata branch from 8ab8694 to 39e8a45 Compare December 21, 2021 13:55
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.
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 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 t-bast force-pushed the invoice-payment-metadata branch from 39e8a45 to 0791667 Compare February 7, 2022 13:34
nodeParams.features,
randomBytes32(),
// We always include a payment metadata in our invoices, which lets us test whether senders support it
randomBytes(64).toByteVector(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: use randomBytes64() ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated in aa81e7d to use a single byte to avoid making invoices too big

description,
PaymentRequest.DEFAULT_MIN_FINAL_EXPIRY_DELTA,
invoiceFeatures,
nodeParams.features,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why not nodeParams.features.initFeatures() ?

Copy link
Copy Markdown
Member Author

@t-bast t-bast Feb 8, 2022

Choose a reason for hiding this comment

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

Done in aebef0c, the feature bits were already filtered inside PaymentRequest.create but it still makes sense to do it here as well.

@t-bast t-bast force-pushed the invoice-payment-metadata branch from abd2f4c to aebef0c Compare February 8, 2022 13:34
@t-bast t-bast merged commit 363ed06 into master Feb 8, 2022
@t-bast t-bast deleted the invoice-payment-metadata branch February 8, 2022 14:04
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