lightningnetwork / lnd

Lightning Network Daemon ⚡️
MIT License
7.65k stars 2.07k forks source link

bumpforceclosefee rpc #8843

Closed ziggie1984 closed 1 month ago

ziggie1984 commented 3 months ago

Fixes https://github.com/lightningnetwork/lnd/issues/8837

For reviewers please also focus on the following questions I included into the code starting with

// Question: 

Should we add an Integration Test for this new RPC call? => Yes I will

Thank you in advance 🙏

EDIT: Depends on https://github.com/lightningnetwork/lnd/pull/8946

coderabbitai[bot] commented 3 months ago

[!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.

Walkthrough

The recent update enhances the fee-bumping mechanism for force close operations in Lightning Network channels, particularly when no HTLCs are involved. It introduces the BumpForceCloseFee functionality, refines anchor handling, and ensures reliable fee adjustments for unconfirmed anchor channels. Users can now effectively increase force close fees, resolving previous limitations and improving overall usability.

Changes

Files/Directories Change Summary
cmd/lncli/walletrpc_active.go Refactored bump force close fee logic, removed deprecated flags, and clarified budget usage for force closes without HTLCs.
contractcourt/channel_arbitrator.go Modified anchor sweeping logic to register anchor outputs even when no HTLCs are present, enhancing fee adjustment capabilities.
docs/release-notes/release-notes-0.18.1.md Documented the fix for bumping anchor channel fees when no HTLCs are present and added the new BumpForceCloseFee walletrpc endpoint.
docs/release-notes/release-notes-0.18.3.md Detailed functional improvements and bug fixes related to the BumpForceCloseFee functionality.
lnrpc/walletrpc/config_active.go Introduced a new field, ChanStateDB, in the Config struct for better state management in wallet RPC.
lnrpc/walletrpc/walletkit.pb.json.go Added a JSON callback function for handling BumpForceCloseFee requests in the WalletKit service.
lnrpc/walletrpc/walletkit.proto Introduced the BumpForceCloseFee RPC method for adjusting fees on anchor channel closures.
lnrpc/walletrpc/walletkit_server.go Expanded the BumpForceCloseFee method to accommodate unconfirmed anchor channels and improve fee adjustment efficiency.
itest/lnd_sweep_test.go Added tests for the new fee bumping functionality to validate behavior when handling force close transactions without HTLCs.
lntest/rpc/wallet_kit.go Implemented a new method for invoking the BumpForceCloseFee RPC call within the HarnessRPC struct, enhancing testing capabilities.

Assessment against linked issues

Objective (Issue #8837) Addressed Explanation
Register the anchor with the sweeper for accurate data
Allow fee bumping without HTLCs
Move logic from lncli to rpc

Possibly related issues

Poem

In the code's deep lightning grasp,
Anchors steady, no longer clasp.
Fees now bump, in clean euphoria,
Channels close, sans-HTLC gloria.
Rabbit smiles, in bits and bytes,
Onward flows, the network's lights. ✨


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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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 generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@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 as 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 resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
ziggie1984 commented 3 months ago

@coderabbitai review

coderabbitai[bot] commented 3 months ago
Actions performed Review triggered. > Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
coderabbitai[bot] commented 3 months ago

[!NOTE] Currently processing new changes in this PR. This may take a few minutes, please wait...

Commits Files that changed from the base of the PR and between 68494fd91d69ccdd3e72a5eaca593b6e42babe23 and 219764f418dac9f25fd0f64a50559d5c4fa652cd.
Files ignored due to path filters (5) * `lnrpc/walletrpc/walletkit.pb.go` is excluded by `!**/*.pb.go`, `!**/*.pb.go` * `lnrpc/walletrpc/walletkit.pb.gw.go` is excluded by `!**/*.pb.gw.go`, `!**/*.pb.gw.go` * `lnrpc/walletrpc/walletkit.swagger.json` is excluded by `!**/*.json` * `lnrpc/walletrpc/walletkit.yaml` is excluded by `!**/*.yaml` * `lnrpc/walletrpc/walletkit_grpc.pb.go` is excluded by `!**/*.pb.go`, `!**/*.pb.go`
Files selected for processing (9) * cmd/lncli/walletrpc_active.go (1 hunks) * contractcourt/channel_arbitrator.go (1 hunks) * docs/release-notes/release-notes-0.18.1.md (1 hunks) * lnrpc/walletrpc/config_active.go (2 hunks) * lnrpc/walletrpc/walletkit.pb.json.go (1 hunks) * lnrpc/walletrpc/walletkit.proto (1 hunks) * lnrpc/walletrpc/walletkit_server.go (3 hunks) * lnwallet/wallet.go (1 hunks) * subrpcserver_config.go (1 hunks)
 _________________________________________________________________________________________________________________
< Iterate the schedule with the code. Use experience you gain as you implement to refine the project time scales. >
 -----------------------------------------------------------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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 generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@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 as 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 resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
ziggie1984 commented 3 months ago

We definitely need to prioritize the flattening of the mulit_hop tests, fixing those takes super long because they include a lot of different special case for different channel types ...

ziggie1984 commented 3 months ago

waiting for https://github.com/lightningnetwork/lnd/pull/8717, so that itests are not updated twice.

yyforyongyu commented 2 months ago

I think this should be moved to 0.19 since we are adding an RPC?

saubyk commented 2 months ago

I think this should be moved to 0.19 since we are adding an RPC?

Need to understand this better. I thought rpc was already added in 0.18 but not doing its function of bumping up the fee

ziggie1984 commented 2 months ago

This PR needs a final decision before I will proceed fixing the itests, basically the following:

Currently when creating the Force-Close transaction we will not account for the parent fee rate immediately but rely on the createRBFCompliantTx which will at least create a transaction which meets the current mempool conditions. This has in my view several downsides, that's why I think the new approach by accounting the feerate is better:

When force-closing a channel the conf target will never select the right fee-rate which was essentially required but will only reach this feerate several blocks down the road which can be a long time until the desired feerate is reached in case the commitment transaction (parent) is very big.

Moreover when trying to bump the feerate of a closing transaction with this newly introduced RPC we will not be able to specify the exact feerate and therefore this might be a bad user experience.

Based on the decision above when we account for the parent feerate we need to change some itests which are now failing, but if we decide against it those itests remain unchanged. That's why I am waiting for your feedback before proceeding.

Maybe @morehouse and @yyforyongyu and comment on this matter ?

Thank you in advance for your time.

yyforyongyu commented 2 months ago

Moreover when trying to bump the feerate of a closing transaction with this newly introduced RPC we will not be able to specify the exact feerate and therefore this might be a bad user experience.

With the new sweeper I don't think it makes sense to specify a feerate anymore. Instead, users should seek to specify a budget, which is more accurate IMO, as in the end you wanna control the fees paid. Previously we achieved so by specifying a feerate, but it was not precise as it's mostly estimation.

ziggie1984 commented 2 months ago

I think this should be moved to 0.19 since we are adding an RPC?

Although its a new RPC, the logic was mostly copied from the lncli side, and it fixes the bug of bumping force closes with no htlcs, so I think getting this in lnd 18.3 is a good choice :)

ziggie1984 commented 2 months ago

This PR needs a final decision before I will proceed fixing the itests, basically the following:

Currently when creating the Force-Close transaction we will not account for the parent fee rate immediately but rely on the createRBFCompliantTx which will at least create a transaction which meets the current mempool conditions. This has in my view several downsides, that's why I think the new approach by accounting the feerate is better:

When force-closing a channel the conf target will never select the right fee-rate which was essentially required but will only reach this feerate several blocks down the road which can be a long time until the desired feerate is reached in case the commitment transaction (parent) is very big.

Moreover when trying to bump the feerate of a closing transaction with this newly introduced RPC we will not be able to specify the exact feerate and therefore this might be a bad user experience.

Based on the decision above when we account for the parent feerate we need to change some itests which are now failing, but if we decide against it those itests remain unchanged. That's why I am waiting for your feedback before proceeding.

@ProofOfKeags this is the main question I have not sure if you saw it ?

ziggie1984 commented 2 months ago

Ok will split into 2 PR's.

Regarding the parent fee rate I am still undecided especially considering the above mentioned flow.

When force-closing a channel the conf target will never select the right fee-rate which was essentially required but will only reach this feerate several blocks down the road which can be a long time until the desired feerate is reached in case the commitment transaction (parent) is very big.

I will for now remove my addition of the parent weight consideration, so we can move on and merge this PR, however we might run into unpleasant behaviour when our commitment transaction is always broadcasted underestimating the fees.

ziggie1984 commented 2 months ago

Addressed all the comments, splitted the PR into two, first 3 commits of this PR belong to the other PR but we need this change so that the new itest will pass. Otherwise removed all the parent fee rate considerations which had the positive side effect of not breaking all the itests 😄.

ziggie1984 commented 2 months ago

@coderabbitai review

coderabbitai[bot] commented 2 months ago
Actions performed Review triggered. > Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
lightninglabs-deploy commented 1 month ago

@yyforyongyu: review reminder @ziggie1984, remember to re-request review from reviewers when ready

guggero commented 1 month ago

0.18.3 is on a side branch, there is no merge freeze in effect.