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

Expose closing tx in waiting_close_channels #8426

Merged
merged 4 commits into from Jan 30, 2024

Conversation

JssDWt
Copy link
Contributor

@JssDWt JssDWt commented Jan 25, 2024

Change Description

This PR exposes the raw closing tx of the waiting_close_channels in the PendingChannels response.

There are cases when a local force close transaction of a static remote key channel drops out of the mempool due to insufficient fees. Currently, the only way to get hold of this transaction to rebroadcast it is to restart LND. However, restarting LND is infeasible for large nodes that want to maintain their uptime. Even if restarting LND is an option, if the tx has insufficient fee, the only way to capture it currently is by scavenging the logs. By adding the raw tx to waiting_close_channels, unconfirmed closes can be pushed through a tx accelerator for example to ensure timely confirmation.

Steps to Test

A pending cooperate close and local force close in the waiting close state includes the raw tx hex of the closing transaction.

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

Summary by CodeRabbit

  • New Features
    • Added MinConf parameter to the WalletBalance RPC call for enhanced balance querying.
    • PendingChannels RPC call now optionally returns the raw hex of the closing transaction for channels in the waiting close state.
    • Documented all available lncli commands for better user guidance.
  • Documentation
    • Updated release notes and added Jesse de Wit to the list of contributors.
  • Refactor
    • Improved internal handling of closing transactions in pending channels for more accurate and informative responses.

Copy link

coderabbitai bot commented Jan 25, 2024

Important

Auto Review Skipped

Auto reviews are limited to the following labels: llm-review. Please add one of these labels to enable auto reviews.

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.

Walkthrough

The latest update introduces enhancements and documentation improvements to the system. Key features include the addition of MinConf to the WalletBalance RPC call for more detailed balance queries, and the PendingChannels functionality now provides the raw hex of closing transactions for channels in the waiting close state. Comprehensive documentation for lncli commands has been added, alongside code adjustments to support these features. Jesse de Wit joins the contributors, marking a collaborative effort in this release.

Changes

Files Change Summary
docs/release-notes/release-notes-0.18.0.md - Added MinConf to WalletBalance
- PendingChannels enhanced
- Documented lncli commands
- Added new contributor
itest/.../lnd_channel_force_close_test.go - Imported encoding/hex
- Updated testCommitmentTransactionDeadline function
lnrpc/lightning.proto - Added include_tx to PendingChannelsRequest
- New closing_tx_hex field in PendingChannelsResponse
lntest/rpc/lnd.go, rpcserver.go - Enhanced PendingChannels method and fetchWaitingCloseChannels function to support including transaction details

🐇✨
In the code's woven meadow, under the moon's soft glow,
New features hop and settle, where digital rivers flow.
With each commit and merge, our garden does grow,
A celebration in code, as onward we go.
🌱🚀

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@JssDWt JssDWt force-pushed the expose-closing-tx branch 2 times, most recently from 8c340e5 to e19923c Compare January 25, 2024 12:11
Copy link
Collaborator

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

Very nice addition! My main comment is to add a param in PendingChannelsRequest and optionally populate this field when requested since it's a relatively large field. In addition, we should update our itest to validate ClosingTxHex is created as expected - maybe we could just add a few lines in one of our tests. Maybe here

ht.AssertChannelWaitingClose(alice, chanPoint)

or here

waitingClose := ht.AssertChannelWaitingClose(alice, aliceChanPoint1)

lnrpc/lightning.proto Outdated Show resolved Hide resolved
rpcserver.go Show resolved Hide resolved
@yyforyongyu yyforyongyu added rpc Related to the RPC interface enhancement Improvements to existing features / behaviour labels Jan 25, 2024
@JssDWt JssDWt force-pushed the expose-closing-tx branch 2 times, most recently from 76198f4 to 5662b3e Compare January 25, 2024 18:57
@JssDWt
Copy link
Contributor Author

JssDWt commented Jan 25, 2024

In addition, we should update our itest to validate ClosingTxHex is created as expected - maybe we could just add a few lines in one of our tests.

Thanks for the pointer to the itest, that's very helpful.
I added some lines of code in the first itest to check whether the tx is valid and matches the closing_txid. Let me know what you think.

I made the IncludeTx boolean true for all testcases using the PendingChannels rpc. I didn't think it could hurt. The alternative is to let every test pass a boolean or a request to that PendingChannels call instead. One has code changes in quite a few places, and the other 'affects' all the tests in those places. Let me know which one you prefer.

Copy link
Collaborator

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

One naming suggestion, then it's LGTM ⚡

lnrpc/lightning.proto Outdated Show resolved Hide resolved
itest/lnd_channel_force_close_test.go Show resolved Hide resolved
lntest/rpc/lnd.go Show resolved Hide resolved
@yyforyongyu yyforyongyu added this to the v0.18.0 milestone Jan 25, 2024
@yyforyongyu
Copy link
Collaborator

