Skip to content

Add --wait to open-channel in the CLI - #318

Open
karliatto wants to merge 1 commit into
lightningdevkit:mainfrom
karliatto:feat/ldk-server-cli-add-open_channel_wait
Open

karliatto wants to merge 1 commit into
lightningdevkit:mainfrom
karliatto:feat/ldk-server-cli-add-open_channel_wait

Conversation

@karliatto

@karliatto karliatto commented Oct 22, 2026 •

Copy link
Copy Markdown

open-channel returned as soon as the open was initiated, so scripts had to poll list-channels to learn whether the counterparty accepted or rejected the channel.

With --wait, the CLI subscribes to the event stream before calling open_channel, since the stream is live-only, and waits for a ChannelStateChanged event for the returned user_channel_id. Pending (or Ready, if Pending was missed) counts as success and prints the channel_id and funding_txo. OpenFailed or Closed counts as failure and prints the reason from the server. It does not wait for the funding transaction to confirm.

--wait-timeout <SECS> bounds the wait. On timeout the CLI prints the current entry for the channel from list_channels, if there is one. Exit codes are 0 for pending, 1 for a request or event stream error, 2 for a failed open and 3 for a timeout, matching pay --wait.

For example when opening a channel for 100.000 sats when 200.000 is the minimum required by the counterpart node the command open-channel will finish and just replied:

{
  "user_channel_id": "<user-channel-id>"
}

But if the user looks for the channel using list-channels the user cannot see anything about that channel. In order to know what happened the user has to actually look at the logs of the server. Or there might be other way I did not find.

With the new --wait when the same situation as before happens, it gives the user information about the failed channel open and the reason.

Channel open initiated: <user-channel-id> (waiting for the counterparty)
Channel open <user-channel-id> failed: Channel closed because counterparty force-closed with message: chan size of 0.00100000 BTC is below min chan size of 0.00200000 BTC

And when the opening is successful it gives:

Channel open initiated: <user-channel-id> (waiting for the counterparty)
{
  "channel_id": "<channel-id>",
  "funding_txo": "<funding-tx-id>",
  "user_channel_id": "<user-channel-id>"
}

`open-channel` returned as soon as the open was initiated, so scripts had to poll list-channels to learn whether the counterparty accepted or rejected the channel.

With `--wait`, the CLI subscribes to the event stream before calling
open_channel, since the stream is live-only, and waits for a
ChannelStateChanged event for the returned user_channel_id. Pending
(or Ready, if Pending was missed) counts as success and prints the
channel_id and funding_txo. OpenFailed or Closed counts as failure and
prints the reason from the server. It does not wait for the funding
transaction to confirm.

`--wait-timeout <SECS>` bounds the wait. On timeout the CLI prints
the current entry for the channel from list_channels, if there is one.
Exit codes are 0 for pending, 1 for a request or event stream error, 2
for a failed open and 3 for a timeout, matching `pay --wait`.

AI tools were used to help write this change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ldk-reviews-bot

ldk-reviews-bot commented Oct 22, 2026 •

Copy link
Copy Markdown

I've assigned @benthecarman 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.

@benthecarman benthecarman 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.

The wait logic here is mostly the same as pay_wait.rs just copied. Could we pull the common parts into a shared module before this lands? pay --wait and open-channel --wait are the first two, and close-channel or splice will likely want --wait too. I'd rather the next one doesn't become a third copy.

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