Skip to content

chancloser: account for aux close outputs in initial coop close fee baseline#10615

Open
darioAnongba wants to merge 1 commit intolightningnetwork:masterfrom
darioAnongba:fix/chancloser-include-aux-outputs
Open

chancloser: account for aux close outputs in initial coop close fee baseline#10615
darioAnongba wants to merge 1 commit intolightningnetwork:masterfrom
darioAnongba:fix/chancloser-include-aux-outputs

Conversation

@darioAnongba
Copy link
Contributor

Problem

Custom channel coop closes can fail with: unable to process close msg: insufficient fee.

Root cause

For taproot/custom channels, ChanCloser computed the initial coop close fee (idealFeeSat) from only local+remote outputs, but the final close tx can include auxiliary extra outputs.

That mismatch can underprice the first accepted close offer (notably in taproot fast-close), causing mempool rejection and peer disconnect.

Fix

Extend coop close fee weight calculation to include optional extra outputs.

@darioAnongba darioAnongba changed the title lnwallet/chancloser: account for aux close outputs in initial coop cl… lnwallet/chancloser: account for aux close outputs in initial coop close fee baseline Feb 27, 2026
@darioAnongba darioAnongba changed the title lnwallet/chancloser: account for aux close outputs in initial coop close fee baseline chancloser: account for aux close outputs in initial coop close fee baseline Feb 27, 2026
@lightninglabs-deploy lightninglabs-deploy added the severity-critical Requires expert review - security/consensus critical label Feb 27, 2026
@lightninglabs-deploy
Copy link
Collaborator

🔴 PR Severity: CRITICAL

Automated classification | 2 files | 98 lines changed

