Skip to content

lnwallet: expose negotiated configs in aux chan state - #10804

Open
GeorgeTsagk wants to merge 1 commit into
lightningnetwork:masterfrom
GeorgeTsagk:close-immediately-itest-lnd-7c38
Open

lnwallet: expose negotiated configs in aux chan state#10804
GeorgeTsagk wants to merge 1 commit into
lightningnetwork:masterfrom
GeorgeTsagk:close-immediately-itest-lnd-7c38

Conversation

@GeorgeTsagk

@GeorgeTsagk GeorgeTsagk commented May 13, 2026

Copy link
Copy Markdown
Collaborator

Description

Pass a populated aux channel state into aux funding so initial custom channel blobs include the negotiated local/remote configs.

This fixes height-0 aux channel state without adding force-close resolution plumbing in lnd.

@GeorgeTsagk GeorgeTsagk self-assigned this May 13, 2026
@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 introduces a mechanism to provide auxiliary resolvers with the initial commitment key ring for channels that are force-closed at height 0. By correctly identifying the commitment keys used before the channel_ready rotation, the changes prevent output misidentification and ensure that auxiliary components function correctly during immediate post-funding force-close events.

Highlights

  • Resolution Request Update: Added an InitialKeyRing field to the ResolutionReq struct to support auxiliary resolvers during force-close scenarios.
  • Key Derivation Logic: Implemented initialCommitmentKeyRingFromState to derive the correct commitment keys for channels at height 0, distinguishing them from post-channel_ready states.
  • Force-Close Integration: Updated NewLocalForceCloseSummary to populate the InitialKeyRing when the local commitment height is 0, ensuring aux resolvers have the necessary context.
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.

@github-actions github-actions Bot added the severity-critical Requires expert review - security/consensus critical label May 13, 2026
@github-actions

Copy link
Copy Markdown

🔴 PR Severity: CRITICAL

Automated classification | 2 files | 61 lines changed

🔴 Critical (2 files)
  • lnwallet/aux_resolutions.go - wallet auxiliary resolution logic (lnwallet/*)
  • lnwallet/channel.go - core channel state machine and commitment transaction handling (lnwallet/*)

Analysis

Both changed files reside in the lnwallet package, which is classified as CRITICAL because it encompasses wallet operations, channel funding, signing, and commitment transaction logic — among the most security-sensitive code in the Lightning Network Daemon.

  • lnwallet/channel.go is the central channel state machine; changes here can affect commitment transaction construction, fee handling, and the correctness of channel updates.
  • lnwallet/aux_resolutions.go handles auxiliary (e.g. custom channel) resolution paths, which feed into on-chain fund recovery.

This PR is small in scope (2 files, 61 lines), so no severity bump was triggered. However, the inherent criticality of lnwallet means expert review is required before merging.


To override, add a severity-override-{critical,high,medium,low} label.
<!-- pr-severity-bot -->

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

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 an InitialKeyRing field to the ResolutionReq struct and implements initialCommitmentKeyRingFromState to derive the key ring for the initial commitment state at height 0. This allows downstream resolvers to correctly distinguish between initial and subsequent commitment states. The reviewer suggested minor documentation improvements to adhere to the repository's style guide, specifically regarding function comment formatting and the requirement for function documentation.

Comment thread lnwallet/channel.go Outdated
Comment thread lnwallet/channel.go Outdated
Comment on lines +672 to +676
func (lc *LightningChannel) initialCommitmentKeyRing(
whoseCommit lntypes.ChannelParty) *CommitmentKeyRing {

return initialCommitmentKeyRingFromState(lc.channelState, whoseCommit)
}

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

This function is missing a comment, which is required by the repository's style guide. Please add a comment that describes its purpose.

Suggested change
func (lc *LightningChannel) initialCommitmentKeyRing(
whoseCommit lntypes.ChannelParty) *CommitmentKeyRing {
return initialCommitmentKeyRingFromState(lc.channelState, whoseCommit)
}
// initialCommitmentKeyRing derives the key ring for the initial commitment
// state at height 0 for the channel.
func (lc *LightningChannel) initialCommitmentKeyRing(
whoseCommit lntypes.ChannelParty) *CommitmentKeyRing {
return initialCommitmentKeyRingFromState(lc.channelState, whoseCommit)
}
References
  1. Every function must be commented with its purpose and assumptions. (link)

@GeorgeTsagk
GeorgeTsagk force-pushed the close-immediately-itest-lnd-7c38 branch from 077847d to 70cfed1 Compare May 13, 2026 14:14
@GeorgeTsagk
GeorgeTsagk requested review from Roasbeef and jtobin May 14, 2026 10:33
@GeorgeTsagk
GeorgeTsagk force-pushed the close-immediately-itest-lnd-7c38 branch from 70cfed1 to 94fdcc7 Compare May 15, 2026 11:50

@jtobin jtobin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm pretty sure this one can be simplified dramatically, and I think the simplifications will carry over to the associated tapd PR. I commented on a bunch of stuff, but didn't check any of it myself, so it could be wrong. Seems worth following these Opus-generated instructions to check:

  • Drop ResolutionReq.InitialKeyRing; add ResolutionReq.CommitHeight fn.Option[uint64].
  • Delete initialCommitmentKeyRingFromState.
  • In NewLocalForceCloseSummary, set CommitHeight: fn.Some(chanState.LocalCommitment.CommitHeight).
  • In NewUnilateralCloseSummary, set CommitHeight: fn.Some(remoteCommit.CommitHeight).
  • Audit the other ResolutionReq construction sites (lnwallet/channel.go:2311, 2394, 7530, 7766, 7903, 8130) and set CommitHeight from the state-num in scope.

Comment thread lnwallet/channel.go Outdated
Comment thread lnwallet/channel.go Outdated
Comment thread lnwallet/aux_resolutions.go Outdated
@GeorgeTsagk
GeorgeTsagk force-pushed the close-immediately-itest-lnd-7c38 branch from 94fdcc7 to 769500d Compare May 29, 2026 12:43
@GeorgeTsagk
GeorgeTsagk requested a review from jtobin June 1, 2026 11:58

@jtobin jtobin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. 👍 👍

@jtobin

jtobin commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

I may revisit this one. Presently reviewing lightninglabs/taproot-assets#2133, and I think this change may not actually be necessary to solve the issue we encounter in tapd downstream? Will report more when I know more..

@jtobin jtobin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just a couple of final recos after your last round of changes to lightninglabs/taproot-assets#1933.

Comment thread lnwallet/aux_resolutions.go Outdated
Comment thread lnwallet/reservation.go Outdated
@GeorgeTsagk
GeorgeTsagk force-pushed the close-immediately-itest-lnd-7c38 branch from de8a76a to dce6625 Compare June 30, 2026 12:20
@GeorgeTsagk
GeorgeTsagk force-pushed the close-immediately-itest-lnd-7c38 branch from dce6625 to cc85166 Compare July 8, 2026 13:31
@GeorgeTsagk
GeorgeTsagk requested a review from jtobin July 8, 2026 13:36

@jtobin jtobin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. 👍 👍

@saubyk saubyk added this to lnd v0.22 Jul 8, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in lnd v0.22 Jul 8, 2026
@saubyk saubyk moved this from Backlog to In review in lnd v0.22 Jul 8, 2026
@Roasbeef

Roasbeef commented Jul 8, 2026

Copy link
Copy Markdown
Member

The diff appears to no longer reflect the PR OP desc.

Comment thread funding/manager.go Outdated
@GeorgeTsagk GeorgeTsagk changed the title lnwallet: surface initial commitment key ring for N=0 force-close aux resolution lnwallet: expose negotiated configs in aux chan state Jul 9, 2026
@GeorgeTsagk

Copy link
Copy Markdown
Collaborator Author

The diff appears to no longer reflect the PR OP desc.

Updated

@GeorgeTsagk
GeorgeTsagk force-pushed the close-immediately-itest-lnd-7c38 branch from cc85166 to bbde57a Compare July 9, 2026 11:47
@GeorgeTsagk
GeorgeTsagk requested a review from Roasbeef July 9, 2026 12:49
@jtobin
jtobin requested a review from ziggie1984 July 13, 2026 15:06

@ziggie1984 ziggie1984 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Change makes sense, wondering why we did not encounter this way earlier on the asset software side, wasn't the config used there form the beginning ?

Comment thread lnwallet/reservation.go Outdated
Comment thread funding/manager_test.go Outdated
Comment thread funding/manager_test.go
@jtobin

jtobin commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

wondering why we did not encounter this way earlier on the asset software side

From what I can tell the broken case is just super rare. IIRC one has to force close before any HTLCs have been exchanged.

@GeorgeTsagk
GeorgeTsagk force-pushed the close-immediately-itest-lnd-7c38 branch from bbde57a to b0a25b9 Compare July 16, 2026 11:56
@GeorgeTsagk
GeorgeTsagk requested a review from ziggie1984 July 16, 2026 12:28
@ziggie1984

Copy link
Copy Markdown
Collaborator

tests in race mod are failing now due to the ew test

@GeorgeTsagk

Copy link
Copy Markdown
Collaborator Author

tests in race mod are failing now due to the ew test

taking a look

@GeorgeTsagk
GeorgeTsagk force-pushed the close-immediately-itest-lnd-7c38 branch from b0a25b9 to 97f642e Compare July 23, 2026 14:03
@litbot-9000

Copy link
Copy Markdown
Collaborator

@Roasbeef: review reminder
@ziggie1984: review reminder
@GeorgeTsagk, remember to re-request review from reviewers when ready

@litbot-9000

Copy link
Copy Markdown
Collaborator

@Roasbeef: review reminder
@ziggie1984: review reminder
@GeorgeTsagk, remember to re-request review from reviewers when ready

2 similar comments
@litbot-9000

Copy link
Copy Markdown
Collaborator

@Roasbeef: review reminder
@ziggie1984: review reminder
@GeorgeTsagk, remember to re-request review from reviewers when ready

@litbot-9000

Copy link
Copy Markdown
Collaborator

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

Labels

no-changelog severity-critical Requires expert review - security/consensus critical

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

6 participants