From 0d890fdc65743b7c5af50905dd3e6cd26ce773ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Wed, 27 Nov 2024 17:05:29 +0000 Subject: [PATCH] fix(gossipsub): fix mesh/fanout inconsistencies When a peer unsubscribes also remove it from fanout. Pull-Request: #5690. --- protocols/gossipsub/CHANGELOG.md | 6 ++++-- protocols/gossipsub/src/behaviour.rs | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index 8d95abc01a2..ddbbc7fb552 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -1,15 +1,17 @@ ## 0.48.0 +- Correct state inconsistencies with the mesh and fanout when unsubscribing. + See [PR 5690](https://github.com/libp2p/rust-libp2p/pull/5690) + - Deprecate `futures-ticker` and use `futures-timer` instead. See [PR 5674](https://github.com/libp2p/rust-libp2p/pull/5674). + - Apply `max_transmit_size` to the inner message instead of the final payload. See [PR 5642](https://github.com/libp2p/rust-libp2p/pull/5642). - Deprecate `void` crate. See [PR 5676](https://github.com/libp2p/rust-libp2p/pull/5676). -## 0.47.1 - - Attempt to publish to at least mesh_n peers when flood publish is disabled. See [PR 5578](https://github.com/libp2p/rust-libp2p/pull/5578). diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index fae45ed452e..075a881db48 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -1962,8 +1962,11 @@ where } } - // remove unsubscribed peers from the mesh if it exists + // remove unsubscribed peers from the mesh and fanout if they exist there. for (peer_id, topic_hash) in unsubscribed_peers { + self.fanout + .get_mut(&topic_hash) + .map(|peers| peers.remove(&peer_id)); self.remove_peer_from_mesh(&peer_id, &topic_hash, None, false, Churn::Unsub); }