fix: subscribe to subnet when aggregating only#160
Conversation
🤖 Kimi Code ReviewReview SummaryThe changes correctly implement the intended behavior where only aggregators subscribe to attestation subnets, while non-aggregators can still publish via gossipsub's fanout mechanism. However, there are several issues that need attention: 1. Potential Panic on Subscription Failure (Line 196)The Fix: if let Err(e) = swarm.behaviour_mut().gossipsub.subscribe(&attestation_topic) {
error!(%attestation_topic_kind, error = %e, "Failed to subscribe to attestation subnet");
// Consider graceful degradation or retry logic
}2. Race Condition in Topic Construction (Lines 183-189)The attestation topic construction happens regardless of whether the node is an aggregator or not, but the topic string is only logged in the conditional branches. This could lead to confusion in logs. Suggestion: Move the topic construction inside the aggregator branch or log it consistently for both cases. 3. Missing Validation for
|
🤖 Codex Code ReviewNo blocking findings in this PR.
Residual risk / suggestion:
Validation gap:
Automated review by OpenAI Codex · custom prompt |
🤖 Claude Code ReviewNow I have a thorough understanding of the PR. Let me write the review. PR #160 —
|
Greptile SummaryThis PR optimizes P2P network resource usage by restricting attestation subnet subscriptions to aggregator nodes only. Non-aggregator nodes can still publish attestations via gossipsub's fanout mechanism without subscribing to the subnet. Key Changes:
Benefits:
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| bin/ethlambda/src/main.rs | Passes is_aggregator flag to start_p2p function |
| crates/net/p2p/src/lib.rs | Conditionally subscribes to attestation subnet based on aggregator status; non-aggregators publish via fanout |
Last reviewed commit: 5ca61c4
crates/net/p2p/src/lib.rs
Outdated
| } else { | ||
| info!(%attestation_topic_kind, "Skipping attestation subnet subscription (not an aggregator)"); | ||
| } |
There was a problem hiding this comment.
we don't need to log this message
crates/net/p2p/src/lib.rs
Outdated
| .behaviour_mut() | ||
| .gossipsub | ||
| .subscribe(&attestation_topic) | ||
| .unwrap(); |
There was a problem hiding this comment.
can we trait error properly?
maybe log an error
Summary
Changes
bin/ethlambda/src/main.rsis_aggregatorflag tostart_p2p()crates/net/p2p/src/lib.rsis_aggregatorparam; wrap attestation.subscribe()in conditionalHow it works
Gossipsub's fanout mechanism allows publishing to topics without subscribing. When a node publishes to an unsubscribed topic, libp2p maintains a temporary fanout set of peers that are subscribed, forwarding the message through them. This means non-aggregators only need outbound delivery (publishing), not inbound collection (subscribing).
Test plan
cargo fmt --all -- --checkcargo clippy --workspace -- -D warningscargo test --workspace --release(all unit tests pass; spec tests require fixtures not in worktree)Closes #159