← Back to Pull requests

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

Merged
Roasbeef merged 32 files (1792 lines) on Nov 27, 2026 21:31 UTC
View on GitHub
Roasbeef Roasbeef commented on Nov 25, 2026 03:12 UTC
Author

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

  • Fixes #11598: netann now rejects channel_announcement messages whose node_id_1 is not lexicographically before node_id_2, as BOLT 7 requires. The check runs before signature validation, so invalid announcements are rejected cheaply.

  • Fixes #11608: channels whose remote HTLC constraints cannot produce a valid channel_update (minimum HTLC above capacity, zero max pending amount) are rejected during funding, and our advertised minimum HTLC is capped at the usable maximum.

  • Fixes #11616: pending-open channels that fail validation, time out, or receive an invalid funding_signed now release all pinned state: the local discovery signal, the initial forwarding policy row, the channel opening state row, the chain arbitrator's watch, on-disk backups, and access-manager pending counts. Persistent connection state is only pruned when the peer has no remaining channels.

  • Fixes #11618: BOLT 1 text rules (control, format, private-use, surrogate characters, and line/paragraph separators; unassigned code points tolerated) are enforced on node aliases, BOLT 11 descriptions, and BOLT 12 offer descriptions, issuers, and payer notes, on both read and write. The fixed-width V1 alias keeps its trailing NUL padding but rejects embedded NUL.

  • Fixes #11626: our own local announcement proofs are never deferred into the evictable in-memory future message cache, where a restart would lose them; only remote proofs are deferred. Local proofs go straight to the durable waiting-proof store.

  • Fixes #11628: the future message cache now charges each message a conservative retained-memory cost (bounded below by the previous count-based limit) and evicts by that budget, so decoded feature maps cannot grow it without bound.
  • 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.
  • Diff: 1792 lines (+1629 / -163) across 32 files Reviewer: ziggie1984 Review duration: 3979m
    All Vouch review confidence checks passed
    Residual risk 0.06 = Change Risk (0.72) × (1 − Review Confidence (0.92)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.72 · 1792 lines diff across 32 files
    0.72
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.92 · 5 substantive comment(s)
    0.92
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    91%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Mass File Touch mass_file_touch
    0.080
    Real PR Conversation Timeline
    13 items
    github-actions[bot] github-actions[bot] commented on Nov 25, 2026 03:27 UTC
    Bot

    🔴 PR Severity: CRITICAL

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

    <details>
    <summary>🔴 <strong>Critical</strong> (4 files)</summary>

  • 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
  • </details>

    <details>
    <summary>🟠 <strong>High</strong> (1 file)</summary>

  • discovery/gossiper.go - gossip protocol handling
  • </details>

    <details>
    <summary>🟡 <strong>Medium</strong> (6 files)</summary>

  • 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
  • </details>

    <details>
    <summary>🟢 <strong>Low</strong> (1 file)</summary>

  • docs/release-notes/release-notes-0.22.0.md - release notes
  • </details>

    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.

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

    ziggie1984 ziggie1984 commented on Nov 25, 2026 18:06 UTC
    Contributor

    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 approved these changes on Nov 25, 2026 21:37 UTC
    Approved Reviewer

    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 commented on code on Nov 26, 2026 00:07 UTC
    Code Review
    docs/release-notes/release-notes-0.22.0.md:1
    @@ -22,6 +22,32 @@
     
     # Bug Fixes
     
    +* Channel announcement validation now rejects node IDs that are not

    Could these entries move to docs/release-notes/unreleased/11632.md, each linking to this PR? The release-notes check rejects edits to the version file and entries without a PR link.

    saubyk saubyk commented on code on Nov 26, 2026 00:08 UTC
    Code Review
    zpay32/decode.go:1
    @@ -83,6 +83,22 @@ func newDecodeOptions() *decodeOptions {
     func Decode(invoice string, net *chaincfg.Params, opts ...DecodeOption) (
     	*Invoice, error) {
     
    +	return decode(invoice, net, lnwire.ValidBoltText, opts...)

    This matches the spec (lightning/bolts#1341 says readers MUST fail the payment), but lnd would be the first to enforce it. Today CLN, Eclair and LDK only check that the description is valid UTF-8, so they still create and pay invoices with newlines. CLN (ElementsProject/lightning#9398) and Eclair (ACINQ/eclair#3329) have open PRs to reject them; I couldn't find one for LDK. Once this ships, lnd users can't pay any of those invoices, or invoices from older lnd, while other wallets still can. The spec discussion measured gossip impact but not invoices.

    Should we plan the rollout for that period? For example, warn about it in the release note, or decode leniently for a release while enforcing on the writer side. Separately, the user sees "description is not valid UTF-8", which is inaccurate for valid UTF-8. Could the error name the rejected character?

    saubyk saubyk commented on code on Nov 26, 2026 00:08 UTC
    Code Review
    lnwire/lnwire.go:1
    @@ -50,6 +52,62 @@ const (
     	dnsAddrOverhead = 3
     )
     
    +// ValidBoltText reports whether data is valid UTF-8 text per the BOLT 1
    +// reader requirements: it contains no character from the Cc, Cf, Cs or Co
    +// general categories, and neither the line separator U+2028 nor the
    +// paragraph separator U+2029. Unassigned code points (Cn) are tolerated so
    +// strings using characters from Unicode versions newer than Go's tables
    +// keep working.
    +func ValidBoltText(data []byte) bool {
    +	if !utf8.Valid(data) {
    +		return false
    +	}
    +
    +	for _, r := range string(data) {
    +		if unicode.Is(unicode.Cc, r) || unicode.Is(unicode.Cf, r) ||

    Dropping remote announcements with these aliases matches BOLT 7 (MUST ignore), and t-bast's mainnet scan on lightning/bolts#1341 found only 9 affected nodes. Local behaviour still needs attention, though. Cf includes the zero-width joiner (U+200D) used in emoji like 👨‍💻, so after upgrading:

  • Configured alias=: lnd fails at startup with "invalid configured alias: node alias has non-utf8 characters". That's misleading, since the alias is valid UTF-8.

  • Alias set via peersrpc.UpdateNodeAnnouncement: it is silently replaced on the network with the hex pubkey, with only a WARN log.
  • Can the error name the rejected character, and can the release note warn about the startup failure and the alias reset?

    saubyk saubyk commented on code on Nov 26, 2026 00:08 UTC
    Code Review
    funding/manager.go:1
    @@ -3809,6 +3853,11 @@ func (f *Manager) extractAnnounceParams(c *chanstate.OpenChannel) (
     		fwdMaxHTLC = capacityMSat
     	}
     
    +	// MinHTLCOut is our preference, not a constraint imposed by the
    +	// peer. Do not let it raise the advertised minimum above the
    +	// remote's maximum.
    +	fwdMinHTLC = min(fwdMinHTLC, fwdMaxHTLC)

    If bitcoin.minhtlc or openchannel --min_htlc_msat is above the remote's maximum, the advertised minimum is capped here with no log line. Could we log when this happens, so operators know their setting wasn't applied? Fine as a follow-up.

    saubyk saubyk commented on code on Nov 26, 2026 00:08 UTC
    Code Review
    docs/release-notes/release-notes-0.22.0.md:1
    @@ -22,6 +22,32 @@
     
     # Bug Fixes
     
    +* Channel announcement validation now rejects node IDs that are not
    +  lexicographically ordered, as BOLT 7 requires, instead of accepting and
    +  relaying invalid gossip.
    +
    +* Channels whose remote HTLC constraints cannot yield a valid `channel_update`
    +  are now rejected during funding, and our minimum-HTLC preference is capped at
    +  the usable maximum, so accepted channels no longer get stuck before their
    +  announcement.
    +
    +* Our own `announcement_signatures` halves are no longer kept in the evictable,
    +  in-memory premature-gossip cache, so they can no longer be lost on restart or
    +  eviction when `gossip.announcement-conf` is set above the default. The cache
    +  now also charges for decoded feature-map memory, bounding what a single peer
    +  can pin.
    +
    +* BOLT text fields (node aliases, BOLT 11 descriptions, and BOLT 12 offer

    This entry describes the change in spec terms only. Could it add a plain-language line for operators: emoji that use zero-width joiners and newlines in invoice memos are no longer accepted, an invalid configured alias now stops startup, and a stored alias may be reset to the pubkey default?

    saubyk saubyk commented on Nov 26, 2026 00:18 UTC
    Reviewer

    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.

    ziggie1984 ziggie1984 commented on code on Nov 26, 2026 01:23 UTC
    Code Review
    docs/release-notes/release-notes-0.22.0.md:1
    @@ -22,6 +22,32 @@
     
     # Bug Fixes
     
    +* Channel announcement validation now rejects node IDs that are not

    Thanks, Suheb. I’ve prepared a local update for these comments:

  • Moved the release notes to docs/release-notes/unreleased/11632.md and linked each entry to this PR. Both release-note checks pass locally.

  • Kept strict BOLT 11 decoding and chose the release-note warning for rollout. The note explains that older invoices with disallowed characters such as newlines may need to be reissued. Invoice description and alias errors now identify the disallowed Unicode code point.

  • The note calls out that an invalid configured alias prevents startup and that an invalid stored alias falls back to the public-key-derived default. The fallback warning now includes the validation error.

  • Funding now logs the original and capped values when it lowers the advertised minimum HTLC.
  • The targeted Go tests and native lint, including staticcheck, pass. The changes are still local.

    saubyk saubyk approved these changes on Nov 26, 2026 01:54 UTC
    Approved Reviewer

    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.

    github-actions[bot] github-actions[bot] commented on Nov 27, 2026 21:32 UTC
    Bot

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

  • #11651 with remaining conflicts!
  • 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
    

    Reviewers
    Assignees
    Roasbeef Roasbeef
    Labels
    risk: low confidence: 91.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 71.5% (HIGH) · Higher = larger blast radius
    71.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 91.9% · Lower = rushed or shallow review
    91.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 5.8% · Safe to merge
    5.8%