Skip to content

Commit 1164fd3

Browse files
authored
fix(gossipsub): race condition for messages already on the network
There is a possible race condition that can happen that results in us inadvertently penalizing a peer. 1. Message A gets published on the network 1. We receive an IHAVE for message A 1. We request an IWANT for message from Peer Z 1. We then publish message A 1. Peer Z responds with our requested message, but we ignore it as its now a duplicate 1. We penalize Peer Z for not responding to our IWANT. This PR removes the promise for a message when we publish it. Pull-Request: libp2p#5928.
1 parent 3654685 commit 1164fd3

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

protocols/gossipsub/CHANGELOG.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
## 0.49.0
22

3-
- Improve error messaging by renaming `PublishError::InsufficientPeers` to
4-
`PublishError::NoPeersSubscribedToTopic`. This change makes it clearer that the error occurs
5-
specifically when trying to publish to a topic with no subscribed peers, rather than a general
3+
- Fix a race condition for messages published which are already in the network.
4+
See [PR 5928](https://github.com/libp2p/rust-libp2p/pull/5928)
5+
6+
- Improve error messaging by renaming `PublishError::InsufficientPeers` to
7+
`PublishError::NoPeersSubscribedToTopic`. This change makes it clearer that the error occurs
8+
specifically when trying to publish to a topic with no subscribed peers, rather than a general
69
peer availability issue.
710
See [PR 5912](https://github.com/libp2p/rust-libp2p/pull/5912)
8-
11+
912
- Allow whitelisting topics for metrics to ensure metrics are recorded correctly for these topics.
1013
See [PR 5895](https://github.com/libp2p/rust-libp2p/pull/5895)
1114

protocols/gossipsub/src/behaviour.rs

+3
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,9 @@ where
732732
self.duplicate_cache.insert(msg_id.clone());
733733
self.mcache.put(&msg_id, raw_message.clone());
734734

735+
// Consider the message as delivered for gossip promises.
736+
self.gossip_promises.message_delivered(&msg_id);
737+
735738
// If the message is anonymous or has a random author add it to the published message ids
736739
// cache.
737740
if let PublishConfig::RandomAuthor | PublishConfig::Anonymous = self.publish_config {

0 commit comments

Comments
 (0)