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 support for option_payment_metadata #313

Merged
merged 5 commits into from
Feb 8, 2022
Merged

Conversation

t-bast
Copy link
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.

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.
src/commonMain/kotlin/fr/acinq/lightning/Features.kt Outdated Show resolved Hide resolved
randomBytes32(),
// We always include a payment metadata in our invoices, which lets us test whether senders support it
randomBytes(64).toByteVector(),
Copy link
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
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

@@ -84,8 +87,10 @@ class IncomingPaymentHandler(val nodeParams: NodeParams, val walletParams: Walle
nodeParams.nodePrivateKey,
description,
PaymentRequest.DEFAULT_MIN_FINAL_EXPIRY_DELTA,
invoiceFeatures,
nodeParams.features,
Copy link
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
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 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.

None yet

2 participants