Skip to content

Follow-up to #792 (multi-LSP support)#956

Open
Camillarhi wants to merge 2 commits into
lightningdevkit:mainfrom
Camillarhi:multi-lsp-support-follow-up
Open

Follow-up to #792 (multi-LSP support)#956
Camillarhi wants to merge 2 commits into
lightningdevkit:mainfrom
Camillarhi:multi-lsp-support-follow-up

Conversation

@Camillarhi

@Camillarhi Camillarhi commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Some minor follow-ups after #792 landed.

  • Retry LSP protocol discovery when it fails at startup, so a transient connection failure doesn't leave a configured LSP permanently unusable. Adds a background retry with backoff and a Liquidity::retry_discovery(node_id) method for on-demand re-discovery (also useful when an LSP rolls out a new protocol).

  • Honor trust_peer_0conf independent of the LSP's supported protocols, It was previously only applied to LSPS2 peers, so LSPS1-only or undiscovered LSPs silently lost their configured 0-conf trust.

Leaving the LSP feature-gating for #900

Fixes - #936

@ldk-reviews-bot

ldk-reviews-bot commented Jul 2, 2026

Copy link
Copy Markdown

👋 Thanks for assigning @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@ldk-reviews-bot ldk-reviews-bot requested a review from tnull July 2, 2026 01:34

@tnull tnull left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excuse the delay here. Second commit seems broken, please avoid the unrelated changes as otherwise it's not really reviewable. Also needs a minor rebase by now.

Comment thread src/lib.rs Outdated
let retry_ls = Arc::clone(&self.liquidity_source);
let retry_logger = Arc::clone(&self.logger);
let retry_cm = Arc::clone(&self.connection_manager);
self.runtime.spawn_background_task(async move {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That likely should be a cancellable task?

Comment thread src/liquidity/mod.rs Outdated
/// The `node_id` must belong to an LSP configured at build time or added via
/// [`Liquidity::add_liquidity_source`]; otherwise [`Error::LiquiditySourceUnavailable`]
/// is returned.
pub fn retry_discovery(&self, node_id: PublicKey) -> Result<(), Error> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of exposing this publicly. Retrying should not be the concern of a user?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was meant to let a user trigger re-discovery for an LSP they know has rolled out a new protocol, the background retry only covers LSPs that never completed discovery in the first place, so an already-discovered LSP adding a protocol wouldn't get picked up.
But thinking about it more, the user usually won't know when an LSP adds a protocol, so leaning on them to call this isn't great. Probably makes more sense to have the background task periodically re-run discovery for already-discovered LSPs too, so new protocols get picked up automatically and there's nothing to expose. I will extend the background check

Comment thread src/liquidity/mod.rs Outdated
.collect()
}

pub(crate) fn get_single_lsp_details(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid such ~single-call helpers (especially if they are only used in one place). Please rather inline them so they don't clutter up the file as much.

Comment thread src/lib.rs Outdated
loop {
let undiscovered_lsps = retry_ls.get_undiscovered_lsps();
if undiscovered_lsps.is_empty() {
tokio::select! {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm? If there's nothing to do, why do need this select?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is there to stop the loop from busy-spinning when there's nothing to discover. The idea was to keep the task alive in case an LSP became undiscovered later, but a runtime add_liquidity_source cleans up the node if its discovery fails, so nothing new ever lands in the undiscovered set after startup. So once it's empty, there's nothing to wait for, and it should just return. I'll clean it up as part of the re-discovery rework, for re-discovering already-discovered LSPs.

Comment thread src/lib.rs Outdated
}
}

tokio::select! {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems an tokio::time::interval would be more suitable?

Comment thread src/lib.rs Outdated

for (node_id, address) in undiscovered_lsps {
if let Err(e) =
retry_cm.connect_peer_if_necessary(node_id, address.clone()).await

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this seems redundant to our general reconnection loop, or not?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configured LSPs aren't added to the peer store at startup, so the reconnection loop doesn't keep them connected. This is what connects us to run discovery.

pub(crate) mod lsps2;
pub use lsps1::LSPS1OrderStatus;
// This file is Copyright its original authors, visible in version control history.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit diff seems to have a lot of unnecessary whitespace/line ending changes. Please amend to avoid that, will re-review then.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the CRLF→LF normalization, which was already flagged as a nit in the earlier review. I'll amend it to pull it out of this commit and into a separate one.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the CRLF→LF normalization, which was already flagged as a nit in the earlier review. I'll amend it to pull it out of this commit and into a separate one.

I think it's been fixed by #965, so shouldn't be necessary if you rebase.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I’ll rebase

Add a background task that retries discovery for any LSP whose protocols
are still undiscovered, using exponential backoff (5s up to 1h). Once no
undiscovered LSPs remain (or the backoff is exhausted), the task settles
into a fixed interval (24h) and re-runs discovery for all configured
LSPs, so we also pick up protocols an LSP rolls out after we first
connected.
Look up trust_peer_0conf by node id via a protocol-independent helper
that does not depend on discovery
@Camillarhi Camillarhi force-pushed the multi-lsp-support-follow-up branch from da5bcdc to b6da9a3 Compare July 9, 2026 20:38
@Camillarhi Camillarhi requested a review from tnull July 9, 2026 20:42
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