Skip to content

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

Merged
pablodeymo merged 4 commits into
mainfrom
fix/924-allowlist-only
Dec 2, 2026
Merged

pablodeymo merged 4 commits into
mainfrom
fix/924-allowlist-only

Conversation

@juanbono

@juanbono juanbono commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

🗒️ Description / Motivation

Follow-up to #952, which merged before these review fixes were pushed.

  • The count limits refused nothing useful and cost an error-log flood. The per-peer limit was the size of the allowlist, which the allowlist already enforces, so it could never refuse anything. The per-RPC limit made gossipsub refuse an oversized RPC with an error it logs at ERROR, with no score penalty and no disconnect, so any connected peer could write error lines at will. A filter of our own cannot make that refusal quiet: the method it would override takes gossipsub's Subscription, which the crate does not export.
  • The beacon allowlist listed every digest since genesis. It only needs the digests this node can still hold.

What Changed

  • crates/net/p2p/src/subscription_filter.rs: Allowlist implements TopicSubscriptionFilter itself and is the whole filter. MaxCountSubscriptionFilter, into_filter and the limit constants are gone. Allowlist::beacon lists every digest still held at the startup digest's first epoch (ForkSchedule::held_at) and every later one: on mainnet, the current and the previous digest. Held sets only move forward, so this covers everything the node can hold for the rest of its run, including several earlier digests at once on a devnet whose boundaries are closer together than UNSUBSCRIBE_LAG_EPOCHS. A startup digest not on the schedule falls back to listing every digest.
  • crates/net/p2p/src/lib.rs: the Gossipsub alias and build_swarm take the Allowlist directly.
  • crates/net/p2p/src/beacon/scoring.rs: the test's control digest moves from genesis's to electra's, since genesis's is no longer listed for a node starting at fulu.
  • CLAUDE.md, docs/beacon_wire.md: describe the allowlist alone, its new range, and why there is no count limit.

Correctness / Behavior Guarantees

Tests Added / Run

  • every_digest_held_from_startup_on_is_listed: from start epochs around dense and sparse boundaries, every digest held_at returns is listed.
  • a_digest_left_before_startup_is_not_listed: the dense case explicitly, plus mainnet-like spacing. Both fail on an earlier draft that listed only the previous digest.
  • a_hello_padded_with_unlisted_topics_keeps_its_listed_one replaces the per-RPC limit test: 10,000 unlisted topics plus one listed, and only the listed one is recorded.
  • cargo test -p ethlambda-p2p --lib --profile release-fast: 623 passed, 1 ignored (on current main).

Related Issues / PRs

✅ Verification Checklist

  • Ran make fmt — clean
  • Ran make lint (clippy with -D warnings) — clean
  • Ran make test (test-consensus, test-node and test-ethrex, at release-fast) — only ethlambda-p2p

…from startup on

Follows up the review of #952.

The per-peer limit was the size of the allowlist, which the allowlist
already enforces, so it could never refuse anything. The per-RPC limit made
gossipsub refuse an oversized RPC with an error it logs at ERROR and does
not penalize, so any connected peer could write error lines at will. A
filter of our own cannot make that refusal quiet: the method it would
override takes gossipsub's `Subscription`, which the crate does not export.
The filter is now the allowlist alone (`Allowlist` implements
`TopicSubscriptionFilter`); `into_filter` and the limit constants are gone.

The beacon allowlist no longer lists every digest of the schedule. It lists
every digest still held at the startup digest's first epoch
(`ForkSchedule::held_at`) and every later one: on mainnet, the current and
the previous digest. Held sets only move forward, so this covers everything
the node can hold for the rest of its run, including several earlier
digests at once on a devnet whose boundaries are closer together than
`UNSUBSCRIBE_LAG_EPOCHS`.

