Skip to content

Correctness fixes for node announcement validation, HTLC limits, funding state release, BOLT text, and gossip cache - #11632

Merged
ziggie1984 merged 12 commits into
lightningnetwork:masterfrom
Roasbeef:morehouse-correctness-fixes
Nov 27, 2026
Merged

ziggie1984 merged 12 commits into
lightningnetwork:masterfrom
Roasbeef:morehouse-correctness-fixes

Conversation

@Roasbeef

Copy link
Copy Markdown
Member

This PR is a batch of correctness fixes for the Morehouse public issue set. Each fix is in its own commit with a regression test.

Fixes

Notes

  • All touched packages pass their tests with -tags=dev; the scoped custom linter reports no findings on this branch.
  • The Unicode category logic in ValidBoltText was independently reviewed against the BOLT 1 reader requirements.
  • The final commit fixes a defect found in adversarial self-review of this branch: the funding-timeout path originally pruned persistent peer connection state unconditionally, which would drop reconnect state for a peer that still had another open channel.

@github-actions github-actions Bot added ci-hold CI is held; remove this label to run CI severity-critical Requires expert review - security/consensus critical labels Nov 25, 2026
@github-actions

Copy link
Copy Markdown

🔴 PR Severity: CRITICAL

gh pr view | 26 files | 1271 additions / 89 deletions

🔴 Critical (4 files)
  • funding/manager.go - channel funding workflow coordination
  • lnwallet/reservation.go - channel funding/reservation logic
  • lnwire/lnwire.go - Lightning wire protocol message handling
  • lnwire/node_announcement.go, lnwire/node_announcement_2.go - wire protocol message definitions
  • server.go - core server coordination
🟠 High (1 file)
  • discovery/gossiper.go - gossip protocol handling
🟡 Medium (6 files)
  • accessman.go - top-level Go file, not separately categorized
  • bolt12/validate.go - BOLT12 validation logic
  • channel_notifier.go - top-level Go file, not separately categorized
  • netann/channel_announcement.go - network announcement helpers
  • zpay32/decode.go, zpay32/invoice.go - invoice encoding/decoding
🟢 Low (1 file)
  • docs/release-notes/release-notes-0.22.0.md - release notes

Analysis

