Repository navigation
Conversation
Andezion
left a comment
There was a problem hiding this comment.
In on_channel_opened, why spend the approval that expires first, and not keep a small "pending opens per peer" set filled by the openchannel hook? also on_lsps_lsps2_approve, on_channel_opened and on_peer_connected each rebuild rpc_path and call ClnRpc::new. maybe we could add a small State::rpc() helper, it could remove about 5 copies
a697d20 to
ead247a
Compare
|
@Andezion Thanks for your review! On which approval to spend: A pending-opens set filled in the
|
ead247a to
117f23c
Compare
Split lsps2_mock_pay() out of lsps2_mock_pay_var_invoice(), so that a test can pay the same invoice twice, or several invoices. Changelog-None
117f23c to
25ae864
Compare
…hannel is open
The LSPS2 client approved zero-conf channels from an LSP with a single
datastore record, lsps/client/<lsp_id>, and deleted it in the
openchannel hook. So:
- if the open failed after the hook, e.g. because we disconnected
before sending funding_signed, the LSP's open for the payer's retry
was refused ("You required zeroconf, but you're not on our
allowlist"), and the buy could not be paid;
- two outstanding JIT invoices from the same LSP shared the record, so
the channel for the second one was refused.
Keep an approval per buy instead, lsps/client/<lsp_id>/<jit_channel_scid>,
until the buy's invoice expires. The openchannel hook allows a zero-conf
channel from the LSP while one of its approvals is left, but no longer
spends it; open_channel doesn't say which buy the channel is for anyway.
An approval is spent once lightningd has saved the channel: it sends
channel_opened before funding_signed, so the LSP still gets one channel
per buy. A dual-funded channel from the LSP doesn't spend one: the
openchannel hook only sees v1 opens, so it never made that channel
zero-conf. If a spent approval's channel is still waiting for
channel_ready when the LSP reconnects, the LSP never got our
funding_signed, and the approval is given back for its retry. Once the
channel got going, the spent approval is deleted: when the buy's invoice
is paid, or on reconnect. An approval given back remembers the channel
it came from, and is deleted the same way if that channel gets going
after all.
If the channel is gone, the approval is given back without waiting for
a reconnect: lightningd forgets a channel the LSP opened when the LSP
fails it before it got going. The openchannel hook gives those back
when all of the LSP's approvals are spent, so the LSP's retry gets one.
A channel we close ourselves before it got going counts as got going,
which errs towards refusing the LSP's next channel for the buy.
Expired approvals, and the record older versions kept, are deleted when
the LSP's approvals are next read.
Changelog-Experimental: lsps-plugin: the LSPS2 client accepts the JIT channel for a payment retried after a failed open, and for each of several JIT invoices from the same LSP.
25ae864 to
f6610b8
Compare
Checklist
Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:
tools/lightning-downgradeFixes #9715.
The LSPS2 client accepted a zero-conf channel from an LSP with a single datastore record per LSP, and deleted it in the
openchannelhook. So if the open failed after the hook, e.g. because we disconnected before sendingfunding_signed, the LSP's open for the payer's retry was refused. And two outstanding JIT invoices from the same LSP shared the record, so the second invoice's channel was refused.This keeps an approval per buy,
lsps/client/<lsp_id>/<jit_channel_scid>, until the buy's invoice expires:openchannelhook allows a zero-conf channel while the LSP has an approval left, but doesn't spend it:open_channeldoesn't say which buy it is forchannel_opened, which comes beforefunding_signed), so the LSP still gets one channel per buy. A dual-funded channel doesn't spend one: the hook only sees v1 opens, so it never made that channel zero-confchannel_readywhen the LSP reconnects (peer_connected), the LSP never got ourfunding_signed, and the approval is given back for its retryopenchannelhook gives those back when all of the LSP's approvals are spent, so the retry gets oneThe first commit lets the mock tests pay an invoice they already have. The second adds three tests against the mock LSP: the retry after a disconnect before
funding_signed, two invoices from the same LSP, paid in either order, and an LSP that opens a second channel for a buy (refused before and after, the test checks it is the zero-conf refusal).Limits: an LSP that disconnects before sending
channel_readygets the approval back on reconnect, at the cost of a funding output it never broadcasts. Any v1 channel the LSP opens while a buy is outstanding spends an approval, as the hook makes it zero-conf, and a channel we close ourselves before it got going counts as got going; both only err towards refusing. Theopenchannelhook and thechannel_openednotification run as separate tasks. lightningd refuses a second open while one is in progress, so the LSP's next open can only start once the first channel is saved. An LSP that sends it right away may still have its hook run before the notification spends the approval, and get a second zero-conf channel for the buy.lsps-lsps2-approvenow looks up the buy's invoice bypayment_hashto take its expiry, so it fails if no such invoice exists.lsps-lsps2-invoicecalls it after creating the invoice.Changelog-Experimental: lsps-plugin: the LSPS2 client accepts the JIT channel for a payment retried after a failed open, and for each of several JIT invoices from the same LSP.