From d411cd7dabec645b7c555765212ef8068c7edce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Thu, 16 Apr 2026 18:46:25 -0300 Subject: [PATCH] refactor(p2p): drop NoPeersSubscribedToTopic suppression Since every validator now subscribes to its own attestation subnet (#293), the transient "no remote peer knows of this subnet yet" condition is no longer part of the expected publish path. If it surfaces, it's a real signal (partition, misconfigured peer) and deserves the warning. Removes: - SwarmHandle::publish_ignore_no_peers and the ignore_no_peers flag on SwarmCommand::Publish - The is_aggregator field on BuiltSwarm / P2PServer (only used to pick between the two publish paths) - The aggregator-only branch in publish_attestation Publish errors are now logged uniformly via inspect_err on the single publish path in the swarm adapter. --- crates/net/p2p/src/gossipsub/handler.rs | 13 +------- crates/net/p2p/src/lib.rs | 4 --- crates/net/p2p/src/swarm_adapter.rs | 41 +++++-------------------- 3 files changed, 9 insertions(+), 49 deletions(-) diff --git a/crates/net/p2p/src/gossipsub/handler.rs b/crates/net/p2p/src/gossipsub/handler.rs index 4d418463..0955ab4a 100644 --- a/crates/net/p2p/src/gossipsub/handler.rs +++ b/crates/net/p2p/src/gossipsub/handler.rs @@ -145,18 +145,7 @@ pub async fn publish_attestation(server: &mut P2PServer, attestation: SignedAtte .cloned() .unwrap_or_else(|| attestation_subnet_topic(subnet_id)); - // Publish to the attestation subnet topic. - // Aggregators are subscribed to the subnet, so gossipsub uses mesh (not fanout). - // In small networks where no other node subscribes, this returns - // NoPeersSubscribedToTopic. Use best-effort to suppress the expected warning; - // the aggregator already self-delivered its attestation locally. - if server.is_aggregator { - server - .swarm_handle - .publish_ignore_no_peers(topic, compressed); - } else { - server.swarm_handle.publish(topic, compressed); - } + server.swarm_handle.publish(topic, compressed); info!( %slot, validator, diff --git a/crates/net/p2p/src/lib.rs b/crates/net/p2p/src/lib.rs index 0298a54a..8b89234d 100644 --- a/crates/net/p2p/src/lib.rs +++ b/crates/net/p2p/src/lib.rs @@ -92,7 +92,6 @@ pub struct BuiltSwarm { pub(crate) block_topic: libp2p::gossipsub::IdentTopic, pub(crate) aggregation_topic: libp2p::gossipsub::IdentTopic, pub(crate) bootnode_addrs: HashMap, - pub(crate) is_aggregator: bool, } /// Build and configure the libp2p swarm, dial bootnodes, subscribe to topics. @@ -250,7 +249,6 @@ pub fn build_swarm( block_topic, aggregation_topic, bootnode_addrs, - is_aggregator: config.is_aggregator, }) } @@ -274,7 +272,6 @@ impl P2P { attestation_committee_count: built.attestation_committee_count, block_topic: built.block_topic, aggregation_topic: built.aggregation_topic, - is_aggregator: built.is_aggregator, connected_peers: HashSet::new(), pending_requests: HashMap::new(), request_id_map: HashMap::new(), @@ -309,7 +306,6 @@ pub struct P2PServer { pub(crate) attestation_committee_count: u64, pub(crate) block_topic: libp2p::gossipsub::IdentTopic, pub(crate) aggregation_topic: libp2p::gossipsub::IdentTopic, - pub(crate) is_aggregator: bool, pub(crate) connected_peers: HashSet, pub(crate) pending_requests: HashMap, diff --git a/crates/net/p2p/src/swarm_adapter.rs b/crates/net/p2p/src/swarm_adapter.rs index 23837a69..1def5406 100644 --- a/crates/net/p2p/src/swarm_adapter.rs +++ b/crates/net/p2p/src/swarm_adapter.rs @@ -1,7 +1,6 @@ use libp2p::{ Multiaddr, PeerId, StreamProtocol, futures::StreamExt, - gossipsub::PublishError, request_response::{self, OutboundRequestId}, swarm::SwarmEvent, }; @@ -14,8 +13,6 @@ pub enum SwarmCommand { Publish { topic: libp2p::gossipsub::IdentTopic, data: Vec, - /// When true, suppress NoPeersSubscribedToTopic errors (other errors still warn). - ignore_no_peers: bool, }, Dial(Multiaddr), SendRequest { @@ -40,25 +37,7 @@ impl SwarmHandle { pub fn publish(&self, topic: libp2p::gossipsub::IdentTopic, data: Vec) { let _ = self .cmd_tx - .send(SwarmCommand::Publish { - topic, - data, - ignore_no_peers: false, - }) - .inspect_err(|_| warn!("Swarm adapter closed, cannot publish")); - } - - /// Publish, suppressing NoPeersSubscribedToTopic errors. Used when the sender - /// is also subscribed to the topic (e.g., aggregator publishing its own - /// attestation to a subnet it subscribes to) and no other peer subscribes. - pub fn publish_ignore_no_peers(&self, topic: libp2p::gossipsub::IdentTopic, data: Vec) { - let _ = self - .cmd_tx - .send(SwarmCommand::Publish { - topic, - data, - ignore_no_peers: true, - }) + .send(SwarmCommand::Publish { topic, data }) .inspect_err(|_| warn!("Swarm adapter closed, cannot publish")); } @@ -144,17 +123,13 @@ async fn swarm_loop( fn execute_command(swarm: &mut libp2p::Swarm, cmd: SwarmCommand) { match cmd { - SwarmCommand::Publish { - topic, - data, - ignore_no_peers, - } => { - let result = swarm.behaviour_mut().gossipsub.publish(topic, data); - if let Err(err) = result - && !(ignore_no_peers && matches!(err, PublishError::NoPeersSubscribedToTopic)) - { - warn!(%err, "Swarm adapter: publish failed"); - } + SwarmCommand::Publish { topic, data } => { + swarm + .behaviour_mut() + .gossipsub + .publish(topic, data) + .inspect_err(|err| warn!(%err, "Swarm adapter: publish failed")) + .ok(); } SwarmCommand::Dial(addr) => { let _ = swarm