Skip to content

fix(p2p): drop the subscription count limits, list only digests held from startup on - #969

Merged
pablodeymo merged 1 commit into
release/v2.0.0from
backport/v2.0.0-pr-960
Dec 2, 2026
Merged

pablodeymo merged 1 commit into
release/v2.0.0from
backport/v2.0.0-pr-960

Conversation

@pablodeymo

Copy link
Copy Markdown
Collaborator

🗒️ Description / Motivation

Backport of #960 to release/v2.0.0, for v2.0.0-rc.2 (follow-up to #965 / #952).

#960 is approved and not merged on main yet, so this is taken from its head (fe9525a3) and not from a squash commit on main. If #960 changes before it merges, this branch has to be refreshed from the new head.

What Changed

The three commits of #960 as one commit on top of release/v2.0.0 (ae54a86e): the diff from its branch point on main (e48246f8) to its head (fe9525a3), applied with git apply --3way. It applied without conflicts and nothing was edited by hand (same git patch-id).

What it does, from #960:

  • Drops MaxCountSubscriptionFilter and the per-peer / per-RPC count limits (Allowlist implements TopicSubscriptionFilter directly). The per-peer limit was the size of the allowlist anyway, and the per-RPC limit made gossipsub refuse oversized RPCs at ERROR with no score penalty or disconnect.
  • Narrows Allowlist::beacon at startup to every digest still held at the startup digest's first epoch (ForkSchedule::held_at) and every later scheduled digest, warning and falling back to listing every scheduled digest if the startup digest is not on the schedule.
  • Shares Allowlist between gossipsub and P2PServer, and has beacon::transition::apply list a digest's topics (Allowlist::list, with a warning) before joining one that is not listed, so a backward clock jump across boundaries never leaves the node deaf.
  • Logs a SubscriptionError::NotAllowed on this node's own subscribe at ERROR in swarm_adapter.

Tests Added / Run

On this branch:

  • cargo fmt --all -- --check, make inert-paths-check, and cargo clippy --locked -p ethlambda-p2p --all-targets -- -D warnings: clean.
  • cargo test --locked -p ethlambda-p2p --lib --profile release-fast: 614 passed, 0 failed, 1 ignored.

Not run locally: the rest of make lint and make test; CI covers them.

Related Issues / PRs

…from startup on

Backport of #960 (at fe9525a) to release/v2.0.0.

Co-authored-by: Juan Bono <juan.bono@lambdaclass.com>
@pablodeymo

Copy link
Copy Markdown
Collaborator Author

/review

@pablodeymo

Copy link
Copy Markdown
Collaborator Author

Review notes

Same change as #960. This branch's patch is identical to #960 at its head (fe9525a3, same git patch-id), which is approved. It is one commit on top of release/v2.0.0 at ae54a86e, so CI here runs it against everything merged to the release branch today.

The commit added after #960's first review (the fix for the bot's M2, a clock stepped back across a fork boundary leaving the node deaf):

  • The allowlist is now a shared handle: gossipsub owns one clone as its filter, P2PServer keeps the other, and transition::apply lists a digest's topics before joining one that is not listed.
  • The list is still bounded. Only this node's own rollover adds to it, from its own clock and fork schedule, so a peer cannot grow it.
  • The topics are listed before the join is sent to the swarm, so gossipsub cannot refuse the join.
  • Covered by a_digest_the_clock_steps_back_to_is_listed_before_it_is_joined and a_topic_listed_later_can_be_joined_by_the_behaviour_holding_the_filter.

Release-branch fit. All three places that construct P2PServer set the new subscription_allowlist field. Build and Lint pass here.

The base is green. On ae54a86e, before this PR: cargo fmt --all -- --check, make lint and the full make test pass locally (5,008 passed, 0 failed). #954, #962 and #964 merged during the GitHub Actions outage with no CI run, so this is the first full run on that combination. This PR itself was not built locally; its own CI covers it.

Bot findings on #960. M2 is fixed by the commit above. M1 (one 12 MB RPC of unlisted topic names holds the swarm task for about 0.2 s) is accepted and documented in #960; the follow-up is sizing max_control_message_size from what other clients send.

