Skip to content

improve CloseChannel docs #9958

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ZZiigguurraatt
Copy link

@ZZiigguurraatt ZZiigguurraatt commented Jun 17, 2025

This is a docs change only to improve the clarity of how to use CloseChannel .

Fixes #9771
Fixes #9837

Copy link
Contributor

coderabbitai bot commented Jun 17, 2025

Important

Review skipped

Auto reviews are limited to specific labels.

🏷️ Labels to auto review (1)
  • llm-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ZZiigguurraatt
Copy link
Author

Do I also need to update lightning.swagger.json to properly complete this PR? It is unclear to me why we seem to have duplicate text in there. What is lightning.swagger.json for?

@guggero
Copy link
Collaborator

guggero commented Jun 17, 2025

Do I also need to update lightning.swagger.json to properly complete this PR? It is unclear to me why we seem to have duplicate text in there. What is lightning.swagger.json for?

Yes, you need to generate the stubs with make rpc.

@ZZiigguurraatt ZZiigguurraatt force-pushed the closechannel_docs branch 2 times, most recently from 6380421 to 89cd7f2 Compare June 19, 2025 15:20
@ZZiigguurraatt
Copy link
Author

@ziggie1984 please review.

Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

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

Nice addition!

// If `no_wait=true` (`wait=false`) when a coop close is attempted, then the
// rpc call will not initially block while it awaits a closing txid to be
// broadcasted to the mempool. Instead, a coop close will be initiated even
// if there are HTLCs active in flight on the channel and a `close_instant`
Copy link
Collaborator

Choose a reason for hiding this comment

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

and a close_instant msg will sent over the stream ...

Copy link
Author

Choose a reason for hiding this comment

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

please check my update

Comment on lines 2188 to 2190
// resolved before that can happen. If a coop close is attempted with no in
// flight HTLCs on the channel OR a force close is attempted, the `no_wait`
// option is ignored. In summary, the `no_wait` option controls if the user
Copy link
Collaborator

Choose a reason for hiding this comment

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

If a coop close is attempted with no inflight HTLCs on the channel the no_wait=true parameter has still the effect that the stream sends the close_instant msg immediately however that should not make much of a difference because LND should broadcast the closing tx without much time delay and therefore should send the close_pending update right after.

Copy link
Author

Choose a reason for hiding this comment

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

please check my update on this. I'm not sure if I got it right about force closing.

// wait for the in flight HTLCs to be resolved and then start the coop
// closing process. Note: `lncli closechannel` always sets `no_wait=true`
// and its `--block` option controls if `lncli` should wait for a
// `close_pending` update and a `chan_close` update before returning or if
Copy link
Collaborator

Choose a reason for hiding this comment

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

should wait for the chan_close update (we still on the lncli side wait for the close_pending, which signals when the tx is broadcasted to the mempool)

Copy link
Author

Choose a reason for hiding this comment

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

please check my update

Comment on lines 2186 to 2189
// will fail and abort the closing process because it can't wait for a
// closing TXID to be broadcast to the mempool because it needs to
// immediately tell the user that there are in flight HTLCs that need to be
// resolved before that can happen. If a coop close is attempted with no in
Copy link
Collaborator

Choose a reason for hiding this comment

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

then the rpc call will fail and abort the closing process because the caller wants to wait for the closing tx being broadcasted to the mempool but because of the inflight HTLCs this can be very long therefore LND will not allow initiating the coop-close with this setting.

Copy link
Collaborator

Choose a reason for hiding this comment

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

it is not that we can't we just decided to not do so because of the above reasons, does it make sense ?

Copy link
Author

Choose a reason for hiding this comment

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

no, that is very convoluted.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok I am trying to say, that we decided to not close the channel in that case because we do not want the user to wait until the HTLCs resolves because he signaled via "wait=true" he wants to wait for the closing information. But we definitely could, like technically this is not a problem, it is just we decided not to, to make sure the user does not have to wait forever

Copy link
Author

Choose a reason for hiding this comment

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

so how exactly would you re-write the sentence?

@ZZiigguurraatt ZZiigguurraatt marked this pull request as ready for review June 24, 2025 15:16
@ZZiigguurraatt
Copy link
Author

taking out of draft as I'd like to see some feedback from others. @saubyk , do you have any feedback?

Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

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

LGTM

