Skip to content

Commit 28fa068

Browse files
authored
fix(gossipsub): Always construct mesh
There is a case where we subscribe to a topic but never create a mesh. This can happen for example when we set the mesh degree to 0, then we don't add any peers and the mesh never gets constructed. We then never send subscriptions to peers and essentially the subscription never existed. This PR ensures the mesh is always constructed when the user subscribes. This PR also improves the logging to downgrade some logs and remove unnecessary logs. Pull-Request: #6100.
1 parent 3f1ee1e commit 28fa068

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

protocols/gossipsub/CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
- Remove `Rpc` from the public API.
44
See [PR 6091](https://github.com/libp2p/rust-libp2p/pull/6091)
5+
56
- Fix applying P3 and P6 Score penalties when their weight is zero
67
See [PR 6097](https://github.com/libp2p/rust-libp2p/pull/6097)
78

8-
## 0.49.0
9-
109
- Fix fanout logic to include correctly scored peers and prevent panics when memcache is set to 0.
1110
See [PR 6095](https://github.com/libp2p/rust-libp2p/pull/6095)
1211

12+
- Fix mesh not being constructed even when not adding any peer.
13+
See [PR 6100](https://github.com/libp2p/rust-libp2p/pull/6100)
14+
15+
## 0.49.0
16+
1317
- Feature gate metrics related code. This changes some `Behaviour` constructor methods.
1418
See [PR 6020](https://github.com/libp2p/rust-libp2p/pull/6020)
1519
- Send IDONTWANT before Publishing a new message.

protocols/gossipsub/src/behaviour.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,6 @@ where
519519
/// Returns [`Ok(true)`] if the subscription worked. Returns [`Ok(false)`] if we were already
520520
/// subscribed.
521521
pub fn subscribe<H: Hasher>(&mut self, topic: &Topic<H>) -> Result<bool, SubscriptionError> {
522-
tracing::debug!(%topic, "Subscribing to topic");
523522
let topic_hash = topic.hash();
524523
if !self.subscription_filter.can_subscribe(&topic_hash) {
525524
return Err(SubscriptionError::NotAllowed);
@@ -548,7 +547,6 @@ where
548547
///
549548
/// Returns `true` if we were subscribed to this topic.
550549
pub fn unsubscribe<H: Hasher>(&mut self, topic: &Topic<H>) -> bool {
551-
tracing::debug!(%topic, "Unsubscribing from topic");
552550
let topic_hash = topic.hash();
553551

554552
if !self.mesh.contains_key(&topic_hash) {
@@ -978,15 +976,16 @@ where
978976

979977
/// Gossipsub JOIN(topic) - adds topic peers to mesh and sends them GRAFT messages.
980978
fn join(&mut self, topic_hash: &TopicHash) {
981-
tracing::debug!(topic=%topic_hash, "Running JOIN for topic");
982-
983979
let mut added_peers = HashSet::new();
984980
let mesh_n = self.config.mesh_n_for_topic(topic_hash);
985981
#[cfg(feature = "metrics")]
986982
if let Some(m) = self.metrics.as_mut() {
987983
m.joined(topic_hash)
988984
}
989985

986+
// Always construct a mesh regardless if we find peers or not.
987+
self.mesh.entry(topic_hash.clone()).or_default();
988+
990989
// check if we have mesh_n peers in fanout[topic] and add them to the mesh if we do,
991990
// removing the fanout entry.
992991
if let Some((_, mut peers)) = self.fanout.remove_entry(topic_hash) {
@@ -1907,7 +1906,7 @@ where
19071906
subscriptions: &[Subscription],
19081907
propagation_source: &PeerId,
19091908
) {
1910-
tracing::debug!(
1909+
tracing::trace!(
19111910
source=%propagation_source,
19121911
"Handling subscriptions: {:?}",
19131912
subscriptions,
@@ -2087,7 +2086,6 @@ where
20872086

20882087
/// Heartbeat function which shifts the memcache and updates the mesh.
20892088
fn heartbeat(&mut self) {
2090-
tracing::debug!("Starting heartbeat");
20912089
#[cfg(feature = "metrics")]
20922090
let start = Instant::now();
20932091

@@ -2533,7 +2531,6 @@ where
25332531
}
25342532
}
25352533

2536-
tracing::debug!("Completed Heartbeat");
25372534
#[cfg(feature = "metrics")]
25382535
if let Some(metrics) = self.metrics.as_mut() {
25392536
let duration = u64::try_from(start.elapsed().as_millis()).unwrap_or(u64::MAX);

0 commit comments

Comments
 (0)