Skip to content

gl-plugin: make lsp_invoice RPC call store additional invoice metadata - #742

Merged
nepet merged 5 commits into
mainfrom
feature/lsp-invoice-meta-storage
Sep 21, 2026
Merged

nepet merged 5 commits into
mainfrom
feature/lsp-invoice-meta-storage

Conversation

@Nazarevsky

Copy link
Copy Markdown
Member

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 LspInvoiceMeta which contains all information that we need to store (specifically, bolt11 invoice). Use datastore requests in order to store metadata. LspInvoiceMeta is stored in both cases - if the invoice was requested from the LSP or not.

Changes

  • introduced LspInvoiceMeta structure for storing meta
  • updated lsp_invoice RPC call to store LspInvoiceMeta

@Nazarevsky
Nazarevsky requested a review from nepet August 25, 2026 16:14
@Nazarevsky Nazarevsky self-assigned this Aug 25, 2026

@nepet nepet left a comment

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.

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.

Comment thread libs/gl-plugin/src/node/mod.rs Outdated
Comment thread libs/gl-plugin/src/storage.rs
Comment thread libs/gl-plugin/src/node/mod.rs Outdated
Comment thread libs/gl-plugin/src/node/mod.rs Outdated
Comment thread libs/gl-plugin/src/node/mod.rs Outdated
Comment thread libs/gl-plugin/src/node/mod.rs
@cdecker
cdecker requested a review from nepet September 13, 2026 12:00
@cdecker

cdecker commented Sep 13, 2026

Copy link
Copy Markdown
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
nepet force-pushed the feature/lsp-invoice-meta-storage branch from afe8879 to 453d4d8 Compare September 21, 2026 13:13

@nepet nepet left a comment

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.

Thanks @Nazarevsky for this important addition to create a more detailed view of the LSP interactions. LGTM

@nepet
nepet enabled auto-merge (rebase) September 21, 2026 13:15
@nepet
nepet merged commit 15b22cf into main Sep 21, 2026
16 checks passed
@nepet
nepet deleted the feature/lsp-invoice-meta-storage branch September 21, 2026 13:27
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.

3 participants