One note, not a blocker. The shared list adds a lock read per topic in can_subscribe. On the worst-case RPC from M1 that is about a million uncontended reads on top of the existing pass. Estimated, not measured.

CI, as of this comment. Build, Lint, "Test (consensus)", "Test minimal preset" and "Beacon spec tests (minimal)" pass. "Test (node)", "Test (include-ethrex)" and "Beacon spec tests (mainnet)" are still running. "Link Check" failed on seven github.com links that returned 503 during the outage; it needs a re-run.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

AI security review: 3 finding(s) to check

Reviewed by Opus, GPT, Kimi, DeepSeek. A judge model checked every one of the findings against the code.
GLM (error, see the run log) did not finish; Opus, GPT, Kimi, DeepSeek reviewed the whole PR. Comment /review continue to retry, with a new budget; reviewers that finished are reused.

# Finding Severity Status Found by Where
M1 Backward-clock recovery does not restore existing peers' subscriptions medium Bug DeepSeek, Kimi (2/4) crates/net/p2p/src/beacon/transition.rs:173
M2 Removing per-RPC subscription count lets a peer stall the swarm task with oversized subscription hellos medium Bug DeepSeek (1/4) crates/net/p2p/src/lib.rs:1048
M3 The allowlist may not bound a peer's stored topic set: gossipsub may record topics from GRAFT without checking the subsc medium Suspected Opus (1/4) crates/net/p2p/src/subscription_filter.rs:76
Details

M1. Backward-clock recovery does not restore existing peers' subscriptions (medium, logic)

  • Trigger: A node starts after a digest has left the startup allowlist, and connected peers' subscriptions under that digest are rejected. The wall clock then steps back across a fork boundary, causing beacon::transition::advance to call apply for that older digest.
  • Mechanism: Allowlist::list only adds topic hashes to the local filter. Gossipsub discarded the peers' earlier subscriptions and peers send a subscription only once; apply does not request fresh subscriptions or disconnect peers to force a new hello. The status paths likewise only warn/drop sync claims on a digest mismatch and leave the connection intact. Nevertheless, apply records the newly listed digest as held and unsubscribes the topics it replaced.
  • Impact: Existing peers remain absent from gossipsub's stored topic set for the recovered digest, so they cannot be selected normally for its meshes or publish fanout. Gossip reception, block/attestation publication, and relaying can remain degraded until peers reconnect or happen to subscribe again, despite the rollover reporting the digest as joined.
  • Judge: Startup now omits older digests that the base branch allowed. After a sufficiently large clock rollback, list() restores only local allowlist membership, not previously discarded peer subscriptions. apply() nevertheless records the digest as held and leaves replaced topics; status mismatches do not force reconnection. Both reports' degraded-mesh/fanout claim holds, though complete isolation is not

