Skip to content

peer: reestablish pending channels on reconnect - #11540

Merged
yyforyongyu merged 2 commits into
lightningnetwork:masterfrom
vincenzopalazzo:repro/pending-channel-reestablish
Nov 11, 2026
Merged

yyforyongyu merged 2 commits into
lightningnetwork:masterfrom
vincenzopalazzo:repro/pending-channel-reestablish

Conversation

@vincenzopalazzo

@vincenzopalazzo vincenzopalazzo commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Change Description

Fixes #4006.

BOLT 2, Message Retransmission, does not mention confirmation:

A funding node:

  • upon disconnection:
    • if it has broadcast the funding transaction:
      • MUST remember the channel for reconnection.

A non-funding node:

  • upon disconnection:
    • if it has sent the funding_signed message:
      • MUST remember the channel for reconnection.

A node:

  • upon reconnection:
    • otherwise:
      • MUST transmit channel_reestablish for each channel.
      • MUST wait to receive the other node's channel_reestablish message before sending any other messages for that channel.

Brontide.Start already remembers the channel. FetchOpenChannels returns it while the funding transaction is unconfirmed. loadActiveChannels then dropped it:

if lnChan.IsPending() {
    p.markPendingChannel(chanID)
    continue
}

No link is created, and Start wrote no channel_reestablish. A peer waiting on that message disconnects, which takes every other channel to that lnd node down until the pending one confirms. See lightningdevkit/rust-lightning#4764.

The first commit contains the regression test and fix. The second commit adds the release note.

The pending channel still does not get a link. The funding manager owns that, and creating one here would be torn down when the final link is added. The fix queues ChanSyncMsg(), the same message already sent for a borked channel, so Start writes it before the write handler. That is the funding-node case the test builds: initiator, funding transaction stored, still pending. A non-funding node that has sent funding_signed is pending in the same map and gets the same message.

The link created after confirmation still runs syncChanStates, which would send channel_reestablish again. A second copy on the same connection is not a reconnection. LDK fails the channel (Peer sent a loose channel_reestablish not after reconnect). The peer records that this connection already queued the message, and the link waits for the remote channel_reestablish without transmitting another one.

channel_ready is still sent by the funding manager after confirmation. It follows this channel_reestablish on the wire, because Start writes the sync message before the write handler starts. This patch does not block channel_ready on receipt of the peer's channel_reestablish. Doing so deadlocks with a peer that only sends channel_reestablish once its own link exists, which is what this code did before the fix.

Steps to Test

  1. go test -count=1 -timeout 120s -run TestPendingChannelReestablishOnReconnect ./peer/
  2. The test passes. It requires a channel_reestablish for the pending funding channel, and requires that this connection recorded the send so the later link does not repeat it.

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

  • The change is not insubstantial.
  • The change obeys the Code Documentation and Commenting guidelines, and lines wrap at 80.
  • Commits follow the Ideal Git Commit Structure.
  • Any new logging statements use an appropriate subsystem and logging level.
  • Any new lncli commands have appropriate tags in the comments for the rpc in the proto file.
  • There is a change description in a PR-specific release note fragment, or the no-changelog label is applied.

@github-actions github-actions Bot added ci-hold CI is held; remove this label to run CI severity-low Best-effort review labels Nov 10, 2026
@github-actions

Copy link
Copy Markdown

🟢 PR Severity: LOW

file analysis | 1 file | 68 lines changed

🟢 Low (1 file)
  • peer/brontide_test.go - test-only change, no production code affected

Analysis

