Refactor liquidity source to support multiple LSP nodes#792
Conversation
|
👋 Thanks for assigning @tnull as a reviewer! |
|
@tnull Early draft up for review, would appreciate feedback on the general API direction |
tnull
left a comment
There was a problem hiding this comment.
Thanks! Some initial questions..
| supported_protocols: Mutex::new(None), | ||
| }) | ||
| .collect(), | ||
| pending_lsps1_opening_params_requests: Mutex::new(HashMap::new()), |
There was a problem hiding this comment.
Uh, no, I don't think we should just merge all into one. Especially given that we intend to add more logic on a per-spec basis, this will be will become even more confusing going forward. If anything, we should maybe start the refactoring by first moving the LSPS1/LSPS2 specific parts to src/liquidity/{lsps1,lsps2}.rs, or maybe even to client/service specific sub-modules like src/liquidity/{client,service}/{lsps1,lsps2}.rs.
There was a problem hiding this comment.
Alright, I will move the LSPS1/LSPS2 specific parts
| pub(crate) async fn lsps1_request_channel( | ||
| &self, lsp_balance_sat: u64, client_balance_sat: u64, channel_expiry_blocks: u32, | ||
| announce_channel: bool, refund_address: bitcoin::Address, | ||
| announce_channel: bool, refund_address: bitcoin::Address, node_id: &PublicKey, |
There was a problem hiding this comment.
Hmm, I do wonder if it would make sense to create something like an struct ServiceProvider and move the API methods to there. Then, each registered LSP would have a corresponding ServiceProvider that exposes a bunch of public and internal APIs, which would make the modularization cleaner and would avoid having to give node_id everywhere?
There was a problem hiding this comment.
Makes sense, I will have a look and see
3cda7f7 to
8bbf55a
Compare
|
Hello @tnull, apologies for the delay. This is ready for another round of review |
8bbf55a to
ea93afe
Compare
tnull
left a comment
There was a problem hiding this comment.
Cool, already looks pretty good! Did a first higher-level pass, have yet to look into the details.
| @@ -1,1542 +0,0 @@ | |||
| // This file is Copyright its original authors, visible in version control history. | |||
There was a problem hiding this comment.
Would be good to structure this PR in a way that (as far as possible) makes any code moves dedicated commits that can be picked up by git diff --color-moved --patience, as otherwise reviewing this in detail will be very hard.
| } | ||
| } | ||
|
|
||
| discovery_ls.discover_all_lsp_protocols().await; |
There was a problem hiding this comment.
I think it would be good to make this part of the background task above? Also, can we spawn the discovery tasks in parallel rather than doing them sequentially?
| } | ||
|
|
||
| /// Configures the [`Node`] instance to source inbound liquidity from the given LSP at runtime, | ||
| /// without specifying the exact protocol used (e.g., LSPS1 or LSPS2). |
There was a problem hiding this comment.
I think we can drop the remark regarding 'without specifying the exact protocol' here and elsewhere, as the API already communicates that due to being generic. I do however wonder if we'd want to move this method to an API-extension object similar to what we do for the payment types? I.e., retrieve the API object via Node::liquidity()?
There was a problem hiding this comment.
Thanks. I will remove the remark and move this to a Node::liquidity() API-extension
| /// [`Bolt11Payment::receive_via_jit_channel`]: crate::payment::Bolt11Payment::receive_via_jit_channel | ||
| #[derive(Clone)] | ||
| #[cfg_attr(feature = "uniffi", derive(uniffi::Object))] | ||
| pub struct LSPS1Liquidity { |
There was a problem hiding this comment.
It seems this is currently not exposed in the API anymore?
| /// The given `token` will be used by the LSP to authenticate the user. | ||
| /// | ||
| /// [bLIP-51 / LSPS1]: https://github.com/lightning/blips/blob/master/blip-0051.md | ||
| #[deprecated(note = "Use `add_lsp` instead")] |
There was a problem hiding this comment.
Hmm, I think so far we've been fine with just breaking the APIs without deprecating them first. If we find a better API I'd be fine with just dropping the old ones to clean up.
6061c6d to
a560764
Compare
tnull
left a comment
There was a problem hiding this comment.
Cool. Docs CI is currently failing.
Would be great if you try once more to breakup the second commit into smaller chunks, but let me know if it's too cumbersome/impossible.
Feel free to mark ready for review then.
a560764 to
c430e51
Compare
|
🔔 1st Reminder Hey @tnull @valentinewallace! This PR has been waiting for your review. |
1 similar comment
|
🔔 1st Reminder Hey @tnull @valentinewallace! This PR has been waiting for your review. |
|
🔔 2nd Reminder Hey @tnull @valentinewallace! This PR has been waiting for your review. |
1 similar comment
|
🔔 2nd Reminder Hey @tnull @valentinewallace! This PR has been waiting for your review. |
|
🔔 3rd Reminder Hey @tnull @valentinewallace! This PR has been waiting for your review. |
1 similar comment
|
🔔 3rd Reminder Hey @tnull @valentinewallace! This PR has been waiting for your review. |
|
🔔 4th Reminder Hey @tnull @valentinewallace! This PR has been waiting for your review. |
1 similar comment
|
🔔 4th Reminder Hey @tnull @valentinewallace! This PR has been waiting for your review. |
22da16c to
2cda868
Compare
606bcf2 to
a55f8b3
Compare
tnull
left a comment
There was a problem hiding this comment.
Seems CI is unfortunately failing right now (CLN failure is unrelated though).
b5a5fa4 to
3c80fdc
Compare
The failing CI has been resolved |
|
🔔 1st Reminder Hey @tnull! This PR has been waiting for your review. |
|
🔔 2nd Reminder Hey @tnull! This PR has been waiting for your review. |
|
🔔 3rd Reminder Hey @tnull! This PR has been waiting for your review. |
f3r10
left a comment
There was a problem hiding this comment.
Great work. Still trying to understand all the changes.
| /// The channel will be opened after one of the returned payment options has successfully been | ||
| /// paid. | ||
| /// | ||
| /// If `node_id` is `None` and multiple LSPs support LSPS1, the first one registered |
There was a problem hiding this comment.
I have one question: Was best-price comparison across multiple LSPS1 providers considered? LSPS2 queries all providers and picks the cheapest, but LSPS1 falls back to the first registered. Is there a reason for this asymmetry, or is price comparison for LSPS1 planned for the future?
There was a problem hiding this comment.
The behavioral difference is intentional and rests on two things:
- The API exposure,
LSPS1Liquidity::request_channeltakesnode_id: Option<PublicKey>and is the user's primary entry point, whilelsps2_receive_to_jit_channelfor example is invoked internally fromBolt11Payment::receive_via_jit_channel, therefore the choice is automated - The Protocol shape, LSPS2 has a
request_opening_paramswhich returns a fee menu, so cost is computable. LSPS1 has arequest_supported_optionswhich returns only capability ranges , no fee fields. The price will only materialize fromcreate_order, which commits to a specific order with a specific LSP.
| allow_0conf = allow_0conf || lsp.trust_peer_0conf; | ||
| } | ||
|
|
||
| if self.liquidity_source.get_lsp_config(&counterparty_node_id, Some(2)).is_some() { |
There was a problem hiding this comment.
If an LSPS2-capable LSP opens a channel before its discovery completes (i.e. supported_protocols is still None), get_lsp_config(Some(2)) returns None and accept_underpaying_htlcs is never enabled. Could this silently break the JIT channel flow for fast LSPs?
There was a problem hiding this comment.
Thanks for pointing this out, discovery_done wait was not covered here. It has been updated
3c80fdc to
1a449ef
Compare
|
🔔 4th Reminder Hey @tnull! This PR has been waiting for your review. |
|
🔔 5th Reminder Hey @tnull! This PR has been waiting for your review. |
|
🔔 6th Reminder Hey @tnull! This PR has been waiting for your review. |
1a449ef to
d39186a
Compare
|
🔔 7th Reminder Hey @tnull! This PR has been waiting for your review. |
Replace per-protocol single-LSP configuration `LSPS1Client` and `LSPS2Client` with a unified `Vec<LspNode>` model where users configure LSP nodes via `add_liquidity_source()` at build time or runtime and per-LSP protocol support is discovered via the LSPS0 `list_protocols`. - Introduce a per-LSP `trust_peer_0conf` flag to `LspConfig`/`LspNode` structs that controls whether 0-conf channels from that LSP are accepted - Add LSPS0 protocol discovery `discover_lsp_protocols` with event handling for `ListProtocolsResponse` - Update events to also use each LSP's `trust_peer_0conf` flag when deciding whether to allow 0-conf channels - Replace `set_liquidity_source_lsps1` and `set_liquidity_source_lsps2` builder methods with a single `add_liquidity_source()` that takes a `trust_peer_0conf` flag - Rename `set_liquidity_provider_lsps2` to `enable_liquidity_provider` - LSPS2 JIT channels now query all LSPS2-capable LSPs and automatically select the cheapest fee offer across all of them - Spawn background discovery task on `Node::start()` and expose a watch channel so dependent flows can wait for discovery to complete - Add a new `Liquidity` handler `Node::liquidity()` exposing `add_liquidity_source()` API for adding LSPs at runtime, and `lsps1()` for the existing LSPS1 surface
Remove the `Ignoring` variant now that the liquidity source is always built, so the enum and its match arms are now pure overhead. Replace it with a struct that holds the `LiquiditySource` directly and have each trait method delegate straight to `liquidity_manager()`.
d39186a to
51e3f54
Compare
|
🔔 8th Reminder Hey @tnull! This PR has been waiting for your review. |
The current setup ties you to a single LSP per protocol via
set_liquidity_source_lsps1/set_liquidity_source_lsps2. This refactor replaces that with a unifiedVec<LspNode>model where LSP nodes are added viaadd_lsp()and protocol support is discovered at runtime through LSPS0list_protocols. Multi-LSP support has been requested previously in #529.set_liquidity_source_lsps1/set_liquidity_source_lsps2in favor ofadd_lsp()LSPS1Client/LSPS2Clientwith global pending request maps keyed byLSPSRequestIdListProtocolsResponseNode::start()request_channel_from_lsp()for explicit LSPS1 LSP selectionis_lsps_node()for multi-LSP counterparty checksThis sets the foundation for LSPS5 support currently being worked on in #729