fix: do not subscribe to subnets when not aggregating#265
Conversation
🤖 Kimi Code ReviewThe PR correctly implements the distinction between aggregator and non-aggregator subscription behavior per Ethereum consensus networking specs. Assessment: Correct and idiomatic Highlights
Pre-existing issue (not blocking)Line 214, 234: Division by zero risk if let subnet_id = vid % config.attestation_committee_count;While this is a protocol invariant that should never be 0 in practice, consider defensively validating this at config load time or using Minor suggestionLine 219: The Conclusion: Ship it. The change correctly reduces subscription overhead for non-aggregator validators while maintaining all necessary publishing capabilities. Automated review by Kimi (Moonshot AI) · kimi-k2.5 · custom prompt |
Greptile SummaryThis PR fixes unnecessary attestation-subnet gossipsub mesh memberships: non-aggregating nodes no longer subscribe to attestation subnets and instead rely on gossipsub fanout for publishing. The topic cache (
Confidence Score: 3/5Mostly safe, but the P1 finding about The core logic of restricting subscriptions to aggregators is sound and well-commented. Score is 3 rather than 4 because of the unconfirmed behavioral change where crates/net/p2p/src/lib.rs — specifically the
|
| Filename | Overview |
|---|---|
| crates/net/p2p/src/lib.rs | Refactors attestation subnet subscriptions so only aggregators join the gossipsub mesh; non-aggregators now rely on fanout publishing. Topic cache building is separated from subscription logic and correctly covers all validator-owned subnets. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[build_swarm called] --> B[Subscribe: block_topic - all nodes]
B --> C[Subscribe: aggregation_topic - all nodes]
C --> D{is_aggregator?}
D -- yes --> E[Build aggregate_subnets from validator_ids + aggregate_subnet_ids]
E --> F{aggregate_subnets empty?}
F -- yes --> G[Fallback: add subnet 0]
F -- no --> H[Subscribe to each subnet in gossipsub mesh]
G --> H
D -- no --> I[Skip subnet subscriptions - fanout only]
H --> J[Build attestation_topics cache from validator_ids only]
I --> J
J --> K[Set metric_subnet from attestation_topics]
K --> L[Return BuiltSwarm]
Prompt To Fix All With AI
This is a comment left during a code review.
Path: crates/net/p2p/src/lib.rs
Line: 231-238
Comment:
**`attestation_topics` no longer covers `aggregate_subnet_ids`**
In the old code, the topic cache was built from `subscribe_subnets`, which for aggregators included both validator-derived subnets and any `aggregate_subnet_ids`. The new code builds it only from `config.validator_ids`. This is a silent behavioral change for aggregators that have `aggregate_subnet_ids` outside their own validators' subnets — those subnet topics will be in the gossipsub subscription set but absent from `attestation_topics`.
If any downstream publish path (e.g. `publish_attestation`) looks up a topic by subnet ID from `attestation_topics` using a subnet that only appears in `aggregate_subnet_ids`, it will find no entry and either silently drop the publish or panic. Worth confirming this path is unreachable, or adding the aggregator's subscribed subnets to the cache as well.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: crates/net/p2p/src/lib.rs
Line: 208-229
Comment:
**Fanout expiry risk for infrequently-publishing validators**
The comment states that non-aggregators "publish via gossipsub fanout." Fanout state in libp2p gossipsub is maintained per-topic and evicted after `fanout_ttl` (60 s here). If a non-aggregating validator restarts or is idle for more than 60 s before its first attestation, the node has no fanout peers for the subnet topic and the first `publish()` call may silently succeed locally but reach zero peers.
Since attestations arrive every slot (4 s) this is only a concern at startup or after a long idle period. Consider logging a warning when the first publish occurs while the node is not subscribed and has no fanout peers, or documenting the startup latency expectation.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix: do not subscribe to subnets when no..." | Re-trigger Greptile
🤖 Codex Code ReviewFindings
No other material security, memory-safety, or SSZ/state-transition issues are touched by this diff. Automated review by OpenAI Codex · gpt-5.4 · custom prompt |
🤖 Claude Code ReviewHere is my review: Review:
|
This PR removes subnet subscribing when we're not an aggregator.
It was already fixed in #160, but was re-introduced in #249