Skip to content

tapchannel: fix immediate force-close proof sync and sweep anchoring#2133

Open
GeorgeTsagk wants to merge 5 commits into
lightninglabs:mainfrom
GeorgeTsagk:close-immediately-itest
Open

tapchannel: fix immediate force-close proof sync and sweep anchoring#2133
GeorgeTsagk wants to merge 5 commits into
lightninglabs:mainfrom
GeorgeTsagk:close-immediately-itest

Conversation

@GeorgeTsagk
Copy link
Copy Markdown
Member

@GeorgeTsagk GeorgeTsagk commented May 13, 2026

Description

This PR fixes immediate post-funding (N=0) force-close recovery by correctly re-syncing active vPacket outputs with re-anchored proofs when anchor indices are stale, and hardens anchor resolution to return explicit errors instead of panicking on out-of-range indices.

It also adds an integration test that force-closes right after funding confirmation and verifies the swept assets remain spendable via an onward transfer to a third node.

Depends on lightningnetwork/lnd#10804

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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 improves the reliability of asset channel force-closes, particularly in scenarios where a channel is closed immediately after funding. It introduces mechanisms to re-sync proofs and re-anchor outputs correctly, while also hardening the code against potential panics during anchor resolution. These changes ensure that assets remain recoverable and spendable even under edge-case timing conditions.

Highlights

  • Immediate Force-Close Recovery: Fixed post-funding (N=0) force-close recovery by ensuring active vPacket outputs are correctly re-synced with re-anchored proofs.
  • Anchor Resolution Hardening: Replaced potential panics with explicit error handling for out-of-range anchor indices, improving system stability.
  • Proof Metadata Persistence: Added support for storing witness scripts and control blocks in proof metadata, enabling reliable sweeps for commitment outputs.
  • Integration Testing: Added a new integration test to verify that assets remain spendable after an immediate force-close.
New Features

🧠 You can now enable Memory (public preview) 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 the 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 counterproductive. 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.

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
Copy Markdown

@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 support for immediate force-closing of asset channels by adding a new test case and updating the auxiliary sweeper and commitment logic to handle the necessary proof metadata and script key synchronization. The review comment regarding the robustness of the confirmation fallback logic in waitForTransferTxConf is valid and provides an actionable improvement, so it has been retained.

Comment on lines +459 to +461
if startHeight == 0 || startHeight > currentHeight {
startHeight = currentHeight
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The fallback confirmation logic might not be robust enough if no height hint is provided. If scanHeight is 0, startHeight is set to currentHeight, meaning only the current block is scanned. If the transaction was confirmed in a recent block (e.g., currentHeight - 1) and the primary notification was missed, this fallback will not find it, as scanHeight will be updated to currentHeight + 1 and the missed block will never be scanned.

To make this fallback more reliable, consider scanning a few recent blocks when no height hint is available.

                if startHeight == 0 {
			const rescanDepth = 6
			if currentHeight > rescanDepth {
				startHeight = currentHeight - rescanDepth
			} else {
				startHeight = 1
			}
		} else if startHeight > currentHeight {
			startHeight = currentHeight
		}

@GeorgeTsagk GeorgeTsagk force-pushed the close-immediately-itest branch from 69612e1 to 0a8e001 Compare May 13, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🆕 New

Development

Successfully merging this pull request may close these issues.

1 participant