add-close-confirmation-info#10509
Conversation
Summary of ChangesHello @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 Highlights
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this comment.
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
CloseConfirmationHeightfield in the channel database to track the confirmation height of the closing transaction. - A new
blocks_til_closedfield in thePendingChannelsRPC response to show the remaining confirmations until a channel is fully closed. - An increase of
MinCLTVDeltafrom 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) { |
There was a problem hiding this comment.
Alternatively can add this assertion to the existing test?
There was a problem hiding this comment.
yes deleted the separated tests and added it to the existent ones.
c064bad to
2628c3e
Compare
2628c3e to
47f0539
Compare
|
@Roasbeef: review reminder |
saubyk
left a comment
There was a problem hiding this comment.
Some comments regarding blocks_til_closed field in the response which I find confusing.
Additionally was wondering, if an existing channel is in "waiting close" state when upgrading what value would they show for blocks_til_closed in the rpc response?
|
Also, think we need a release note entry here since we are adding a new field in the rpc response which the users should be made aware of. |
47f0539 to
5b0353f
Compare
|
@claude review |
|
Claude finished @ziggie1984's task in 3m 14s —— View job PR Review
Overall this is a well-structured addition. The TLV encoding, state management, and test coverage are solid. I have a few findings worth addressing before merging.
|
| Severity | Issue |
|---|---|
| Minor | MarkCloseConfirmationHeight doc comment says "confirms" but means "detected in a block" |
| Minor | Upgrade path with CloseConfirmationHeight == 0 needs comment/explanation |
| Nit | MarkCloseConfirmationHeight called for all spend types without comment |
| Nit | requiredConfs coupling between rpcserver and chain_watcher should be documented |
| Nit | Line length in itest comment |
The core logic for the targetHeight arithmetic (closeConfHeight + requiredConfs - 1) is correct. The TLV serialization/deserialization and the 0-sentinel pattern for reset are sound. Release notes look good.
|
Regarding @saubyk's question about channels already in waiting-close state during an upgrade: This is a transient state that resolves itself automatically. On startup, the chain watcher re-registers for spend notifications on the funding output. The chain notifier immediately re-delivers the already-confirmed spend event, which triggers |
5b0353f to
6ee0dcb
Compare
6ee0dcb to
4af48c9
Compare
ellemouton
left a comment
There was a problem hiding this comment.
looks good! a couple of suggestions
| // CloseConfirmationHeight records the block height at which the closing | ||
| // transaction was first confirmed. This is used to track remaining | ||
| // confirmations until the channel is considered fully closed. | ||
| CloseConfirmationHeight uint32 |
There was a problem hiding this comment.
maybe just add what a zero value here means
There was a problem hiding this comment.
actually - should we not just have this as fn.Option to start with?
|
|
||
| // Reset the close confirmation height since the spend | ||
| // was reorged out. | ||
| err := c.cfg.chanState.MarkCloseConfirmationHeight(0) |
There was a problem hiding this comment.
perhaps just worth having an explicit ResetConfHeight method instead of repurposing 0?
| closing transaction is not yet confirmed, this value equals the | ||
| total number of confirmations required. | ||
| */ | ||
| uint32 blocks_til_close_confirmed = 6; |
There was a problem hiding this comment.
also just worth adding the closed height?
18c27b5 to
ae33401
Compare
…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.
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.
ae33401 to
216c109
Compare
calvinrzachman
left a comment
There was a problem hiding this comment.
thanks for the routing log fix 🙏
Add a new fields blocks_til_closed and close_height to the WaitingCloseChannel message in PendingChannels RPC response. This shows users how many more blocks until the 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.
216c109 to
d6ea87d
Compare
Add an integration test that verifies the blocks_til_closed field and the close_height 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
d6ea87d to
86af342
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new CloseConfirmationHeight field to track the block height at which a channel's closing transaction is first confirmed, enabling reorg-safe confirmation tracking for closed channels. The changes involve updating the channel database schema, modifying persistence logic, and integrating state management in the chain_watcher to record and reset this height during block confirmations and reorgs. The RPC API is extended with blocks_til_close_confirmed and close_height fields in the PendingChannelsResponse.WaitingCloseChannel message, providing users with real-time, reorg-aware confirmation status. Comprehensive integration tests were added to verify the correct behavior of these new fields under various scenarios, including reorgs. A minor logging improvement was also included.


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