@ziggie1984 ziggie1984 requested a review from saubyk June 24, 2025 17:10
// initiated even if HTLCs are active on the channel. The channel will wait
// until all HTLCs are resolved and then start the coop closing process. The
// channel will be disabled in the meantime and will disallow any new HTLCs.
// When force closing, `no_wait` has no effect.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is an extremely verbose description and it doesn't seem to me that this is right place to get into the detailed scenarios here. How and where would this content would be made available to the user?

My first reaction is that it's not easy to follow and digest. And we may need to supplement the documentation somewhere else, rather than here.

@ziggie1984
Copy link
Collaborator

I think we should deprecate this field in the first place and default to no_wait=true if everybody agrees. I don't see a usecase for wait=true/no_wait=false. No_Wait=true does the same thing even better

@ZZiigguurraatt
Copy link
Author

I think we should deprecate this field in the first place and default to no_wait=true if everybody agrees. I don't see a usecase for wait=true/no_wait=false. No_Wait=true does the same thing even better

That is not a bad idea.

@ZZiigguurraatt
Copy link
Author

What about breaking b0c0cde out into a separate PR so that can at least be added and then we can get more feedback from the team on #9958 (comment) ?

@@ -878,7 +879,7 @@
},
{
"name": "no_wait",
"description": "If true, then the rpc call will not block while it awaits a closing txid\nto be broadcasted to the mempool. To obtain the closing tx one has to\nlisten to the stream for the particular updates. Moreover if a coop close\nis specified and this flag is set to true the coop closing flow will be\ninitiated even if HTLCs are active on the channel. The channel will wait\nuntil all HTLCs are resolved and then start the coop closing process. The\nchannel will be disabled in the meantime and will disallow any new HTLCs.",
"description": "When force closing, `no_wait` has no effect.\nIf `no_wait=true` (`wait=false`) when a coop close is attempted, then the\nrpc call will not initially block while it awaits a closing txid to be\nbroadcasted to the mempool. Instead, a coop close will be initiated even\nif there are HTLCs active inflight on the channel and a `close_instant`\nmessage will be immediately returned over the stream which contains\n`num_pending_htlcs` if there are inflight HTLCs that still need to be\nresolved before a coop close can be initiated. After the `close_instant`\nis received, then the channel will be disabled to disallow any new HTLCs\nand the rpc will block while it waits for the exsting inflight HTLCs to\nbe resolved and then start the coop closing process. To obtain the\nclosing TXID one has to listen to the stream for a `close_pending`\nupdate. If the client disconnects the stream before this is received, LND\nwill continue to wait for the inflight HTLCs to be resolved and then\nstart the coop closing process. Note: `lncli closechannel` always sets\n`no_wait=true` and its `--block` option controls if `lncli` should wait\nfor a `chan_close` update (indicating the channel close has been mined)\nbefore returning or if it should disconnect the stream and return\nimmediately after `close_pending` is received when the TX is broadcast to\nthe mempool. If `no_wait=false` (`wait=true`) when a coop close is\nattempted and there are inflight HTLCs on the channel, then the rpc call\nwill fail and abort the closing process because it can't wait for a\nclosing TXID to be broadcast to the mempool because it needs to\nimmediately tell the user that there are inflight HTLCs that need to be\nresolved before that can happen. If a coop close is attempted with no\ninflight HTLCs on the channel with `no_wait=true`, it will still result\nin an immediate `close_instant` message being returned on the stream but\n`num_pending_htlcs` will be 0 and *nearly* immediately after that the\n`close_pending` message will be returned on the stream. If a coop close\nis attempted with no inflight HTLCs on the channel with `no_wait=false`,\nthe `close_instant` message will be skipped and *nearly* immediately the\n`close_pending` message will be returned on the stream. In summary, the\n`no_wait` option controls if the user is willing to wait for the rpc call\nto send an initial immediate response message back indicating if there\nare inflight HTLCs on the channel and a coop close is attempted. It then\nindirectly controls if the rpc call later waits for inflight HTLCs to be\nresolved before attempting a coop close or if it will instantly fail.\nThe default value is false.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please consider removing the non-existent wait parameter from the document, as I believe it makes the documentation confusing. I actually went looking for the wait param in the API after reading this. 😄

Here's a suggested text to reduce the verbosity and improved readability:

The no_wait parameter governs the RPC call's behavior during a cooperative channel close but has no effect on a force close.

Setting no_wait=true prevents the RPC call from blocking, even if the channel has active HTLCs. Instead, it immediately returns a close_instant message indicating the number of pending HTLCs, disables the channel to block new payments, and then waits for the existing HTLCs to be resolved before initiating the cooperative close. To obtain the closing transaction ID, the client must listen to the stream for a close_pending update. The lncli closechannel command always uses no_wait=true, and its --block option separately controls whether it waits for the closing transaction to be broadcast (close_pending) or fully mined (chan_close).

Conversely, if no_wait=false and active HTLCs exist, the RPC call will fail immediately, as it cannot simultaneously wait for HTLC resolution and inform the user of their presence. When no HTLCs are active, setting no_wait=true results in a close_instant message (with zero pending HTLCs) followed quickly by the close_pending update, whereas no_wait=false skips the close_instant message and proceeds directly to the close_pending update.

Copy link
Member

Choose a reason for hiding this comment

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

agree it's confusing - I went to look it up too😅

@yyforyongyu
Copy link
Member

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This PR improves the documentation for CloseChannel, especially around the new RBF cooperative close feature and the no_wait parameter. The changes are spread across several files, including the proto definitions and generated code.

I have one suggestion to improve the readability of the documentation for the no_wait parameter in lnrpc/lightning.proto. The new text is very detailed but also very dense, which can make it hard to understand the complex behavior. I've proposed a restructured version that should be easier to parse.

Comment on lines +2166 to +2203
// When force closing, `no_wait` has no effect.
// If `no_wait=true` (`wait=false`) when a coop close is attempted, then the
// rpc call will not initially block while it awaits a closing txid to be
// broadcasted to the mempool. Instead, a coop close will be initiated even
// if there are HTLCs active inflight on the channel and a `close_instant`
// message will be immediately returned over the stream which contains
// `num_pending_htlcs` if there are inflight HTLCs that still need to be
// resolved before a coop close can be initiated. After the `close_instant`
// is received, then the channel will be disabled to disallow any new HTLCs
// and the rpc will block while it waits for the exsting inflight HTLCs to
// be resolved and then start the coop closing process. To obtain the
// closing TXID one has to listen to the stream for a `close_pending`
// update. If the client disconnects the stream before this is received, LND
// will continue to wait for the inflight HTLCs to be resolved and then
// start the coop closing process. Note: `lncli closechannel` always sets
// `no_wait=true` and its `--block` option controls if `lncli` should wait
// for a `chan_close` update (indicating the channel close has been mined)
// before returning or if it should disconnect the stream and return
// immediately after `close_pending` is received when the TX is broadcast to
// the mempool. If `no_wait=false` (`wait=true`) when a coop close is
// attempted and there are inflight HTLCs on the channel, then the rpc call
// will fail and abort the closing process because it can't wait for a
// closing TXID to be broadcast to the mempool because it needs to
// immediately tell the user that there are inflight HTLCs that need to be
// resolved before that can happen. If a coop close is attempted with no
// inflight HTLCs on the channel with `no_wait=true`, it will still result
// in an immediate `close_instant` message being returned on the stream but
// `num_pending_htlcs` will be 0 and *nearly* immediately after that the
// `close_pending` message will be returned on the stream. If a coop close
// is attempted with no inflight HTLCs on the channel with `no_wait=false`,
// the `close_instant` message will be skipped and *nearly* immediately the
// `close_pending` message will be returned on the stream. In summary, the
// `no_wait` option controls if the user is willing to wait for the rpc call
// to send an initial immediate response message back indicating if there
// are inflight HTLCs on the channel and a coop close is attempted. It then
// indirectly controls if the rpc call later waits for inflight HTLCs to be
// resolved before attempting a coop close or if it will instantly fail.
// The default value is false.

Choose a reason for hiding this comment

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

medium

This documentation block is very dense and hard to read. It describes complex behavior, so improving its structure would greatly enhance clarity for developers.

I've restructured it with paragraphs and bullet points to explain the different scenarios for no_wait. I also fixed a typo (exsting -> existing).

    // When force closing, `no_wait` has no effect.
    //
    // For cooperative closures, this option controls whether the client is willing
    // to wait for an initial response from the server about inflight HTLCs. This
    // indirectly determines if the RPC call will wait for HTLCs to be resolved or
    // fail immediately.
    //
    // The behavior is as follows:
    //
    // If `no_wait=true` (`wait=false`):
    // A `close_instant` message is immediately returned, indicating the number of
    // pending HTLCs. The channel is then disabled, and the RPC call blocks until
    // all existing inflight HTLCs are resolved before proceeding with the
    // cooperative close. The final closing transaction ID is sent in a
    // `close_pending` update. If the client disconnects, LND will continue the
    // process in the background.
    //
    // If `no_wait=false` (`wait=true`):
    // If there are any inflight HTLCs, the RPC call will fail immediately, as it
    // cannot wait for a closing transaction while HTLCs need resolution.
    //
    // Behavior with no inflight HTLCs:
    // - `no_wait=true`: An immediate `close_instant` message is returned with
    //   `num_pending_htlcs=0`, followed shortly by a `close_pending` message.
    // - `no_wait=false`: The `close_instant` message is skipped, and a
    //   `close_pending` message is returned shortly after.
    //
    // Note on `lncli`: `lncli closechannel` always sets `no_wait=true`. Its
    // `--block` option controls whether `lncli` waits for the channel close to be
    // mined (`chan_close` update) or returns after the transaction is broadcast
    // (`close_pending` update).
    //
    // The default value is false.

Copy link
Member

Choose a reason for hiding this comment

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

@gemini-code-assist I think the NoWait is a bit confusing, what would be a good alternative for it? sth like FailOnInflightHtlcs or AutoResolveHtlcs?

Choose a reason for hiding this comment

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

That's an excellent question, yyforyongyu! The name no_wait for a boolean flag can indeed be confusing, as it's a negative assertion. Generally, it's good practice to name boolean flags positively, so true means the action described by the name will occur.

Let's consider your suggestions:

  • FailOnInflightHtlcs: If this flag were true by default, it would align with the current no_wait=false behavior (failing if HTLCs are present). However, if we want to keep the current default value (false) and simply rename the flag, this would imply FailOnInflightHtlcs: false means it won't fail, which is still a double negative.

  • AutoResolveHtlcs: This name is much clearer. If AutoResolveHtlcs is true, it means the system will automatically resolve inflight HTLCs before closing (which corresponds to the current no_wait=true behavior). If AutoResolveHtlcs is false (which is the current default for no_wait), it means it won't auto-resolve, and thus will fail if HTLCs are present. This aligns perfectly with the existing default value and provides a positive, descriptive name.

Therefore, AutoResolveHtlcs seems like a strong candidate for a clearer name, as it directly describes the behavior when the flag is set to true and maintains consistency with the current default false value of no_wait.

It's important to note that renaming a field in a .proto file (like no_wait to auto_resolve_htlcs) would be a breaking change for existing API clients, as the field name changes in the generated code and the wire format. This would typically require careful versioning or migration strategies if this RPC is already in use by external consumers.

Copy link
Member

Choose a reason for hiding this comment

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

@gemini-code-assist can you come up with a better name pls?

Choose a reason for hiding this comment

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

That's a great follow-up question, yyforyongyu! It's important to find the most intuitive name for such a critical parameter.

Building on our previous discussion about positive boolean naming, let's consider another strong candidate:

  • AllowPendingHtlcs:
    • If AllowPendingHtlcs is true (corresponding to no_wait=true), it means the cooperative close process is allowed to begin even if there are HTLCs currently pending on the channel. The RPC call would return immediately with a close_instant message, and the HTLCs would be resolved asynchronously via the stream.
    • If AllowPendingHtlcs is false (corresponding to no_wait=false, the current default), it means the RPC call will not allow pending HTLCs and will fail immediately if any are present.

Comparing AllowPendingHtlcs with AutoResolveHtlcs:

  • AutoResolveHtlcs emphasizes the action taken by the system (automatically resolving HTLCs in the background).
  • AllowPendingHtlcs emphasizes the condition under which the RPC proceeds (permitting pending HTLCs at the start of the close attempt).

Both are good, positive names that clearly describe the behavior when set to true. The choice between them might come down to whether the primary emphasis should be on the system's action (AutoResolveHtlcs) or the state it tolerates (AllowPendingHtlcs). Given the original description's focus on initiating a close "even if there are HTLCs active inflight," AllowPendingHtlcs might slightly better capture that specific nuance.

As mentioned before, any renaming of this field in the .proto file would constitute a breaking change for existing API clients, requiring careful consideration for versioning and migration.

@yyforyongyu
Copy link
Member

I think we should take gemini's suggestion into consideration and update the docs a bit. We may also create a followup PR to deprecate the flag NoWait, and use a new one with a better name as suggested by gemini.

@lightninglabs-deploy
Copy link

@ZZiigguurraatt, remember to re-request review from reviewers when ready

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.

[bug]: CloseChannel: no_wait=True still waiting [bug]: CloseChannel documentation makes no mention of the new RBF cooperative close protocol
6 participants