M2. Removing per-RPC subscription count lets a peer stall the swarm task with oversized subscription hellos (medium, DoS/resource)

  • Trigger: A connected peer sends a gossipsub control RPC whose subscriptions field is padded up to max_control_message_size (~12 MB) with many short, unlisted topic names, and can repeat this on the connection.
  • Mechanism: The old Gossipsub type wrapped MaxCountSubscriptionFilter, which rejected an RPC after a per-request count check. The new type uses only Allowlist, whose can_subscribe performs membership checks after gossipsub has already decoded/copied the subscription entries on the swarm task. A max-size RPC therefore makes the swarm task churn through hundreds of thousands of entries (the PR's own comment says about 0.2 s), with no score penalty or disconnect for the sending peer.
  • Impact: The shared swarm event loop is stalled, delaying gossip forwarding, mesh heartbeats, and all other peers' traffic; a peer can repeat the oversized RPC to sustain the degradation.
  • Judge: The per-request count rejection is removed without reducing the approximately 12 MB control-frame limit. Subscription filtering now processes oversized batches synchronously while the shared swarm is polled, allowing repeated batches to delay other peers and commands. The byte cap bounds individual allocations but does not preserve event-loop responsiveness. The precise 0.2-second duration is only

M3. The allowlist may not bound a peer's stored topic set: gossipsub may record topics from GRAFT without checking the subscription filter (medium, DoS/resource)

  • Trigger: Any connected peer sends gossipsub control RPCs containing many GRAFTs, each naming a unique (or very long) topic that is not on the allowlist. They arrive in libp2p-gossipsub's handle_graft on the swarm task.
  • Mechanism: The PR, and the docs it updates, say the allowlist alone bounds what one peer holds and use that to justify removing the per-peer count limit. The filter only runs on SUBSCRIBE/UNSUBSCRIBE entries (filter_incoming_subscriptions) and on this node's own subscribe calls. From memory of libp2p-gossipsub, handle_graft starts with a loop ('if a peer has grafted us ... they must be subscribed to the topic. Ensure we have recorded the mapping') that inserts every GRAFTed topic into the peer's stored topic set. That loop runs before the GRAFT is checked against this node's mesh, and it never consults the subscription filter. GRAFTs for unknown topics are then ignored without any score penalty. If that is still true in 0.50.0, a peer can grow its stored topic set without limit through GRAFT for as long as it stays connected, which is exactly the growth the allowlist is meant to stop. This existed before the PR: the old MaxCountSubscriptionFilter limits applied only to subscription RPCs, not to GRAFT.
  • Impact: A single connected peer could grow this node's memory at roughly the rate of the bandwidth it sends, retained until it disconnects, which could end in an OOM. The safety argument the PR relies on would not hold.
  • Judge: The local filter supplies only can_subscribe(), so it cannot itself prevent a separate GRAFT path from inserting topics. However, the pinned libp2p-gossipsub source is unavailable locally, so the claimed handle_graft insertion and retention behavior cannot be confirmed. If that bypass exists, it would also affect the base branch's subscription-only count filter and would be pre-existing.

Cost of this review: ~$2.28 of a $30 budget (estimated from token counts).

@pablodeymo

Copy link
Copy Markdown
Collaborator Author

On the AI review's three findings

No code change from any of them. M1 and M2 are known and accepted, and M3 does not hold for the gossipsub version this branch pins.

M1 (after a clock step back, connected peers are not recorded on the re-listed digest)

True, and documented where the list is extended (Allowlist::list and the commit that added it).

  • It needs the clock to step back across a fork boundary, to before the digests listed at startup.
  • Before that commit the node was deaf on the digest until a restart. Now it joins the digest, and its meshes fill as peers connect or subscribe again.
  • Forcing fresh subscriptions would mean disconnecting every peer at that moment. That is not done here.

Accepted as a limit of the recovery, not a regression: the node is no worse off than a node that has just started.

M2 (a 12 MB subscription RPC holds the swarm task)

The same finding as M1 on #960, answered there: #960 (comment)

In short: putting MaxCountSubscriptionFilter back bounds one RPC, not the work a peer can cause, and brings back an ERROR line a peer can write at will. The cost is about 0.2 s for one RPC of a million short names, measured on a copy of the pass, not in a running node. Accepted; the follow-up is sizing max_control_message_size from what other clients send.

M3 (GRAFT may record topics without going through the filter)

Not the case in libp2p-gossipsub 0.50.0, which Cargo.lock pins. Checked against its source (src/behaviour.rs):

  • A peer's stored topic set (PeerDetails::topics) is written in one place only, the subscription handler, and only for the entries the filter let through (for subscription in filtered_topics { ... peer.topics.insert(...) }).
  • handle_graft reads the peer with connected_peers.get, not get_mut, and for a topic this node has no mesh for it logs and continues ("spam hardening: ignore GRAFTs for unknown topics"). It stores nothing for it.

The loop the finding describes from memory ("ensure we have recorded the mapping") is not in this version. So the allowlist does bound a peer's stored topic set, as the PR says.

@pablodeymo
pablodeymo merged commit a50a634 into release/v2.0.0 Dec 2, 2026
18 of 20 checks passed
@pablodeymo
pablodeymo deleted the backport/v2.0.0-pr-960 branch December 2, 2026 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants