Skip to content

Conversation

Suvrat1629
Copy link

@Suvrat1629 Suvrat1629 commented Oct 18, 2025

Change Description

This PR updates the lncli closechannel and closeallchannels commands to include fee_per_vbyte and local_close_tx in their JSON output when available.

  • Refactors executeChannelClose to send all close details (txid, fee, local flag) via a struct.
  • Ensures both single and batch close flows print these fields in their output.

Fixes #9831

Steps to Test

  1. Open a channel and close it using lncli closechannel with a custom fee.
  2. Confirm the JSON output includes closing_txid, fee_per_vbyte, and local_close_tx.
  3. Run lncli closeallchannels and confirm the output for each channel includes the new fields.

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.

…loseallchannels output

- Update closechannel and closeallchannels commands to display fee_per_vbyte and local_close_tx in the JSON output when available.
- Refactor executeChannelClose to send all close details (txid, fee, local flag) via a struct.
Copy link

Summary of Changes

Hello @Suvrat1629, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the user experience for lncli channel closing commands by enriching their JSON output. Users can now immediately access critical information such as the transaction fee per vbyte and whether the closure was initiated locally or remotely, directly from the closechannel and closeallchannels commands. This enhancement provides more comprehensive details for better monitoring and automation of channel management.

Highlights

  • Enhanced lncli Output: The lncli closechannel and closeallchannels commands now include fee_per_vbyte and local_close_tx in their JSON output, providing more detailed information about channel closures.
  • Refactored Channel Closing Logic: The executeChannelClose function has been refactored to pass all channel closing details (transaction ID, fee, and local/remote flag) via a dedicated CloseInfo struct, improving data encapsulation.
  • Consistent Information Across Commands: Both single channel and batch channel closing operations now consistently display these new fields in their output, ensuring a uniform user experience.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 pull request refactors the closechannel and closeallchannels commands to include fee_per_vbyte and local_close_tx in their JSON output. The change introduces a new CloseInfo struct and modifies executeChannelClose to communicate more details about the channel closure. The implementation is mostly correct, but there is a critical issue that can lead to deadlocks in both commands if the channel close stream ends before sending closing transaction details. I've provided comments and suggestions to fix this by ensuring the communication channel is always closed and handling this case in the receiving goroutines.

func executeChannelClose(ctxc context.Context, client lnrpc.LightningClient,
req *lnrpc.CloseChannelRequest, txidChan chan<- string, block bool) error {
req *lnrpc.CloseChannelRequest, closeInfoChan chan<- CloseInfo, block bool) error {

Choose a reason for hiding this comment

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

critical

To prevent a potential deadlock in the calling functions (closeChannel and closeAllChannels), closeInfoChan should be closed when this function exits. If executeChannelClose returns without sending a value (for example, if the stream ends with io.EOF before a ClosePending update), the receiving goroutines will block indefinitely. Using defer to close the channel is the idiomatic way to ensure it's closed on all execution paths.

    defer close(closeInfoChan)

Comment on lines +1159 to +1160
closeInfo := <-closeInfoChan
printJSON(closeInfo)

Choose a reason for hiding this comment

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

high

To complement the proposed change of always closing closeInfoChan in executeChannelClose, this read operation should be updated to handle the case where the channel is closed without a value being sent. Using the two-variable assignment form of a channel receive (value, ok := <-ch) allows checking whether a value was received before attempting to use it, preventing the printing of an empty JSON object if no close information is sent.

        closeInfo, ok := <-closeInfoChan
        if ok {
            printJSON(closeInfo)
        }

Comment on lines +1483 to +1486
closeInfo := <-closeInfoChan
res.ClosingTxid = closeInfo.ClosingTxid
res.FeePerVbyte = closeInfo.FeePerVbyte
res.LocalCloseTx = closeInfo.LocalCloseTx

Choose a reason for hiding this comment

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

high

This blocking read from closeInfoChan can lead to a deadlock if executeChannelClose returns without sending data. To fix this, you should handle the case where the channel is closed without a value being sent. In the context of closeAllChannels, not receiving close information when no error occurred should be treated as a failure for that specific channel closure, and an appropriate error message should be set in the result.

            closeInfo, ok := <-closeInfoChan
            if !ok {
                res.FailErr = "channel close stream ended " +
                    "before sending closing transaction"
                return
            }
            res.ClosingTxid = closeInfo.ClosingTxid
            res.FeePerVbyte = closeInfo.FeePerVbyte
            res.LocalCloseTx = closeInfo.LocalCloseTx

Copy link
Contributor

@NishantBansal2003 NishantBansal2003 left a comment

Choose a reason for hiding this comment

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

Nice work 👍, the direction looks good

My main comment is FeePerVbyte and LocalCloseTx are only populated when the node opts for rbf-coop-close, otherwise, these values are not set. When returning the response, they appear with default (wrong) values, so we should decide whether this is the intended behavior or if they should be updated in all cases.

Comment on lines +1233 to +1235
if feeRate > 0 {
fmt.Fprintf(os.Stderr, "Fee rate: %d sat/vbyte\n", feeRate)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How would feeRate ever be negative?

Comment on lines +1223 to +1231
var closeTypeMsg string
if isLocalClose {
closeTypeMsg = " (local close)"
} else {
closeTypeMsg = " (remote close)"
}

fmt.Fprintf(os.Stderr, "Channel close transaction "+
"broadcasted: %v\n", txid)
"broadcasted: %v%s\n", txid, closeTypeMsg)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would say not required, since I can get this info from the JSON response anyway

txidChan := make(chan string, 1)
err = executeChannelClose(ctxc, client, req, txidChan, false)
closeInfoChan := make(chan CloseInfo, 1)
err = executeChannelClose(ctxc, client, req, closeInfoChan, false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines +1237 to +1245
if !sentCloseInfo {
closeInfo := CloseInfo{
ClosingTxid: txid.String(),
FeePerVbyte: feeRate,
LocalCloseTx: isLocalClose,
}
closeInfoChan <- closeInfo
sentCloseInfo = true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: In which case could the CloseStatusUpdate_ClosePending stream be received more than once?

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.

[feature]: lncli closechannel should report the fee rate of the on chain closing transaction in the output

2 participants