This PR is classified CRITICAL because it modifies funding/manager.go and lnwallet/reservation.go (channel funding/reservation workflow), lnwire/* (wire protocol message definitions), and server.go (core server coordination). It additionally touches discovery/gossiper.go (HIGH) and several MEDIUM-tier packages. Because the change spans multiple distinct critical packages (funding, lnwallet, lnwire, server.go), it would normally warrant an additional severity bump, but CRITICAL is already the highest tier. Non-test/non-generated changes total 14 files and ~374 lines, below the file/line count bump thresholds on their own. Given the breadth across wire protocol, funding, and server-level code, this PR warrants expert review.


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

@ziggie1984
ziggie1984 self-requested a review November 25, 2026 17:53
@ziggie1984 ziggie1984 removed the ci-hold CI is held; remove this label to run CI label Nov 25, 2026
@ziggie1984

Copy link
Copy Markdown
Collaborator

I found three issues at 7ec8c3e that I’d address before merge.

  1. Funding validation failure can enter the channel_ready success path. Cleanup closes the discovery signal that ordinarily means confirmation succeeded. The failed channel is still in the DB as pending, so the readiness handler can proceed with state changes. The handler should check the persisted open state before processing readiness.
  2. An offline funding timeout can consume a restricted slot. The missing-score branch synthesizes a score, and the last-pending-channel path charges a live restricted slot. Update the pending count without adding a score or changing slot accounting for offline peers.
  3. BOLT text writers still accept unassigned Unicode code points. BOLT 1 allows readers to accept Cn, but the writer rule excludes all C* categories. Apply the stricter rule at local authoring boundaries while preserving validation and serialization of received announcements.

make lint-native also reported three line-length findings and one whitespace finding. The enabled staticcheck analyzer reported no findings on the diff.

@ziggie1984
ziggie1984 force-pushed the morehouse-correctness-fixes branch from 5335bed to 64e9a99 Compare November 25, 2026 21:01
In this commit, we reject channel announcements whose node IDs are equal or in descending lexicographical order before doing any signature verification. BOLT 7 requires receivers to ignore these messages, so accepting them allows invalid gossip to enter and propagate through our graph.

The regression covers both equal and descending node IDs and verifies that the ordering error takes precedence over signature validation.
@ziggie1984
ziggie1984 force-pushed the morehouse-correctness-fixes branch from 64e9a99 to cff8b97 Compare November 25, 2026 21:08

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

The code changes address the findings from my review, including the startup and invoice compatibility fixes and the reconnect-pruning guard. The local tests, native lint, staticcheck, and GitHub Static Checks passed on this revision.

The release-note fragment check still needs to pass before merge.

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

Thanks for batching these, the fixes look good from a product side. Main asks before merge:

  1. Release note needs to move to docs/release-notes/unreleased/11632.md with PR links, or the check will fail.
  2. The BOLT 1 text rules match bolts#1341, but lnd would be the first implementation to enforce them. CLN, Eclair and LDK still create and pay invoices with newlines in the description. Can we plan the rollout (release-note warning, or lenient decoding for a release)?
  3. Local alias handling: a ZWJ emoji in alias= now stops startup with a misleading "non-utf8" error, and a stored alias may be silently reset to the pubkey. Please make the errors and the release note clear for operators.

Comment thread zpay32/decode.go Resolved
Comment thread lnwire/lnwire.go Resolved
Comment thread funding/manager.go Resolved
Roasbeef and others added 11 commits November 25, 2026 22:24
In this commit, we reject remote HTLC constraints that cannot produce a valid channel update: a zero in-flight maximum or a minimum above the channel capacity. This prevents accepted channels from getting stuck before their announcement.

We also cap our optional minimum HTLC preference at the remote and capacity-derived maximum. Our preference must not turn otherwise usable remote limits into an invalid update. Focused tests cover rejection at the capacity boundary and the announcement parameter clamp.
In this commit, we stop deferring our own announcement_signatures in the evictable, in-memory futureMsgs cache. The funding manager creates our half only after its required confirmation depth and never re-sends it, so caching could permanently lose it on restart or eviction by any peer. Local halves now go straight through the normal pipeline, which durably stores them and reliably delivers them to our counterparty. Remote halves still wait for the configured proof maturity delta.

We also charge the future message cache for retained memory instead of a constant 1 per entry. Each message costs its maximum wire body plus 16 bytes per decoded feature bit, so a dense channel announcement can no longer let one peer pin ~0.7 GB. Ordinary messages keep their 1,000-entry bound, oversized entries are refused, and eviction stays LRU. Tests cover local-proof survival across restart/eviction, weighted admission/eviction, and the dense-feature memory bound.
In this commit, we enforce the BOLT 1 text rules on every field the spec types as utf8: node aliases, BOLT 11 descriptions, and BOLT 12 offer descriptions, issuers, and payer notes. A shared ValidBoltText helper rejects invalid UTF-8, control and format characters, private use, surrogates, and the line and paragraph separators while tolerating unassigned code points.

The fixed-width V1 alias keeps its trailing NUL padding but rejects embedded NUL; V2 aliases and all invoice and offer fields validate on both read and write so locally constructed messages cannot carry banned characters either. Tests cover each banned category, malformed UTF-8, and valid non-ASCII text.
In this commit, we centralize pending-channel cleanup in cleanupPendingChannel, which closes the local discovery signal, deletes the initial forwarding policy row and deletes the channel opening state row. All three steps are idempotent, so it is safe to call from several failure paths.

We invoke it when a confirmed funding transaction fails wallet validation, when the funding timeout fires, and when the funder receives an invalid funding_signed message. The timeout path also resolves the contract so the chain arbitrator stops watching the channel and the peer is pruned from persistent reconnects.

The access manager now re-creates a missing peer score from the persisted pending count on a pending close, so an offline peer's pending channel slot is released instead of leaking temporary access until restart. The backup proxy now treats FundingTimeoutEvent as a close so the timed-out channel is removed from the on-disk backup immediately.
Wrap over-length comments and log lines, convert counted loops to
integer ranges, use t.Context in tests, add a checked type assertion,
insert missing blank lines before returns, and reflow multi-line
statements so the native linter reports no findings on this branch.
The funding timeout handler pruned the peer's persistent connection
state unconditionally. A peer can have another open or pending channel
while one pending channel times out; pruning then dropped reconnect
state for a peer we still share a channel with. The brontide Start path
guards its prune with an open-channel count check; mirror that by asking
the access manager whether the peer has any open or pending channels
before pruning.
@ziggie1984
ziggie1984 force-pushed the morehouse-correctness-fixes branch from cff8b97 to 4d94fc6 Compare November 26, 2026 01:25
@ziggie1984
ziggie1984 requested a review from saubyk November 26, 2026 01:33

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

Thanks for working through all five. The release note now gives operators clear steps for the stricter text rules, and the new errors name the rejected character. LGTM from a product side.

@ziggie1984
ziggie1984 enabled auto-merge November 26, 2026 01:56
@ziggie1984
ziggie1984 added this pull request to the merge queue Nov 26, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 26, 2026
@ziggie1984
ziggie1984 added this pull request to the merge queue Nov 27, 2026
@ziggie1984 ziggie1984 added the backport-v0.21.x-branch This label triggers a backport to branch `v0.21.x-branch ` label Nov 27, 2026
Merged via the queue into lightningnetwork:master with commit e0055c8 Nov 27, 2026
32 checks passed
@github-actions

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-11632-to-v0.21.x-branch
git worktree add --checkout .worktree/backport-11632-to-v0.21.x-branch backport-11632-to-v0.21.x-branch
cd .worktree/backport-11632-to-v0.21.x-branch
git reset --hard HEAD^
git cherry-pick -x 4174c1c07779b2c1c90b89aa7a144a418a5078d5 67d26d85029f9675e5a611e86cf7f283056e88df 710a79e898beb6a4731340ca4ea9573efa7d417e 03d59d5cc0cc7a0cfc4fb742b75d04ae66bcdb3f 979648da2f226d203fe8035a4e88d48e5b14dcca d1ddf7cab1399808f0ddc28486968c82bdf950a4 62e730808c49ee197e826a843e357c44de5b3d18 dc22517552782dae2c6ebe2831e5ba63299c7190 bcafd9e847abaa086a0d8dd058ef3ae8c291a16d c6c09479722f0ba82d299b88728917780da7381c 4d94fc6500360ea5985a22a964e1dd38cfb85e07
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 ` severity-critical Requires expert review - security/consensus critical

Projects

None yet

3 participants