@coderabbitai review

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b9a8e2f and 5662b3e.
Files ignored due to path filters (3)
  • lnrpc/lightning.pb.go is excluded by: !**/*.pb.go
  • lnrpc/lightning.pb.gw.go is excluded by: !**/*.pb.gw.go
  • lnrpc/lightning.swagger.json is excluded by: !**/*.json
Files selected for processing (5)
  • docs/release-notes/release-notes-0.18.0.md (2 hunks)
  • itest/lnd_channel_force_close_test.go (2 hunks)
  • lnrpc/lightning.proto (2 hunks)
  • lntest/rpc/lnd.go (1 hunks)
  • rpcserver.go (5 hunks)
Additional comments: 11
docs/release-notes/release-notes-0.18.0.md (2)
  • 182-184: The addition of the raw hex of the closing transaction in waiting_close_channels is correctly documented under the RPC Updates section. This change enhances the PendingChannels functionality, aligning with the PR's objective to improve channel closure processes.
  • 282-282: Adding Jesse de Wit to the contributors list is appropriate and acknowledges their contributions to this release.
lntest/rpc/lnd.go (1)
  • 134-136: The modification to include the IncludeTx: true parameter in the PendingChannelsRequest struct correctly implements the new functionality introduced by the PR. This change ensures that the raw closing transaction hex is included in the PendingChannels response when requested.
itest/lnd_channel_force_close_test.go (2)
  • 5-5: The addition of the encoding/hex package is appropriate for decoding hex strings, which is necessary for the new functionality being tested.
  • 145-162: The validation of the closing transaction hex in the testCommitmentTransactionDeadline function is correctly implemented. It checks for the presence of the ClosingTxHex, decodes it, deserializes the transaction, and compares the transaction ID to the expected value. This ensures that the ClosingTxHex provided in the PendingChannelsResponse matches the actual closing transaction.
lnrpc/lightning.proto (2)
  • 2639-2641: The addition of the include_tx boolean field to PendingChannelsRequest allows callers to request the inclusion of the raw closing transaction hex in the response. This is a useful feature for nodes to access unconfirmed close transactions directly.
  • 2739-2742: The addition of the closing_tx_hex string field to WaitingCloseChannel within PendingChannelsResponse enables the inclusion of the raw closing transaction hex when include_tx is true in the request. This enhancement facilitates the use of transaction accelerators and improves the reliability of channel closure processes.
rpcserver.go (4)
  • 3721-3722: The method signature for fetchWaitingCloseChannels has been updated to include an includeTx boolean parameter. This change aligns with the PR's objective to conditionally include the closing transaction details in the response based on this parameter.
  • 3737-3772: The getClosingTx helper function has been introduced to locate the closing transaction of a waiting close channel. It first attempts to find the force closing transaction and, if not found, tries to locate the cooperative closing transaction. The function handles errors appropriately, returning nil for the transaction if it's not found, which is a sensible approach given the context that the remote party might have broadcasted the closing transaction.
  • 3832-3837: Error handling within the loop that processes waiting close channels is correctly implemented. If an error occurs while trying to find the closing transaction for a channel, the error is logged, and the function returns immediately with the error, ensuring that the error state is not ignored.
  • 3921-3923: The call to fetchWaitingCloseChannels correctly passes the IncludeTx field from the incoming request. This ensures that the caller's preference regarding the inclusion of the closing transaction details is respected.

rpcserver.go Outdated Show resolved Hide resolved
@JssDWt
Copy link
Contributor Author

JssDWt commented Jan 25, 2024

I've also added the flag to lncli, which was a piece I hadn't included before.

Copy link
Collaborator

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

LGTM ⛵

@JssDWt
Copy link
Contributor Author

JssDWt commented Jan 25, 2024

Addressed the rabbit's actionable comment.

Copy link
Collaborator

@guggero guggero 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, looks pretty good.

rpcserver.go Outdated
@@ -3857,11 +3856,28 @@ func (r *rpcServer) fetchWaitingCloseChannels() (waitingCloseChannels,
Memo: string(waitingClose.Memo),
}

var closingTxid string
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: either use a single var ( ... ) block or combine with var closingTxid, closingTxHex string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done var closingTxid, closingTxHex string

@@ -2733,6 +2736,10 @@ message PendingChannelsResponse {

// The transaction id of the closing transaction
string closing_txid = 4;

// The raw hex encoded bytes of the closing transaction. Included if
// include_raw_tx is true.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: "Included if include_raw_tx in the request is true", since there is no direct relationship between request/response in the API docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@JssDWt
Copy link
Contributor Author

JssDWt commented Jan 29, 2024

Addressed @guggero's comments and rebased.

@yyforyongyu yyforyongyu merged commit dd7b186 into lightningnetwork:master Jan 30, 2024
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements to existing features / behaviour rpc Related to the RPC interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants