Skip to content

discovery: account for future gossip memory - #11158

Open
moscowchill wants to merge 2 commits into
lightningnetwork:masterfrom
moscowchill:fix/account-future-gossip-memory
Open

discovery: account for future gossip memory#11158
moscowchill wants to merge 2 commits into
lightningnetwork:masterfrom
moscowchill:fix/account-future-gossip-memory

Conversation

@moscowchill

@moscowchill moscowchill commented Sep 1, 2026

Copy link
Copy Markdown

Change Description

The future gossip cache currently charges each decoded message as one unit. A ChannelAnnouncement1 feature vector can decode into 65,536 map entries, so the existing 1,000-message limit does not bound the memory retained by the cache.

This PR converts the cache to a retained-memory budget while preserving the existing upper bound of 1,000 ordinary messages. Every future message receives a conservative maximum-wire-body charge, and decoded channel-announcement feature entries receive an additional per-entry charge. A maximally dense announcement therefore consumes 1,114,109 cache bytes and the production cache retains at most 58 such objects.

Validation order, replay behavior, and monotonic cache keys remain unchanged. The change is scoped to bounding retained cache state; transient decoding work remains subject to the existing gossip processing limits.

Steps to Test

go test ./discovery -count=1
go test ./lnwire -count=1
go test -race ./discovery -run '^(TestFutureChanAnnCacheBounds|TestFutureMsgCacheEviction|TestPrematureAnnouncementProcessing)$' -count=10

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative error paths are included.
  • The bug fix contains a test exercising weighted admission and eviction.

Code Style and Documentation

  • The change is substantial and focused.
  • The change follows the code documentation and 80-column guidelines.
  • The commit follows the ideal Git commit structure.
  • New logging uses an appropriate subsystem and level.
  • No lncli command is added.
  • A release-note entry is included.

Future gossip entries currently have a constant cache cost even when a decoded channel announcement retains a dense feature map.

Charge a maximum wire body per message plus each decoded feature-map entry, preserving the ordinary message count while bounding dense retained state.

Signed-off-by: moscowchill <gasgeverij@proton.me>
Signed-off-by: moscowchill <gasgeverij@proton.me>
@moscowchill
moscowchill marked this pull request as ready for review September 1, 2026 18:22
@github-actions github-actions Bot added the severity-high Requires knowledgeable engineer review label Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

🟠 PR Severity: HIGH

gh pr diff | 3 files | 155 lines changed

🟠 High (1 file)
  • discovery/gossiper.go - modifies the future gossip message cache admission/eviction logic in the gossip protocol subsystem
🟢 Low (2 files)
  • discovery/gossiper_test.go - test-only changes
  • docs/release-notes/release-notes-0.22.0.md - release notes

Analysis

The core change is in discovery/gossiper.go, which falls under discovery/* (gossip protocol) — classified HIGH. It changes how the future-message cache accounts for memory (switching from a per-message count limit to a retained-memory budget) to bound worst-case memory usage from densely-packed ChannelAnnouncement1 feature vectors. This affects cache admission/eviction behavior in a core gossip component, warranting review by an engineer familiar with the gossip subsystem. No file-count or line-count bump thresholds were crossed (only 1 non-test/non-doc file, ~48 non-test lines changed), and no other critical packages are touched.


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

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

Labels

severity-high Requires knowledgeable engineer review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant