Skip to content

add-close-confirmation-info#10509

Open
ziggie1984 wants to merge 4 commits intolightningnetwork:masterfrom
ziggie1984:cnct-reorg-v2
Open

add-close-confirmation-info#10509
ziggie1984 wants to merge 4 commits intolightningnetwork:masterfrom
ziggie1984:cnct-reorg-v2

Conversation

@ziggie1984
Copy link
Collaborator

@ziggie1984 ziggie1984 commented Jan 16, 2026

Add the close confirmation info which is now needed since channels are not immediately considered closed now.

@gemini-code-assist
Copy link

Summary of Changes

Hello @ziggie1984, 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 overhauls the channel closure mechanism to enhance its resilience against blockchain reorganizations and provide more transparent status updates to users. It introduces dynamic confirmation scaling for cooperative closes, where the number of required confirmations is now proportional to the channel's value, offering a better balance between security and user experience. A state-machine-based approach is implemented in the chain_watcher to robustly manage the confirmation process of closing transactions, including handling reorgs and RBF replacements. Additionally, the minimum CLTV delta and incoming broadcast delta have been increased to bolster routing security, and a new RPC field provides real-time confirmation countdowns for channels awaiting closure.

Highlights

  • Dynamic Confirmation Scaling for Channel Closures: Cooperative channel closes now dynamically adjust the required number of confirmations based on channel capacity, ranging from 1 for small channels to 6 for large ones. This improves security against reorgs while maintaining efficiency for smaller value channels.
  • Enhanced Reorg Protection for Channel Closures: The chain_watcher component has been refactored into a robust state machine to handle chain reorganizations during the confirmation period of channel closing transactions. This ensures correct processing even if transactions are re-mined or replaced.
  • Improved User Visibility of Closing Channels: A new blocks_til_closed field has been added to the PendingChannels RPC response, providing users with a clear countdown of remaining confirmations until a channel is considered fully closed.
  • Increased CLTV Delta for Routing Security: The minimum CLTV delta (MinCLTVDelta) has been increased from 18 to 24 blocks, and DefaultIncomingBroadcastDelta from 10 to 16. This provides a larger safety margin for HTLCs and reduces the risk of force closures due to timing issues.
  • Comprehensive Testing for Reorg Scenarios: Extensive new unit and integration tests, including property-based testing, have been added to validate the new reorg-aware logic for various channel close types, ensuring the robustness of the updated system.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

@ziggie1984
Copy link
Collaborator Author

Looks like this:

Screenshot 2026-01-16 at 23 00 46

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 introduces a more robust confirmation handling mechanism for channel closures, particularly for cooperative closes, to better withstand chain reorganizations. This is achieved by implementing a state machine in the chain_watcher to track spend confirmations and handle reorgs gracefully. The number of confirmations required for a cooperative close is now scaled based on channel capacity, with a minimum of 3 confirmations in production for reorg safety.

The changes also include:

  • A new CloseConfirmationHeight field in the channel database to track the confirmation height of the closing transaction.
  • A new blocks_til_closed field in the PendingChannels RPC response to show the remaining confirmations until a channel is fully closed.
  • An increase of MinCLTVDelta from 18 to 24 blocks for a larger safety margin.
  • Extensive new tests, including property-based tests, to validate the new reorg handling logic.

The code is well-structured, thoroughly tested, and the new logic for handling reorgs is a significant improvement in robustness. I have a couple of minor comments regarding a documentation inconsistency and a style guide violation.

// confirmations until the channel is considered fully closed. It also tests
// that the field resets correctly after a chain reorg removes the closing
// transaction's confirmations.
func testWaitingCloseBlocksTilClosed(ht *lntest.HarnessTest) {
Copy link
Member

Choose a reason for hiding this comment

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

Alternatively can add this assertion to the existing test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes deleted the separated tests and added it to the existent ones.

…mation

This commit adds a new CloseConfirmationHeight field to the OpenChannel
struct which records the block height at which the closing transaction
was first confirmed. This is stored using TLV encoding (TlvType9) for
backwards compatibility.

A new MarkCloseConfirmationHeight method is added to persist this value,
which can be called when the closing tx confirms and also supports
updates in case of chain reorgs.
@ziggie1984 ziggie1984 force-pushed the cnct-reorg-v2 branch 2 times, most recently from c064bad to 2628c3e Compare January 20, 2026 23:09
@saubyk saubyk added this to the v0.20.1 milestone Jan 21, 2026
@ziggie1984 ziggie1984 marked this pull request as ready for review January 21, 2026 19:35
Update the chain watcher to set and reset the CloseConfirmationHeight
field when monitoring a channel close. When a spend is detected, we
record the spending height so users can see remaining confirmations.
When a reorg removes the close tx from the chain, we reset the height
to 0 to reflect that the transaction is no longer confirmed.
Add a new field blocks_til_closed to the WaitingCloseChannel message in
PendingChannels RPC response. This shows users how many more blocks
until their waiting close channel will be fully closed and removed.

The required confirmations are determined by CloseConfsForCapacity which
scales based on channel capacity for reorg safety. If the close tx is
not yet confirmed, the full required confirmations are shown.
Add an integration test that verifies the blocks_til_closed field in
the WaitingCloseChannel RPC response. The test covers:

1. Initial state: shows full required confirmations when tx unconfirmed
2. Countdown: decrements as blocks are mined
3. Reorg handling: resets to full confirmations when close tx is
   reorged out of the chain
4. Recovery: countdown resumes correctly after close tx is re-mined
Copy link
Contributor

@Abdulkbk Abdulkbk left a comment

Choose a reason for hiding this comment

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

LGTM

image

reorg safety factor which is determined by the channel capacity. As
long as the closing transaction is not confirmed, this value will be
the number of confirmations required to consider the channel fully
closed.
Copy link
Contributor

Choose a reason for hiding this comment

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

we should run make rpc again as the comment here is inconsistent with lightning.swagger.json and lightning.pb.go: "Will be 0 if the closing transaction is not yet confirmed"

@@ -162,6 +162,8 @@ func testRBFCoopCloseDisconnect(ht *lntest.HarnessTest) {
// testCoopCloseRBFWithReorg tests that when a cooperative close transaction
Copy link
Contributor

Choose a reason for hiding this comment

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

missing a release-note entry

@saubyk saubyk modified the milestones: v0.20.1, v0.21.0 Jan 27, 2026
@saubyk saubyk added this to v0.21 Jan 27, 2026
@lightninglabs-deploy
Copy link
Collaborator

@Roasbeef: review reminder
@ziggie1984, 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

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants