Skip to content

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

Merged
Roasbeef merged 1 commit into
lightningnetwork:masterfrom
GeorgeTsagk:close-immediately-itest-lnd-7c38
Sep 2, 2026
Merged

Roasbeef merged 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 Resolved
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 Resolved
Comment thread lnwallet/channel.go Resolved
Comment thread lnwallet/aux_resolutions.go Resolved
@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 Resolved
Comment thread lnwallet/reservation.go Resolved
@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 Resolved
@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 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

@jtobin

jtobin commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

This one came up during a sync last week; think there's nothing holding it up. (cc @ziggie1984 @Roasbeef)

@GeorgeTsagk
GeorgeTsagk removed the request for review from Roasbeef September 1, 2026 15:46
Comment thread funding/manager_test.go Resolved

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

LGTM, would be good to add the missing godocs

Comment thread funding/manager_test.go Resolved
Comment thread lnwallet/reservation_test.go Resolved
@ziggie1984 ziggie1984 added this to v0.21 Sep 2, 2026
@ziggie1984 ziggie1984 removed this from lnd v0.22 Sep 2, 2026
@ziggie1984 ziggie1984 added this to the v0.21.4 milestone Sep 2, 2026
@ziggie1984 ziggie1984 added the backport-v0.21.x-branch This label triggers a backport to branch `v0.21.x-branch ` label Sep 2, 2026
@GeorgeTsagk
GeorgeTsagk force-pushed the close-immediately-itest-lnd-7c38 branch from 97f642e to 98abfba Compare September 2, 2026 14:41
@ziggie1984
ziggie1984 enabled auto-merge September 2, 2026 14:52
@Roasbeef
Roasbeef disabled auto-merge September 2, 2026 18:27
@Roasbeef
Roasbeef merged commit 1e12765 into lightningnetwork:master Sep 2, 2026
76 of 77 checks passed
@github-project-automation github-project-automation Bot moved this to Done in v0.21 Sep 2, 2026
@github-project-automation github-project-automation Bot moved this from 👀 In review to ✅ Done in Taproot-Assets Project Board Sep 2, 2026
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

Created backport PR for v0.21.x-branch:

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin backport-10804-to-v0.21.x-branch
git worktree add --checkout .worktree/backport-10804-to-v0.21.x-branch backport-10804-to-v0.21.x-branch
cd .worktree/backport-10804-to-v0.21.x-branch
git reset --hard HEAD^
git cherry-pick -x 98abfba173967223d738677bdce85bd9541026cb
git push --force-with-lease

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-v0.21.x-branch This label triggers a backport to branch `v0.21.x-branch ` no-changelog severity-critical Requires expert review - security/consensus critical

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants