cl/p2p: accept gossip subscriptions only for known topics #26058
<!-- ccr-overview-v2 -->
🟢 Approval recommended
No active review issues are recorded for the change restricting gossip subscriptions to scheduled fork digests and recognized topics.
No open issues 🎉
<details>
<summary><strong>What changed in this PR</strong></summary>
This PR limits Caplin gossip subscriptions to scheduled fork digests and recognized topic names, preventing peers from growing subscription state with arbitrary topics across repeated RPCs.
Changes:
| File | Description |
| ---- | ----------- |
| cl/p2p/p2p.go | Handles errors when creating pubsub options. |
| cl/p2p/libp2p_setting.go | Restricts subscriptions to scheduled digests and recognized topic patterns. |
| cl/p2p/libp2p_setting_test.go | Tests accepted and rejected topics and fork/blob schedule digests. |
</details>
<sub>Review effort: Balanced</sub>
make([]string, 0, ...) requires the capacity argument to be of type int, but this code builds a uint64 capacity. This is a compile-time error. Build the capacity as an int (with explicit conversions for each count) before calling make.
This test hard-codes fork epochs (including FuluForkEpoch) while scheduledForkDigests derives epochs from ForkVersionSchedule and explicitly skips forks at FarFutureEpoch. To avoid a mismatch between the test and production logic, build epochs from beaconConfig.ForkVersionSchedule (applying the same FarFutureEpoch filter) plus beaconConfig.BlobSchedule, rather than using the individual *ForkEpoch fields.
If multiple entries in ForkVersionSchedule/BlobSchedule share the same epoch, this will compute and store duplicate digests, which then multiplies the allowlist size. Consider de-duplicating epochs (or digests) before returning to keep the allowlist smaller and avoid redundant work.
[!WARNING]
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add acopilot-code-review.ymlfile specifying one with theruns-onattribute. See the docs for more details.
<!-- ccr-overview-v2 -->
Copilot review overview
<details open>
<summary><strong>3 open issues</strong></summary>
make([]string, 0, ...) requires the capacity argument to be of type int, but this code builds a…](https://github.com/erigontech/erigon/pull/26058#discussion_r4522041271) · NewFuluForkEpoch) while scheduledForkDigests derives… · NewForkVersionSchedule/BlobSchedule share the same epoch, this will compute… · New</details>
<sub>Review effort: Lite</sub>
Not an error: make accepts a size of any integer type, and this compiles and passes lint.
Kept as is: the test reads the mainnet config, where these epochs are scheduled, so the digests it asks for are the ones the function must return.
No effect: the allowlist is a map, so a duplicate digest adds no entry. Only the temporary slice has a few repeated strings, once at startup.
Approved these changes.
<!-- ccr-overview-v2 -->
🟢 Approval recommended
No active review issues block approval of the finite gossip-subscription allowlist change.
No open issues 🎉
<details>
<summary><strong>3 resolved since last review</strong></summary>
make([]string, 0, ...) requires the capacity argument to be of type int, but this code builds a…](https://github.com/erigontech/erigon/pull/26058#discussion_r4522041271)FuluForkEpoch) while scheduledForkDigests derives…ForkVersionSchedule/BlobSchedule share the same epoch, this will compute…</details>
<sub>Review effort: Balanced</sub>
awskii
AskAlexSharov
Bug: the subscription filter accepts any digest and any name of the right shape, and its limit is per RPC. One peer can send many RPCs with new topic names, and gossipsub keeps each one until the peer disconnects.
Fix: accept only the digests of the fork and blob schedule and the known topic names, so the set of topics is finite.