Skip to content
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

Allow coop closing a channel with HTLCs on it via lncli #9491

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

Conversation

ziggie1984
Copy link
Collaborator

@ziggie1984 ziggie1984 commented Feb 9, 2025

This PR adds the possibility to coop close a channel which has still HTLCS on it. Moreover it makes sure we do not exceed the max-fee-rate we specify.


This change is Reviewable

Copy link
Contributor

coderabbitai bot commented Feb 9, 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.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

@ziggie1984 ziggie1984 self-assigned this Feb 9, 2025
@ziggie1984 ziggie1984 marked this pull request as ready for review February 9, 2025 11:54
@ziggie1984 ziggie1984 force-pushed the closechannel-rpc branch 2 times, most recently from 6f66e70 to 1e9cbc8 Compare February 9, 2025 12:33
Copy link
Member

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

I guess this is a followup of #8167?

cmd/commands/commands.go Outdated Show resolved Hide resolved
cmd/commands/commands.go Outdated Show resolved Hide resolved
docs/release-notes/release-notes-0.18.5.md Outdated Show resolved Hide resolved
@ziggie1984 ziggie1984 force-pushed the closechannel-rpc branch 2 times, most recently from 67122b4 to 9e289f7 Compare February 10, 2025 08:05
@ziggie1984 ziggie1984 force-pushed the closechannel-rpc branch 2 times, most recently from 7f47e31 to 83bc0b9 Compare February 12, 2025 15:35
Copy link
Member

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 4 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: 4 of 5 files reviewed, 4 unresolved discussions (waiting on @starius)


itest/lnd_coop_close_with_htlcs_test.go line 263 at r2 (raw file):

	// Wait for Bob to understand that the channel is ready to use.
	ht.AssertChannelInGraph(bob, chanPoint)

use ht.CreateSimpleNetwork instead?


