Skip to content

Commit d08dedf

Browse files
committed
fix(network): add immediate peer addition to gossipsub mesh and enable flood publishing
- Implemented a critical fix to add peers as explicit gossipsub peers immediately after connection, ensuring they are included in the mesh for all topics without delay. - Enabled flood publishing for small networks to ensure messages are sent to all connected peers immediately, addressing issues in 2-node networks where mesh formation can be delayed.
1 parent 4780dbe commit d08dedf

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

app/src/actors_v2/network/network_actor.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,25 @@ impl NetworkActor {
329329
endpoint.get_remote_address().to_string(),
330330
);
331331
self.metrics.record_connection_established();
332+
333+
// CRITICAL FIX FOR ISSUE #2: Add peer as explicit gossipsub peer immediately
334+
// This ensures the peer is added to the gossipsub mesh for all topics
335+
// without waiting for the heartbeat tick (which can take 1+ seconds)
336+
if let Some(cmd_tx) = &self.swarm_cmd_tx {
337+
let cmd = SwarmCommand::AddExplicitPeer { peer_id };
338+
if let Err(e) = cmd_tx.try_send(cmd) {
339+
tracing::warn!(
340+
peer_id = %peer_id,
341+
error = ?e,
342+
"Failed to send AddExplicitPeer command after connection"
343+
);
344+
} else {
345+
tracing::debug!(
346+
peer_id = %peer_id,
347+
"Sent AddExplicitPeer command for immediate mesh formation"
348+
);
349+
}
350+
}
332351
}
333352

334353
SwarmEvent::ConnectionClosed { peer_id, cause, .. } => {

app/src/actors_v2/network/swarm_factory.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ fn create_behaviour(
8282
// Relax gossip parameters for small networks
8383
.gossip_lazy(3) // Gossip to this many peers (default: 6)
8484
.gossip_factor(0.5) // Gossip factor (default: 0.25)
85+
// CRITICAL FIX: Enable flood publishing for small networks
86+
// This ensures messages are sent to all connected peers immediately,
87+
// even if the mesh hasn't formed yet. Essential for 2-node networks
88+
// where mesh formation can be delayed.
89+
.flood_publish(true) // Flood messages to all connected peers (default: false)
8590
.message_id_fn(|msg: &gossipsub::Message| {
8691
// Use first 20 bytes of hash as message ID
8792
let mut hasher = DefaultHasher::new();

0 commit comments

Comments
 (0)