Tests: every digest held from startup on is listed, from start epochs
around dense and sparse boundaries; a digest left before startup is not;
a hello padded with 10,000 unlisted topics keeps its listed one (replacing
the per-RPC limit test); the scoring test's control digest moves to
electra's, since genesis's is no longer listed.
@pablodeymo

Copy link
Copy Markdown
Collaborator

/review

… join loud, test the allowlist on blob-parameter digests

Follow-ups from a review of this PR.

The per-RPC note said the filter's pass over an RPC is "one hash lookup
each, no more than decoding them cost". Before the allowlist sees an RPC's
subscriptions, gossipsub copies every topic name in it into a map, on the
swarm task: about 0.15 us an entry, some 0.2 s for an RPC filled to
`max_control_message_size` with a million short names (measured on a copy of
that pass, not in a running node). The limit is still left out: it bounds
how long one RPC holds the swarm task, not the work, since the same names
split over RPCs under it cost the same in total. The module doc and
`docs/beacon_wire.md` now say this, and name `max_control_message_size` as
what would shorten the stall.

The allowlist is fixed at startup while the rollover follows the clock, so a
clock stepped back to before the listed digests has the rollover join a
digest gossipsub refuses. The swarm adapter now logs a join the filter
refused at `ERROR`, saying the node hears nothing on the topic; it was a
generic warning. The docs state the assumption.

A start digest that is not on the schedule lists every scheduled digest.
That exists for tests on a made-up digest, and now logs a warning, since
outside a test it means the digest and the schedule disagree.

The docs also say the listed range starts at the start digest's first epoch,
not the node's start epoch, so the previous digest stays listed.

Tests, both on mainnet's own schedule, whose current digest is a
blob-parameter one, with expectations written from the config's epochs:
- `a_start_on_a_blob_parameter_digest_lists_it_and_the_one_before`
- `a_node_on_a_scheduled_digest_keeps_nothing_under_one_the_chain_left`, at
  swarm level: until now every swarm-level test ran on a made-up digest and
  so only on the list-everything fallback.
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

AI security review: 1 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 Removal of per-RPC subscription count allows CPU exhaustion from connected peers medium Suspected DeepSeek (1/4) crates/net/p2p/src/subscription_filter.rs:55
Details

M1. Removal of per-RPC subscription count allows CPU exhaustion from connected peers (medium, DoS/resource)

  • Trigger: Any connected peer sends repeated gossipsub RPCs filled with up to MAX_COMPRESSED_PAYLOAD_SIZE (~12 MiB) of subscription entries. The input reaches gossipsub's inbound subscription handling on the swarm task; no peer scoring penalty or disconnect applies to ordinary subscription messages.
  • Mechanism: This filter replaces libp2p's MaxCountSubscriptionFilter, which previously rejected an RPC whose subscription count exceeded max_subscriptions_per_request before the allowlist scan. With only can_subscribe implemented, the default filter applies a hash-set membership check to each decoded subscription entry on the swarm adapter's single event loop. max_control_message_size (crates/net/p2p/src/lib.rs:1329) bounds RPC bytes but not entry count, so one 12 MiB message can carry hundreds of thousands of short topic entries, and an attacker can send such messages continuously. On the lean wire there is additionally no connection ceiling (unlimited_connections), so this can be amplified across many peers.
  • Impact: A connected peer can force large decoding/allocation and subscription-filter CPU work on the swarm task, delaying or starving gossip processing, request/response handling, and peer-scoring timers.
  • Judge: The PR removes the early subscription-count rejection, permitting larger allowlist passes on the shared swarm task. However, decoding/allocation of large RPCs and unlimited lean connections already existed on the base. The additional byte-bounded filtering work plausibly increases CPU pressure, but I could not confirm the claimed starvation or a new CPU-exhaustion vulnerability from the available

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

@pablodeymo

Copy link
Copy Markdown
Collaborator

Review follow-ups pushed to this branch (11a3b1b9)

I reviewed this PR and pushed one commit on top of yours with the fixes that did not need a design decision. Summary of what it does, and what I left for you.

In the commit

  • Per-RPC limit: the explanation, not the design. The doc said the filter's pass is "one hash lookup each, no more than decoding them cost". Before the allowlist sees an RPC's subscriptions, gossipsub's default filter_incoming_subscriptions copies every topic name into a map, on the swarm task. On a copy of that pass: about 0.15 µs an entry, some 0.2 s for an RPC filled to max_control_message_size (12 MB) with a million short names. Measured standalone on a laptop, not in a running node. I kept the limit out: it bounds how long one RPC holds the swarm task, not the work, since the same names split over RPCs under the limit cost the same in total. The module doc and docs/beacon_wire.md now say this.

  • A join the filter refuses is logged at ERROR. The allowlist is fixed at startup and the rollover follows the clock, so a clock stepped back to before the listed digests has transition::apply join a digest gossipsub refuses, and the node is deaf on it until a restart. It takes a step back across two boundaries (the previous digest is always listed), so this only makes the case visible. The docs state the assumption.

  • The every-digest fallback warns. A start digest that is not on the schedule still lists every digest, which the tests on [0u8; 4] rely on, but it now logs a warning.

  • Docs: the listed range starts at the start digest's first epoch, not the node's start epoch, so the previous digest stays listed however long ago the chain left it.

  • Two tests on mainnet's own schedule, where the current digest is a blob-parameter one, with expectations written from the config's epochs rather than read from held_at:

    • a_start_on_a_blob_parameter_digest_lists_it_and_the_one_before
    • a_node_on_a_scheduled_digest_keeps_nothing_under_one_the_chain_left, at swarm level. Until now every swarm-level test ran on a made-up digest, so only on the fallback.

    Both fail when the allowlist is made to list every digest. cargo test -p ethlambda-p2p --lib --profile release-fast: 625 passed, 1 ignored. Clippy and fmt clean for the crate.

Left for you

  • impl TopicSubscriptionFilter for Allowlist is libp2p's WhitelistSubscriptionFilter line for line. The Gossipsub alias could take that type, with Allowlist as its builder. Your call.
  • first_held is found in four steps (find the entry, held_at, first element, search for its index). A ForkSchedule method returning the first held index at an epoch would shorten it without repeating the rule.
  • max_control_message_size is what would actually shorten the worst stall, with no error logging. It is set to the 12 MB frame bound because an honest hello around a boundary and a large IHAVE both pass the 16 KiB default. A value between the two needs interop data, since an RPC over it closes the stream. I only documented it.

@pablodeymo

Copy link
Copy Markdown
Collaborator

/review

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

AI security review: 2 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 Removing MaxCountSubscriptionFilter lets a peer force large subscription-RPC processing on the shared swarm task medium Suspected DeepSeek (1/4) crates/net/p2p/src/lib.rs:1041
M2 Backward clock correction can permanently refuse the current fork’s topics low Bug Opus, DeepSeek, GPT, Kimi (4/4) crates/net/p2p/src/subscription_filter.rs:122
Details

M1. Removing MaxCountSubscriptionFilter lets a peer force large subscription-RPC processing on the shared swarm task (medium, DoS/resource)

  • Trigger: Any connected gossipsub peer repeatedly sends 12 MB subscription RPCs filled with many short, unlisted topic names.
  • Mechanism: The Gossipsub behaviour now uses the direct Allowlist filter rather than MaxCountSubscriptionFilter, so there is no per-RPC count limit. The code documents that before can_subscribe() runs, libp2p-gossipsub's default filter_incoming_subscriptions pass copies every incoming subscription name into a map on the shared swarm task; max_control_message_size (12 MB) bounds bytes but not entry count, allowing roughly a million short entries in one RPC. Each such RPC can stall the swarm task for hundreds of milliseconds, and the peer is not scored or disconnected for doing this.
  • Impact: A connected attacker can degrade or deny gossipsub processing for all peers, impeding block/attestation propagation and potentially causing slow-peer disconnections of honest peers.
  • Judge: The PR removes the subscription-count wrapper, retains the approximately 12 MB RPC limit, and polls the swarm on one shared task. However, libp2p-gossipsub's dependency source was unavailable locally, so I could not independently verify the default map-building path, scoring behavior, or claimed live-node stalls. The repository comment reports only a standalone measurement; the denial-of-service i

