-
Notifications
You must be signed in to change notification settings - Fork 0
Wait for all channels to be usable before payout #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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
There was a problem hiding this 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".
| 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 👍 / 👎.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
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.