-
Notifications
You must be signed in to change notification settings - Fork 24
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
Conversation
8ab8694
to
39e8a45
Compare
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.
39e8a45
to
0791667
Compare
randomBytes32(), | ||
// We always include a payment metadata in our invoices, which lets us test whether senders support it | ||
randomBytes(64).toByteVector(), |
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.
nit: use randomBytes64()
?
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.
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, |
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.
why not nodeParams.features.initFeatures()
?
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.
Done in aebef0c, the feature bits were already filtered inside PaymentRequest.create
but it still makes sense to do it here as well.
abd2f4c
to
aebef0c
Compare
Add support for
option_payment_metadata
as specified in lightning/bolts#912This 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
andtotal_amount
) in an encrypted blob inside the invoice, and verify its presence and integrity when receiving a payment that contains apayment_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
.