Repository navigation
fix(p2p): drop the subscription count limits, list only digests held from startup on - #960
Conversation
…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.
|
/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.
AI security review: 1 finding(s) to checkReviewed by Opus, GPT, Kimi, DeepSeek. A judge model checked every one of the findings against the code.
DetailsM1. Removal of per-RPC subscription count allows CPU exhaustion from connected peers (medium, DoS/resource)
Cost of this review: ~$2.20 of a $30 budget (estimated from token counts). |
Review follow-ups pushed to this branch (
|
|
/review |
AI security review: 2 finding(s) to checkReviewed by Opus, GPT, Kimi, DeepSeek. A judge model checked every one of the findings against the code.
DetailsM1. Removing MaxCountSubscriptionFilter lets a peer force large subscription-RPC processing on the shared swarm task (medium, DoS/resource)
M2. Backward clock correction can permanently refuse the current fork’s topics (low, logic)
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.
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:
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 On M2 (a clock stepped back leaves the node deaf)Fixed in 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.
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: |
|
/review |
…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.
…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>
🗒️ Description / Motivation
Follow-up to #952, which merged before these review fixes were pushed.
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'sSubscription, which the crate does not export.What Changed
crates/net/p2p/src/subscription_filter.rs:AllowlistimplementsTopicSubscriptionFilteritself and is the whole filter.MaxCountSubscriptionFilter,into_filterand the limit constants are gone.Allowlist::beaconlists 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 thanUNSUBSCRIBE_LAG_EPOCHS. A startup digest not on the schedule falls back to listing every digest.crates/net/p2p/src/lib.rs: theGossipsubalias andbuild_swarmtake theAllowlistdirectly.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
main's exposure before fix(p2p): keep a peer's gossipsub subscriptions only for listed topics, within a count limit #952 (AllowAllSubscriptionFilter), minus storing the names: one RPC is bounded bymax_control_message_size, and its entries are filtered on the swarm task.Tests Added / Run
every_digest_held_from_startup_on_is_listed: from start epochs around dense and sparse boundaries, every digestheld_atreturns 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_onereplaces 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 currentmain).Related Issues / PRs
✅ Verification Checklist
make fmt— cleanmake lint(clippy with-D warnings) — cleanmake test(test-consensus,test-nodeandtest-ethrex, atrelease-fast) — onlyethlambda-p2p