Skip to content

Conversation

@amackillop
Copy link
Contributor

Usable channels are a strict superset of ready channels and are
ultimately what is required for payouts to succeed. LDK node starts
fresh on each request and could reach the point of trying to pay
before the channels are marked as usable. Usable means that the channel
is ready, the peer is connected, and the channel is not negotiating
a shutdown.

Wait for all channels to be marked as usable to ensure the entire
balance is available. Since by design the client only has one peer
(us, the LSP) all channels should be marked usable at the same time.
Some logs are there to tell us if this assumption is wrong.

Usable channels are a strict superset of ready channels and are
ultimately what is required for payouts to succeed. LDK node starts
fresh on each request and could reach the point of trying to pay
before the channels are marked as usable. Usable means that the channel
is ready, the peer is connected, and the channel is not negotiating
a shutdown.

Wait for all channels to be marked as usable to ensure the entire
balance is available. Since by design the client only has one peer
(us, the LSP) all channels should be marked usable at the same time.
Some logs are there to tell us if this assumption is wrong.
Extract hardcoded polling intervals (10ms, 50ms, 100ms) and channel
readiness timeout (5000ms) into Duration constants at module level.
This improves consistency and makes tuning easier.

POLL_INTERVAL: 10ms for all event loop polling
CHANNEL_USABLE_TIMEOUT: 10s max wait for channels to become usable
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 771a61ae26

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1181 to +1186
loop {
let channels = node.list_channels();
let total = channels.len();
let usable = channels.iter().filter(|c| c.is_usable).count();

if total > 0 && usable == total {

Choose a reason for hiding this comment

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

P2 Badge Avoid blocking payouts when any channel is unusable

The new wait loop only returns early when usable == total, so if any channel is non-usable (e.g., negotiating shutdown or a disconnected peer) every payment call will sleep until CHANNEL_USABLE_TIMEOUT even if another channel is already usable and has enough outbound capacity. This is a regression from the previous readiness check and can add a consistent 10s delay (or cause upstream timeouts) in pay_lnurl, pay_bolt11, and pay_bolt12_offer whenever a single channel stays non-usable. Consider returning once at least one usable channel exists (or only waiting for channels that can become usable) to avoid blocking payments unnecessarily.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is by design as explained in the description. Dealing with channel closures is a problem for another time

const POLL_INTERVAL: Duration = Duration::from_millis(10);

/// Max time to wait for channels to become usable after sync.
const CHANNEL_USABLE_TIMEOUT: Duration = Duration::from_secs(10);
Copy link
Contributor Author

@amackillop amackillop Jan 21, 2026

Choose a reason for hiding this comment

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

Just had a thought. Tuning these in mdk-checkout is probably easier than doing it here. Should consider passing these in from the consuming library

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.

2 participants