Skip to content

Commit c4f6bd0

Browse files
Refactor backoff handling and improve test wait time for compatibility
- Updated backoff handling logic in the GossipSub class to always add backoff, regardless of topic presence in the mesh. - Adjusted the wait time in the test_handle_prune function to 0.5 seconds for better compatibility on Windows systems.
1 parent 035b699 commit c4f6bd0

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

libp2p/pubsub/gossipsub.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,12 +1085,14 @@ async def handle_prune(
10851085
px_peers.append(peer)
10861086

10871087
# Remove peer from mesh for topic
1088-
if topic in self.mesh:
1089-
if backoff_till > 0:
1090-
self._add_back_off(sender_peer_id, topic, False, backoff_till)
1091-
else:
1092-
self._add_back_off(sender_peer_id, topic, False)
1088+
# Always add backoff, even if topic is not currently in mesh
1089+
if backoff_till > 0:
1090+
self._add_back_off(sender_peer_id, topic, False, backoff_till)
1091+
else:
1092+
self._add_back_off(sender_peer_id, topic, False)
10931093

1094+
# Remove sender from mesh if topic exists in mesh
1095+
if topic in self.mesh:
10941096
self.mesh[topic].discard(sender_peer_id)
10951097
if self.scorer is not None:
10961098
self.scorer.on_leave_mesh(sender_peer_id, topic)

tests/core/pubsub/test_gossipsub.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ async def test_handle_prune():
207207

208208
# NOTE: We increase `heartbeat_interval` to 3 seconds so that bob will not
209209
# add alice back to his mesh after heartbeat.
210-
# Wait for bob to `handle_prune`
211-
await trio.sleep(0.1)
210+
# Wait for bob to `handle_prune` - increased wait time for Windows compatibility
211+
await trio.sleep(0.5)
212212

213213
# Check that alice is no longer bob's mesh peer
214214
assert id_alice not in gossipsubs[index_bob].mesh[topic]

0 commit comments

Comments
 (0)