Repository navigation
gl-plugin: make lsp_invoice RPC call store additional invoice metadata - #742
Merged
Merged
Conversation
nepet
requested changes
Aug 27, 2026
nepet
left a comment
Member
There was a problem hiding this comment.
Thank you @Nazarevsky for putting this together.
The approach makes sense and the doc comment on LspInvoiceMeta does a good job explaining why this workaround is needed, which will save the next person a lot of time.
One general note to keep in mind, not a blocker: nothing cleans these entries up on invoice expiry or payment so far, so they accumulate indefinitely. May not be a problem though, if we only store "lsp_invoices" and if we don't expect them to be created indefinitely.
Collaborator
|
@nepet I think this looks quite good now, want me to merge it? |
In order to get an invoice, lsp_invoice RPC call is used, however, no additional information about the requested invoice is stored. That is unfortunate, since we may need this data to detect whether the incomming payment actually used for opening JIT channel or not. Besides, we don't store any information about the original invoice (e.g. the original amount), so this structure includes that information.
When calling lsp_invoice RPC call, two outcomes may be produced: - the client has enough liquidity in channels to receive a payment - a common bolt11 invoice is requested; - the client has not enough liquidity in channels to receive a payment - a JIT channel requested from an LSP; For both variants we use datastore in order to store additional meta information for the invoice. It is worth to state that the key by which the invoice meta distinguished is invoice's label. My first intention was to use payment hash, however, we cannot rely on invoice's payment hashes because invoice payment hashes for an LSP (with original amount) and for a client (with reduced amount) are the same in case of unspecified amount.
…or instead of returning, minor fixes on function signatures There is a bunch minor fixes provided in this commit: - now LspInvoiceMeta contains expected_amount_msat and lsp_id. In lsp_invoice RPC call those are bounded to default values in case of the standart invoice request (not JIT opening). In other case, lsp_id is taken from the active offer and expected_amount_msat is a saturating subtraction of requested_amount_msat and opening_fee_msat; - previously write_lsp_invoice_meta returned an error. Changed it to logging an error instead of returning it; - change write_lsp_invoice_meta signature; - in write_lsp_invoice_meta make record_serialized return Result instead of Status.
Since we moved from storing metadata on an every invoice request to only JIT requets, the data structure name does not longer correspond to it's purpose. Therefore changed it to more appropriate one + updated description.
nepet
force-pushed
the
feature/lsp-invoice-meta-storage
branch
from
September 21, 2026 13:13
afe8879 to
453d4d8
Compare
nepet
approved these changes
Sep 21, 2026
nepet
left a comment
Member
There was a problem hiding this comment.
Thanks @Nazarevsky for this important addition to create a more detailed view of the LSP interactions. LGTM
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Currently, when a client requests for lsp invoice (JIT channel opening), no information about the original invoice is stored. Basically, the client hands out the requested invoice to a payer but receives only reduced amount. We'd like to have a way of understanding whether the requested invoice was for channel opening or a simple payment.
Solution
Introduced a structure
LspInvoiceMetawhich contains all information that we need to store (specifically, bolt11 invoice). Use datastore requests in order to store metadata.LspInvoiceMetais stored in both cases - if the invoice was requested from the LSP or not.Changes
LspInvoiceMetastructure for storing metaLspInvoiceMeta