🔴 Critical (1 file)
  • lnwallet/chancloser/chancloser.go - Falls under lnwallet/*: wallet operations, channel funding, and commitment transactions — requires expert review
🟢 Low (1 file)
  • docs/release-notes/release-notes-0.21.0.md - Release notes documentation

Analysis

This PR modifies lnwallet/chancloser/chancloser.go, which is part of the lnwallet/* package — a CRITICAL severity category covering wallet operations, channel funding, signing, and commitment transactions. Any changes here directly affect on-chain fund safety and cooperative channel closing logic, warranting expert review.

Severity bump check: No bump needed — only 2 non-test files changed (~98 lines), and a single critical package is touched.

The test file (lnwallet/chancloser/chancloser_test.go) and the release notes (docs/release-notes/release-notes-0.21.0.md) were excluded from the line/file count per policy.


To override, add a severity-override-{critical,high,medium,low} label.

@gemini-code-assist
Copy link

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 addresses a critical issue where cooperative channel closes, particularly for taproot and custom channels with auxiliary outputs, could fail due to insufficient fee estimation. The ChanCloser mechanism now accurately accounts for these additional outputs when calculating the initial cooperative close fee, preventing transactions from being underpriced and subsequently rejected by the mempool. This ensures smoother and more reliable channel closures for advanced channel types.

Highlights

  • Cooperative Close Fee Calculation Enhancement: The calcCoopCloseFee function was updated to accept and incorporate optional auxiliary transaction outputs into its fee weight estimation, ensuring more accurate fee calculations for cooperative channel closes.
  • Iterative Fee Estimation for Auxiliary Outputs: A new estimateCloseFee function was introduced to handle the complexity of auxiliary outputs, which may depend on the close fee itself. This function iteratively calculates the fee to ensure consistency between the fee and the set of auxiliary outputs.
  • Improved Initial Fee Baseline: The initFeeBaseline method now utilizes the new estimateCloseFee function, preventing underpriced cooperative closes for taproot and custom channels that include auxiliary outputs, thereby avoiding mempool rejection and peer disconnects.
  • Comprehensive Testing: New test cases, including TestInitFeeBaselineWithAuxCloseOutputs, were added to validate the correct accounting of auxiliary close outputs in the fee baseline calculation, ensuring the robustness of the fix.
  • Release Note Update: A release note entry was added to document the fix for cooperative close fee baseline issues when channels include auxiliary close outputs.

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

Changelog
  • docs/release-notes/release-notes-0.21.0.md
    • Updated bullet point formatting from '*' to '-' for consistency.
    • Added a release note entry detailing the fix for cooperative close fee baseline calculation to include auxiliary outputs.
  • lnwallet/chancloser/chancloser.go
    • Modified calcCoopCloseFee to accept an extraOutputs parameter for including auxiliary transaction outputs in fee weight estimation.
    • Implemented a loop within calcCoopCloseFee to add the weights of extraOutputs to the total transaction weight.
    • Updated SimpleCoopFeeEstimator.EstimateFee to pass nil for extraOutputs when calling calcCoopCloseFee.
    • Introduced estimateCloseFee to handle iterative fee calculation for auxiliary close outputs, ensuring self-consistent fee and output sets.
    • Changed the signature of initFeeBaseline to return an error.
    • Modified initFeeBaseline to use estimateCloseFee for calculating idealFeeSat and maxFee, incorporating auxiliary output considerations.
    • Added error handling for estimateCloseFee calls within initFeeBaseline.
    • Updated BeginNegotiation to handle the potential error returned by initFeeBaseline.
  • lnwallet/chancloser/chancloser_test.go
    • Imported wallettypes package.
    • Added mockAuxChanCloser struct and its associated methods (ShutdownBlob, AuxCloseOutputs, FinalizeClose) to simulate auxiliary channel closer behavior for testing.
    • Updated TestMaxFeeClamp to use require.NoError when calling chanCloser.initFeeBaseline().
    • Added TestInitFeeBaselineWithAuxCloseOutputs to specifically verify that auxiliary close outputs are correctly factored into the initial fee baseline calculation.
    • Updated TestTaprootFastClose to use require.NoError for initFeeBaseline() calls.
Activity
  • The pull request was created by darioAnongba to address a known issue with cooperative channel closes failing due to incorrect fee estimation for channels with auxiliary outputs.
  • The changes involve modifying core fee calculation logic and adding new functions to handle iterative fee estimation, along with comprehensive test coverage.
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 addresses a problem where custom channel cooperative closes could fail due to insufficient fee estimation when auxiliary close outputs were present. The changes correctly extend the fee weight calculation to include these extra outputs, preventing underpriced close offers. The pull request also includes updates to release notes and new test cases to validate the fix. Overall, the changes improve the robustness of the channel closing mechanism for taproot and custom channels.

Comment on lines 255 to 256
// calcCoopCloseFee computes an "ideal" absolute co-op close fee given the
// delivery scripts of both parties and our ideal fee rate.

Choose a reason for hiding this comment

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

medium

The function signature for calcCoopCloseFee has been updated to include extraOutputs. Please update the function comment to reflect this new parameter and its purpose, as per the style guide rule that every function must be commented with its purpose and assumptions (Repository Style Guide, line 17).

Comment on lines 388 to +390
// initFeeBaseline computes our ideal fee rate, and also the largest fee we'll
// accept given information about the delivery script of the remote party.
func (c *ChanCloser) initFeeBaseline() {
func (c *ChanCloser) initFeeBaseline() error {

Choose a reason for hiding this comment

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

medium

The initFeeBaseline function now returns an error. The function comment should be updated to reflect this change, explaining when an error might be returned. This aligns with the style guide's requirement for function comments to be complete sentences and describe the function's purpose and assumptions (Repository Style Guide, lines 17, 19).

@darioAnongba darioAnongba force-pushed the fix/chancloser-include-aux-outputs branch from a00ee17 to 6925adc Compare February 27, 2026 14:12
@darioAnongba darioAnongba force-pushed the fix/chancloser-include-aux-outputs branch from 6925adc to dab25a4 Compare February 27, 2026 14:42
@darioAnongba darioAnongba marked this pull request as ready for review February 27, 2026 14:42
@lightninglabs-deploy lightninglabs-deploy added severity-critical Requires expert review - security/consensus critical and removed severity-critical Requires expert review - security/consensus critical labels Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

severity-critical Requires expert review - security/consensus critical

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants