Skip to content

fix(p2p): keep a peer's gossipsub subscriptions only for listed topics, within a count limit - #965

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

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

Conversation

@pablodeymo

Copy link
Copy Markdown
Collaborator

🗒️ 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 64ba9d51 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):

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

Related Issues / PRs

…s, within a count limit (#952)

## 🗒️ Description / Motivation

Closes #924.

Gossipsub stores every topic a peer subscribes to until the peer
disconnects, and a topic is stored under its name. Both wires ran
`AllowAllSubscriptionFilter`, so one connected peer could grow this
node's memory without limit, with ever more topics or with names
megabytes long. Nothing else bounded it: an RPC is only capped by the 12
MB frame, and peer scoring does not look at subscriptions.

This puts an allowlist inside a count limit, as the issue proposes and
as Lighthouse does. The allowlist is what bounds a peer's stored topics;
the count limit is per RPC.

## What Changed

- **`crates/net/p2p/src/subscription_filter.rs` (new):** the filter both
wires run, `MaxCountSubscriptionFilter<WhitelistSubscriptionFilter>`,
and the `Allowlist` it is built from.
- **Beacon:** every global kind and every data column, attestation and
sync committee subnet, under every digest of the `ForkSchedule` (fork
and blob-parameter boundaries; gloas's four kinds under gloas digests
only). Built once at startup from the whole schedule, so the next
digest's topics are listed before peers join them.
- **Lean:** `block`, `aggregation` and every `attestation_{n}` below
both the committee count and `VALIDATOR_REGISTRY_LIMIT` (no validator id
reaches it, so no subnet past it is published on), plus any subnet the
node was told to subscribe to.
- **Limits:** one peer may hold every listed topic, so the per-peer
count never refuses anything and the allowlist is the bound; one RPC may
carry twice the allowlist's entries, and never fewer than 500.
- **`beacon/topics.rs`:** `every_topic(fork, digest,
attestation_subnet_count)`, the widest topic set under one digest. It
goes through `BeaconTopics::for_fork`, so a fork that adds a global kind
is listed without touching the filter.
- **`lib.rs`:** the `Gossipsub` alias names the new filter;
`build_swarm` derives it from the wire and hands it to a private
`build_swarm_with_filter`, which a test uses to stand up a peer that
subscribes to topics this node does not list.
- **Docs:** the alias doc, a "Which subscriptions are kept" section in
`docs/beacon_wire.md`, and a bullet in `CLAUDE.md`.

## Correctness / Behavior Guarantees

- **Unlisted subscriptions are not stored.** That is what bounds a
stored name's length. They cost the sending peer nothing.
- **Every subnet is listed, joined or not.** Gossipsub picks fanout and
flood-publish peers from the stored subscriptions, so publishing on a
subnet this node has not joined (a gloas column sidecar, an attestation
a validator client submitted) still finds its peers.
- **The filter also gates this node's own `subscribe`.** A topic missing
from the allowlist is one the node cannot join, which is why the list is
built from what the topic code produces rather than written beside it.
The start digest is listed too; in production it is one of the
schedule's.
- **No per-peer count below the whole allowlist.** A subscription
refused for a count is never resent, and how many digests a peer holds
at once depends on its own client's join and leave timing, with each
join counted before the leaves that follow it. Any cap sized from this
node's own window (four digests, with a boundary at every epoch) would
leave a peer joining a fifth out of that digest for good.
- **A hello over the per-RPC limit is ignored whole**, listed topics
included, and a hello is never resent. That limit is therefore sized
from the most an honest peer can send, not from what is typical.

The numbers on a mainnet-shaped config (mainnet's schedule plus gloas,
207 topics per gloas digest):

| Limit | Value | A peer on every subnet of two digests uses |
|---|---|---|
| Topics one peer may hold | 2,237 (the whole allowlist) | 414 |
| Entries in one RPC | 4,474 | 414, plus whatever it sends that this
node does not list |

One choice is worth a reviewer's opinion:

- **The 500 floor per RPC** is the figure the issue gives for Prysm's
and Teku's cap. I did not check it in their code. It only binds on lean,
whose topic set is a handful.

`max_control_message_size` is unchanged (finding M2 in the issue's
"Related").

## Tests Added / Run

Added or changed in `ethlambda-p2p`:

- `a_peer_on_every_subnet_of_two_digests_is_heard_subscribing`
(extended): the same hello with topics this node does not list added
under both digests. Every listed topic is heard and none of the others
is kept. It now uses two real digests of a schedule, since made-up ones
are no longer listed.
- `a_subscription_to_an_unlisted_topic_is_not_stored`: an unknown kind,
an unknown digest, the first subnet past a family, a 64 KiB name and a
name not shaped like a topic are dropped; the listed topic in the same
hello is kept.
- `a_peer_joining_a_digest_while_holding_four_others_is_heard`: a peer
holding every topic of four digests joins a fifth, and every join is
heard. Checked that it fails with the earlier four-digest cap (828
topics).
- `a_hello_over_the_per_rpc_limit_is_ignored_whole`: a hello exactly at
the per-RPC limit is read; one entry more is ignored whole, and a later
subscription from the same peer is still heard.
- `subscription_filter::tests` (11): what the allowlist holds and leaves
out on both wires, that no set of listed topics is over a limit, and
that a lean committee count of `u64::MAX` lists 2 + 4,096 topics while a
subnet the node was told to join past the registry is still listed.
- `scoring::tests::a_mesh_grafted_ahead_of_its_fork_is_scored`: its
control topic was under a made-up digest, which the allowlist refuses.
It is now under the schedule's genesis digest.

Run locally:

- `cargo test --locked --profile release-fast -p ethlambda-p2p`: 580
passed, 0 failed, 1 ignored.
- `make lint`: clean.
- `cargo fmt --all --check`: clean.

Not run: the rest of the workspace's tests, and anything against other
clients. Since a limit set too low silently leaves an honest peer out of
every mesh, this should go through the kurtosis interop battery before
it is cherry-picked onto `release/v2.0.0`.

## Related Issues / PRs

- Closes #924
- Finding M6 of the review on #724
- The AI security review's findings M1 and M2 on this PR are addressed
in 0c871e8
- Intended for `release/v2.0.0` by cherry-pick once merged here; the
commit applies cleanly to that branch today. It is not on the #943
checklist yet.

## ✅ Verification Checklist

- [x] Ran `make fmt` — clean (`cargo fmt --all --check`)
- [x] Ran `make lint` (clippy with `-D warnings`) — clean
- [ ] Ran `make test` (`test-consensus`, `test-node` and `test-ethrex`,
at `release-fast`) — only `ethlambda-p2p`'s tests were run, passing

(cherry picked from commit 64ba9d5)
@pablodeymo

Copy link
Copy Markdown
Collaborator Author

/review

@pablodeymo

Copy link
Copy Markdown
Collaborator Author

Antigravity review:
PR #965 (ff3ac9e) is an exact, clean backport of PR #952 (64ba9d5), and all 13 CI checks are green.
──────

  1. Backport Fidelity Checks

• Identical git patch-id: Both 64ba9d5 (#952 on main) and ff3ac9e (#965 on backport/v2.0.0-pr-952) produce the exact same stable
patch ID (4841e28cd154b0f38d33ca6c94bae932a55e667a), carrying the (cherry picked from commit
64ba9d5) trailer with zero manual edits.
• Byte-for-byte crates/net/p2p/ equivalence: Between #952's parent on main (64ba9d5^) and origin/release/v2.0.0 (ded3fcc), there
are zero differing commits across any of the 6 touched paths (CLAUDE.md, docs/beacon_wire.md, and crates/net/p2p/). Merging #965 into
origin/release/v2.0.0 yields a crates/net/p2p/ tree that is byte-for-byte identical to 64ba9d5 on main.
• Conflict-free with release/v2.0.0 & sibling PRs: Verified via git merge-tree --write-tree that #965 merges cleanly with current
origin/release/v2.0.0 (ded3fcc) as well as #954, #962, and #968.
──────
2. Functional Check on release/v2.0.0 (including Hoodi Glamsterdam)
• Topic coverage across fork rollover (topics::every_topic, Allowlist::beacon): Built from ForkSchedule::new(&beacon.config, beacon.
genesis_validators_root), which now includes Hoodi's Gloas boundary at epoch 143616 (#901 / #967). All global topics, Gloas's 4
topics (GLOAS_TOPIC_KINDS under Gloas digests), 128 data-column subnets, 64 attestation subnets, and 4 sync-committee subnets are
allowlisted ahead of the boundary, so both this node's own transition::apply joins and peers' early warm-up subscriptions pass the
filter.
• Per-peer & per-RPC limits in #952: max_subscribed_topics = self.topics.len() ensures no set of allowlisted topics across multiple
held digests is ever rejected (including join-before-leave across dense boundaries), and Lean subnets are bounded by
VALIDATOR_REGISTRY_LIMIT (4096).
──────
3. Reminder on Follow-up PR #960

As #965's description notes, #965 is ready to merge into release/v2.0.0 now, and once #960 (fe9525a, which removes
MaxCountSubscriptionFilter to prevent gossipsub ERROR-log floods on oversized RPCs, narrows the startup allowlist to held/future
digests, and dynamically lists digests on backward clock jumps) finishes review and merges on main, #960 will need its own cherry-
pick backport onto release/v2.0.0 before tagging v2.0.0-rc.2.

@pablodeymo
pablodeymo merged commit 0c3a5f6 into release/v2.0.0 Dec 2, 2026
14 checks passed
@pablodeymo
pablodeymo deleted the backport/v2.0.0-pr-952 branch December 2, 2026 19:14
pablodeymo added a commit that referenced this pull request Dec 2, 2026
…they are sent (#968)

## 🗒️ Description / Motivation

Backport of #956 to `release/v2.0.0`, for `v2.0.0-rc.2`.

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

## What Changed

The ten commits of #956 as one commit on top of `release/v2.0.0`
(`3ed99c86`): the diff from its branch point on `main` (`e48246f8`) to
its head (`36232dcf`), applied with `git apply --3way`. It applied
without conflicts and nothing was edited by hand. That includes #958,
the by-root counterpart, which was merged into #956's branch.

What it does, from #956:

- An `execution_payload_envelopes_by_range` answer stops once 16 MiB of
SSZ has gone out, always carrying the first envelope its window has.
Before, one request could make the node load and send about 1 GiB.
- Envelopes are read as they are sent: the codec reads each row just
before writing its chunk, and a row that fails to read or decode ends
the answer where it is.
- The requester asks the same peer again after an answer that stops
short, for up to 30 s.
- `execution_payload_envelopes_by_root` answers are bounded and read the
same way (#958).

## Tests Added / Run

On this branch:

- `cargo fmt --all -- --check` and `make lint`: clean.
- `cargo test -p ethlambda-p2p --profile release-fast --lib`: 587
passed, 0 failed, 1 ignored.
- `cargo test -p ethlambda-storage --profile release-fast --features
rocksdb`: 256 passed, 0 failed, 2 ignored.

Not run locally: the rest of `make test`.

## Related Issues / PRs

- Original: #956 (closes #895 on `main`), with #958.
- The other PRs open against the release branch: #954, #962 (backport of
#950) and #965 (backport of #952). This one merges with each of them
without conflicts (checked with `git merge-tree`), though it shares
`crates/net/p2p/src/lib.rs`, `CLAUDE.md` and `docs/beacon_wire.md` with
some of them.
- Release checklist: #943.
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>
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