diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index 550bbad4d99..94b9b922973 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -35,6 +35,9 @@ - Fix `cargo clippy` warnings in `rustc 1.84.0-beta.1`. See [PR 5700](https://github.com/libp2p/rust-libp2p/pull/5700). +- Fixe an issue where an `InsufficientPeers` error could occur under certain conditions, despite having peers subscribed to a topic. + See [PR 5793](https://github.com/libp2p/rust-libp2p/pull/5793). + ## 0.47.0 diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 6172875e5b9..356f1d6cd77 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -675,9 +675,14 @@ where // Gossipsub peers None => { tracing::debug!(topic=%topic_hash, "Topic not in the mesh"); + // `fanout_peers` is always non-empty if it's `Some`. + let fanout_peers = self + .fanout + .get(&topic_hash) + .filter(|peers| !peers.is_empty()); // If we have fanout peers add them to the map. - if self.fanout.contains_key(&topic_hash) { - for peer in self.fanout.get(&topic_hash).expect("Topic must exist") { + if let Some(peers) = fanout_peers { + for peer in peers { recipient_peers.insert(*peer); } } else {