Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions crates/net/p2p/src/gossipsub/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions crates/net/p2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PeerId, Multiaddr>,
pub(crate) is_aggregator: bool,
}

/// Build and configure the libp2p swarm, dial bootnodes, subscribe to topics.
Expand Down Expand Up @@ -250,7 +249,6 @@ pub fn build_swarm(
block_topic,
aggregation_topic,
bootnode_addrs,
is_aggregator: config.is_aggregator,
})
}

Expand All @@ -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(),
Expand Down Expand Up @@ -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<PeerId>,
pub(crate) pending_requests: HashMap<H256, PendingRequest>,
Expand Down
41 changes: 8 additions & 33 deletions crates/net/p2p/src/swarm_adapter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use libp2p::{
Multiaddr, PeerId, StreamProtocol,
futures::StreamExt,
gossipsub::PublishError,
request_response::{self, OutboundRequestId},
swarm::SwarmEvent,
};
Expand All @@ -14,8 +13,6 @@ pub enum SwarmCommand {
Publish {
topic: libp2p::gossipsub::IdentTopic,
data: Vec<u8>,
/// When true, suppress NoPeersSubscribedToTopic errors (other errors still warn).
ignore_no_peers: bool,
},
Dial(Multiaddr),
SendRequest {
Expand All @@ -40,25 +37,7 @@ impl SwarmHandle {
pub fn publish(&self, topic: libp2p::gossipsub::IdentTopic, data: Vec<u8>) {
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<u8>) {
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"));
}

Expand Down Expand Up @@ -144,17 +123,13 @@ async fn swarm_loop(

fn execute_command(swarm: &mut libp2p::Swarm<Behaviour>, 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
Expand Down
Loading