M2. Backward clock correction can permanently refuse the current fork’s topics (low, logic)

  • Trigger: A beacon node starts while its wall clock is ahead and NTP or the operator subsequently corrects it backward to an epoch whose digest precedes the earliest digest retained by this slice. The same failure occurs on any later backward clock step across that boundary, which is only a few epochs on a dense devnet.
  • Mechanism: The allowlist permanently omits every schedule entry before first_held. beacon::transition::advance rereads SystemTime and apply computes held_at for the corrected epoch, then sends subscriptions for those older digests through the same Allowlist. swarm_adapter::execute_command receives SubscriptionError::NotAllowed, logs it, and does not retry. Nevertheless, apply inserts the rejected BeaconTopics into kept, assigns them to wire.topics/window_topics, and unsubscribes the previously held topics, so its state says the rejected joins succeeded.
  • Impact: After the clock correction, the node leaves its working meshes but hears and publishes nothing on the actual current digest, including dynamic aggregator and sync-committee subnets. It can remain unable to follow gossip until restarted or until the wall clock returns to a listed digest range.
  • Judge: A rollback into an excluded digest is reachable when a pending rollover timer rereads the corrected wall clock. The static allowlist rejects that digest's joins, but transition::apply records them as held, removes obsolete subscriptions, and switches the current digest without receiving subscription results. Later transitions retain those recorded topics without retrying. The base allowed every sc

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

…wlist lacks

The allowlist is built at startup for a clock that only moves forward: the
digests still held at the start digest's first epoch, and every later one.
The same filter gates this node's own joins. A clock stepped back to before
those digests has `transition::apply` join one that is not listed, which
gossipsub refuses, while `apply` records it as held and leaves the topics the
node was on. The node then hears and publishes nothing until a restart. The
last commit made that case loud; this one removes it.

`Allowlist` is now a handle on a shared list. Gossipsub owns one clone as its
filter, `BuiltSwarm` hands the other to the `P2PServer`, and `apply` lists a
digest's topics (`Allowlist::list`) before joining one that is not on the
list, with a warning. The list grows only by a digest the node itself joins,
which the schedule bounds, so what a peer can make this node store is bounded
as before.

A digest listed that late starts with no peer recorded on it: subscriptions
peers sent while it was unlisted were dropped and are not sent again, so its
meshes fill as peers connect or subscribe again.
@pablodeymo

Copy link
Copy Markdown
Collaborator

On M1 (large subscription RPCs hold the swarm task)

No code change for this one. It is the trade-off the PR already documents, and I checked the three ways out against libp2p-gossipsub 0.50.0:

  • A filter of our own cannot refuse an oversized RPC early and quietly. The method to override, TopicSubscriptionFilter::filter_incoming_subscriptions, takes &[Subscription], and types::Subscription is not in the crate's pub use list, so the signature cannot be written outside it.
  • Putting MaxCountSubscriptionFilter back bounds one RPC, not the work. Its length check does run before the map is built, so an RPC over the limit costs nothing. But the same names split over RPCs under the limit go through the same pass, so what a peer can make the swarm task spend is bounded by the bytes it sends either way. And each refused RPC is logged by gossipsub at ERROR ("Subscription filter error ... ignoring RPC from peer") and then dropped, with no score penalty and no disconnect, so a peer can write those lines at will. That is the flood this PR removes.
  • max_control_message_size is what shortens the stall, with no logging. It is 12 MB here against a default of 16 KiB. I would not lower it without interop data: an RPC over it fails to decode and its stream is closed, and an honest IHAVE from a peer sharing many subnets can be large. A rough estimate, not a measurement, puts that in the hundreds of KB.