itest/lnd_coop_close_with_htlcs_test.go line 270 at r2 (raw file):

	// Have alice attempt to close the channel but we the expected fee rate
	// exceeds the max fee rate so we fail the closing process.
	closeClient := alice.RPC.CloseChannel(&lnrpc.CloseChannelRequest{

nit: can use ht.CloseChannelAssertErr instead


cmd/commands/commands.go line 1036 at r2 (raw file):

			Name: "block",
			Usage: `block will wait for the channel to be closed,
			"meaning that it will wait for the channel tx to get 1

should be close tx or channel close tx, not sure what channel tx is


rpcserver.go line 2876 at r2 (raw file):

		).FeePerKWeight()

		if maxFee != 0 && maxFee < feeRate {

I'm not sure about this approach, either should it abort the flow, or cap the value. Since right now, the chan closer will always use the maxFee instead when it's set.

Copy link
Collaborator

@starius starius left a comment

Choose a reason for hiding this comment

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

I added several questions.

cmd/commands/commands.go Show resolved Hide resolved
cmd/commands/commands.go Outdated Show resolved Hide resolved
cmd/commands/commands.go Outdated Show resolved Hide resolved
rpcserver.go Outdated Show resolved Hide resolved
@@ -1101,6 +1108,9 @@ func closeChannel(ctx *cli.Context) error {
SatPerVbyte: ctx.Uint64(feeRateFlag),
DeliveryAddress: ctx.String("delivery_addr"),
MaxFeePerVbyte: ctx.Uint64("max_fee_rate"),
// This makes sure that a coop close will also be executed if
// active HTLCs are present on the channel.
NoWait: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

The effect of waiting for HTLCs is documented in rpcserver.go, but not in the schema.

// If true, then the rpc call will not block while it awaits a closing txid.
// Consequently this RPC call will not return a closing txid if this value
// is set.
bool no_wait = 8;
// If the user hasn't specified NoWait, then before we attempt
// to close the channel we ensure there are no active HTLCs on
// the link.
if !in.NoWait && len(channel.ActiveHtlcs()) != 0 {

I propose to add this important detail to the schema as well and maybe rename the flag to coop_with_htlcs or wait_for_htlcs or something to make it clear that it affects the closing transaction (making it coop instead of force close), not only for how long it executes.

Looking at the current name and the description of NoWait I thought originally, that it is a flag similar to --block before I read the code of rpcserver.go.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we cannot rename it because of backwards comp. issues. I think with a proper description we can keep it like this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The description is great! Thanks!

Is it possible to decouple it into two flags? So NoWait only affects RPC behavior (whether or now to wait in RPC for transaction being broadcasted and return its txid) and a new flag would define what to do if there is a pending HTLC (force-close or wait-and-coop-close).

In that case NoWait can be removed, since it can be implemented on the client side similar to --block. The former will wait on gRPC stream for a transaction being broadcast, while the later waits on gRPC stream for confirmation of the transaction.

What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah I think resolving this with 2 distinct flags is the way to go, but I keep it low priority for now.

cmd/commands/commands.go Show resolved Hide resolved
docs/release-notes/release-notes-0.19.0.md Outdated Show resolved Hide resolved
docs/release-notes/release-notes-0.19.0.md Outdated Show resolved Hide resolved
Copy link
Collaborator Author

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

Reviewable status: 1 of 12 files reviewed, 12 unresolved discussions (waiting on @starius and @yyforyongyu)


rpcserver.go line 2876 at r2 (raw file):

Previously, yyforyongyu (Yong) wrote…

I'm not sure about this approach, either should it abort the flow, or cap the value. Since right now, the chan closer will always use the maxFee instead when it's set.

Could you elaborate, we only want to abort if the user specified a feerate which is lower than the estimate for the first intial fee rate ?


cmd/commands/commands.go line 1036 at r2 (raw file):

Previously, yyforyongyu (Yong) wrote…

should be close tx or channel close tx, not sure what channel tx is

👌


itest/lnd_coop_close_with_htlcs_test.go line 270 at r2 (raw file):

Previously, yyforyongyu (Yong) wrote…

nit: can use ht.CloseChannelAssertErr instead

ok but had to change the func signature for that, now I pass in the req instead of the single arguments.

rpcserver.go Outdated Show resolved Hide resolved
Copy link
Member

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

Looks like the CI failed

Reviewed 9 of 11 files at r3.
Reviewable status: 10 of 12 files reviewed, 11 unresolved discussions (waiting on @starius and @ziggie1984)


rpcserver.go line 2876 at r2 (raw file):

Previously, ziggie1984 (ziggieXXX) wrote…

Could you elaborate, we only want to abort if the user specified a feerate which is lower than the estimate for the first intial fee rate ?

yeah nvm, was thinking we should cap it since it could cause the coop negotiation to fail, but maybe it's easier to just abort it here.


rpcserver.go line 2899 at r3 (raw file):

	if in.NoWait {
		rpcsLog.Trace("[closechannel] sending instant update")
		activeHtlcs := len(channel.ActiveHtlcs())

I think this value is already obtained above.

lnrpc/lightning.proto Show resolved Hide resolved
lnwallet/chancloser/chancloser.go Outdated Show resolved Hide resolved
@saubyk saubyk added this to the v0.19.0 milestone Feb 13, 2025
Copy link
Collaborator

@starius starius left a comment

Choose a reason for hiding this comment

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

LGTM! 🌴
The proposal to decouple the flag is for another PR if you decide to implement it.

cmd/commands/commands.go Show resolved Hide resolved
@@ -1101,6 +1108,9 @@ func closeChannel(ctx *cli.Context) error {
SatPerVbyte: ctx.Uint64(feeRateFlag),
DeliveryAddress: ctx.String("delivery_addr"),
MaxFeePerVbyte: ctx.Uint64("max_fee_rate"),
// This makes sure that a coop close will also be executed if
// active HTLCs are present on the channel.
NoWait: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

The description is great! Thanks!

Is it possible to decouple it into two flags? So NoWait only affects RPC behavior (whether or now to wait in RPC for transaction being broadcasted and return its txid) and a new flag would define what to do if there is a pending HTLC (force-close or wait-and-coop-close).

In that case NoWait can be removed, since it can be implemented on the client side similar to --block. The former will wait on gRPC stream for a transaction being broadcast, while the later waits on gRPC stream for confirmation of the transaction.

What do you think?

Copy link
Collaborator Author

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

Reviewable status: 6 of 12 files reviewed, 11 unresolved discussions (waiting on @starius and @yyforyongyu)


rpcserver.go line 2899 at r3 (raw file):

Previously, yyforyongyu (Yong) wrote…

I think this value is already obtained above.

Done.

cmd/commands/commands.go Show resolved Hide resolved
For the lncli cmd we now always initiate the coop close even if
there are active HTLCs on the channel. In case HTLCs are on the
channel and the coop close is initiated LND handles the closing
flow in the background and the lncli cmd will block until the
transaction is broadcasted to the mempool. In the background LND
disallows any new HTLCs and waits until all HTLCs are resolved
before kicking of the negotiation process.
Moreover if active HTLCs are present and the no_wait param is not
set the error msg is now highlightning it so the user can react
accordingly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

4 participants