This PR only modifies peer/brontide_test.go, which is a _test.go file. Although peer/* is normally a critical-tier package (encrypted peer connections, Noise protocol), test-only changes are classified as low severity per the exclusion rule for test files. No production code paths are affected, and the change is well under the file/line thresholds that would otherwise trigger a severity bump.


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

@github-actions

Copy link
Copy Markdown

⚠️ Severity changed: LOW → CRITICAL (files changed since last classification)

🔴 PR Severity: CRITICAL

file analysis | 4 files | 150 lines changed

🔴 Critical (2 files)
  • htlcswitch/link.go - HTLC forwarding / payment routing state machine
  • peer/brontide.go - encrypted peer connection (Noise protocol) handling
🟢 Low (2 files)
  • peer/brontide_test.go - test-only change, no production code affected
  • docs/release-notes/unreleased/11540.md - release notes only

Analysis

This PR now modifies production code in htlcswitch/link.go and peer/brontide.go, both of which fall under critical-tier packages (HTLC forwarding state machine and encrypted peer connection handling, respectively). The remaining changes are a test file and a release note. Since the highest-severity file changed determines overall severity, this PR is classified as critical and warrants expert review. File/line counts (4 files, 150 lines) are well below the thresholds that would otherwise trigger an additional severity bump.


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

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

/gateway review

Approve — no blockers. Real bug, correct minimal fix, test catches it.

The bug: a pending funding channel (broadcast, unconfirmed) is remembered across reconnect per BOLT 2, but loadActiveChannels dropped it with continue, so no channel_reestablish was ever transmitted for it. A peer that requires the message for every remembered channel (LDK does) disconnects, taking all other channels down until the pending one confirms.

The fix queues ChanSyncMsg() for pending channels at reconnect — the same message path borked channels already use — and records the send in chanSyncSent so the post-confirmation link doesn't retransmit. Design checks I ran rather than trusted:

  • BOLT 2 text: verified against the spec. The funding node "MUST remember the channel for reconnection" once it has broadcast, and "MUST transmit channel_reestablish for each channel" on reconnection — confirmation is not a condition. The PR's reading is correct.
  • Duplicate suppression: LDK fails a channel on a loose second reestablish, and the ChanSyncMsgSent flag cleanly prevents it while the link still waits for the remote's message, as required.
  • Ordering: confirmed in Start: all queued sync messages are written before the write handler launches, so this reestablish precedes channel_ready on the wire as the body claims.
  • The channel_ready deadlock tradeoff: the PR deliberately does not block channel_ready on receipt of the peer's reestablish. That's the only safe choice against pre-fix peers (which never send it for pending channels — blocking would hang those channels forever), at the cost of a residual spec nit you can't distinguish without feature negotiation. Correct call, and it's documented in the body.
  • Error path: if ChanSyncMsg() itself fails, the channel stays marked pending with no message — degrades to pre-fix behavior for that channel only. Fine.

Verified by execution: TestPendingChannelReestablishOnReconnect passes at the PR head and fails at the pre-fix commit 7ea573d18 (the test-only commit before the fix), so the test demonstrably catches the bug. Full go test ./peer/ passes (9.8s). gofmt clean, go vet clean, added lines ≤80 cols, release note present.

Note: the failing "CI result" check is the ci-hold label on this PR, not the code — remove the label for a full CI run. Not verified here: itests (no Docker).

— claudell ⚡ (OpenClaw dev agent; approval posts as litbot-9000 and does not count toward branch protection)

@ziggie1984
ziggie1984 force-pushed the repro/pending-channel-reestablish branch from fc57596 to f821fe0 Compare November 10, 2026 17:45
@ziggie1984 ziggie1984 changed the title peer: reproduce missing channel_reestablish for pending channels peer: send channel_reestablish for pending channels Nov 10, 2026
@ziggie1984

ziggie1984 commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Reworked the PR history into two focused commits: the regression test and implementation are together in the first commit, and the release note is in the second. Vincenzo remains the author and signatory on both commits.

@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

@ziggie1984 ziggie1984 added severity-override-low Manual override to low and removed ci-hold CI is held; remove this label to run CI labels Nov 10, 2026
ziggie1984 pushed a commit to vincenzopalazzo/lnd that referenced this pull request Nov 10, 2026
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
@ziggie1984
ziggie1984 force-pushed the repro/pending-channel-reestablish branch from f821fe0 to 2a5c505 Compare November 10, 2026 19:01
@ziggie1984 ziggie1984 changed the title peer: send channel_reestablish for pending channels peer: reestablish pending channels on reconnect Nov 10, 2026
@github-actions github-actions Bot added severity-low Best-effort review and removed severity-critical Requires expert review - security/consensus critical labels Nov 10, 2026
@github-actions

Copy link
Copy Markdown

⚠️ Severity changed: CRITICAL → LOW (manual override applied)

🟢 PR Severity: LOW

override | 4 files | 148 lines changed

Analysis

A severity-override-low label is present on this PR, so automatic classification was skipped and the severity is forced to low per the manual override.

For reference, the file-based classification would otherwise have been critical, driven by production changes in htlcswitch/link.go (HTLC forwarding state machine) and peer/brontide.go (encrypted peer connection handling), alongside a test file and a release note.


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

ziggie1984 pushed a commit to vincenzopalazzo/lnd that referenced this pull request Nov 10, 2026
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
@ziggie1984
ziggie1984 force-pushed the repro/pending-channel-reestablish branch from 2a5c505 to 2565c63 Compare November 10, 2026 19:04
ziggie1984 pushed a commit to vincenzopalazzo/lnd that referenced this pull request Nov 11, 2026
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
@ziggie1984
ziggie1984 force-pushed the repro/pending-channel-reestablish branch from 2565c63 to a34ec76 Compare November 11, 2026 01:49
@ziggie1984
ziggie1984 enabled auto-merge November 11, 2026 01:49
@yyforyongyu yyforyongyu added backport-v0.20.x-branch This label is used to trigger the creation of a backport PR to the branch `v0.20.x-branch`. backport-v0.21.x-branch This label triggers a backport to branch `v0.21.x-branch ` labels Nov 11, 2026
@yyforyongyu yyforyongyu added this to the v0.21.7 milestone Nov 11, 2026
@yyforyongyu
yyforyongyu disabled auto-merge November 11, 2026 12:51
@yyforyongyu
yyforyongyu self-requested a review November 11, 2026 13:05
BOLT 2 requires a node to send channel_reestablish for every
remembered channel when a peer reconnects. Pending channels are remembered
but have no link, so lnd previously sent nothing until funding confirmed. A
peer waiting for the message could disconnect the shared connection.

Queue the message while loading pending channels and record the handoff so
the link created after confirmation still processes the remote state without
sending a duplicate.

Add regression coverage for the pending funding-node case.

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
@yyforyongyu
yyforyongyu force-pushed the repro/pending-channel-reestablish branch from a34ec76 to 6e47397 Compare November 11, 2026 13:51
@yyforyongyu
yyforyongyu merged commit 926d903 into lightningnetwork:master Nov 11, 2026
1 check failed
@github-actions

Copy link
Copy Markdown

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

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

git fetch origin backport-11540-to-v0.20.x-branch
git worktree add --checkout .worktree/backport-11540-to-v0.20.x-branch backport-11540-to-v0.20.x-branch
cd .worktree/backport-11540-to-v0.20.x-branch
git reset --hard HEAD^
git cherry-pick -x 14efa3d32ffb2a7341522d6294af98450371f22c 6e473970bc476aa299fe9f3aae9fb73353972cd6
git push --force-with-lease

@github-actions

Copy link
Copy Markdown

Successfully created backport PR for v0.21.x-branch:

ziggie1984 added a commit that referenced this pull request Nov 11, 2026
…21.x-branch

[v0.21.x-branch] Backport #11540: peer: reestablish pending channels on reconnect
ziggie1984 pushed a commit that referenced this pull request Nov 11, 2026
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
ziggie1984 added a commit that referenced this pull request Nov 11, 2026
…20.x-branch

[v0.20.x-branch] Backport #11540: peer: reestablish pending channels on reconnect
@kaloudis kaloudis mentioned this pull request Nov 11, 2026
6 of 29 tasks
paulscode pushed a commit to paulscode/lightning-fork that referenced this pull request Nov 12, 2026
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
(cherry picked from commit 6e47397)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-v0.20.x-branch This label is used to trigger the creation of a backport PR to the branch `v0.20.x-branch`. backport-v0.21.x-branch This label triggers a backport to branch `v0.21.x-branch ` severity-low Best-effort review severity-override-low Manual override to low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

funding_locked sent before channel_reestablish

4 participants