So the finding stands as described (about 0.2 s for one RPC filled with a million short names, measured on a copy of the pass, not in a running node) and is accepted for now. The follow-up is sizing max_control_message_size from what other clients actually send.

On M2 (a clock stepped back leaves the node deaf)

Fixed in fe9525a3.

The allowlist is built at startup for a clock that only moves forward, and the same filter gates this node's own joins. A clock stepped back past the listed digests had the rollover join a digest gossipsub refuses, record it as held, and leave the topics it was on.

Allowlist is now a handle on a shared list: gossipsub owns one clone as its filter and P2PServer keeps another. transition::apply lists a digest's topics (Allowlist::list) before joining one that is not listed, and logs a warning. The list grows only by digests the node itself joins, which the schedule bounds, so the bound on what a peer can make this node store is unchanged.

One limit: a digest listed that late starts with no peer recorded on it. Subscriptions peers sent while it was unlisted were dropped and are not sent again, so its meshes fill as peers connect or subscribe again.

Tests: a_digest_the_clock_steps_back_to_is_listed_before_it_is_joined (rollover, back across two boundaries) and a_topic_listed_later_can_be_joined_by_the_behaviour_holding_the_filter (a real gossipsub behaviour refuses the join before the listing and takes it after). make lint and make test-node pass locally (2,893 passed, 0 failed).

@pablodeymo

Copy link
Copy Markdown
Collaborator

/review

@pablodeymo
pablodeymo enabled auto-merge December 2, 2026 18:52
pablodeymo added a commit that referenced this pull request Dec 2, 2026
…s, within a count limit (#965)

## 🗒️ Description / Motivation

Backport of #952 (`64ba9d51` on `main`) to `release/v2.0.0`, for
`v2.0.0-rc.2`.

## What Changed

`git cherry-pick -x 64ba9d5` on top of `release/v2.0.0` (`7d5e9f22`).
It applied without conflicts, and the patch is identical to the one
merged on `main` (same `git patch-id`). Nothing was edited by hand.

**Not the final shape of this fix.** #960 (approved, not merged yet)
reworks it: it drops the two count limits this backport carries and
narrows the allowlist to the digests held from startup on. #960 needs
its own backport once it merges on `main`, before rc.2 is tagged. Until
then the release branch has the count limits, under which gossipsub logs
every over-limit RPC at `ERROR`.

## Tests Added / Run

Run on the four backports together (#950, #951, #955, #952 on top of
`7d5e9f22`; that tree is the same one a merge of `main` at `64ba9d51`
into the release branch gives):

- `cargo fmt --all -- --check` and `make lint`: clean.
- `cargo test -p ethlambda-validator -p ethlambda-blockchain -p
ethlambda-p2p --profile release-fast`: 2,043 passed, 0 failed, including
the tests #952 added.

This branch alone was not built locally; CI covers it.

## Related Issues / PRs

- Original: #952.
- The other backports for rc.2: #950, #951, #955, #952 (one PR each,
because the repository squashes and the release changelog has one line
per commit). The four touch no file in common and can merge in any
order.
- Release checklist: #943.
@pablodeymo
pablodeymo added this pull request to the merge queue Dec 2, 2026
pablodeymo added a commit that referenced this pull request Dec 2, 2026
…from startup on (#969)

## 🗒️ 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

- Original: #960 (follows up #952 / #924).
- Backport of #952 on `release/v2.0.0`: #965.
- Release checklist: #943.

Co-authored-by: Juan Bono <juan.bono@lambdaclass.com>
Merged via the queue into main with commit 8f2a09e Dec 2, 2026
14 checks passed
@pablodeymo
pablodeymo deleted the fix/924-allowlist-only branch December 2, 2026 20:20
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