Skip to content

Commit e29dad6

Browse files
authored
fix(gossipsub): Remove penalty for duplicate publish messages
We had a mechanism designed to punish peers that send messages to us with the same message-id. This was a mitigation to prevent peers from sending us back messages we just published. However, in content-based networks, there is often the scenario (which is not explicitly forbidden in gossipsub) where there can be multiple publishers of the same message. This mechanism was downscoring honest nodes in this system. This PR removes this mechanism. If we want to have something like this, we can tie it now to nodes sending messages after recieving IDONTWANT's from us. This has its own pitfalls and I leave for a future PR. cc @dknopik Pull-Request: #6112.
1 parent 6433611 commit e29dad6

File tree

3 files changed

+3
-34
lines changed

3 files changed

+3
-34
lines changed

protocols/gossipsub/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
## 0.50.0
2+
- Remove peer penalty for duplicate messages.
3+
See [PR 6112](https://github.com/libp2p/rust-libp2p/pull/6112)
24

35
- Remove `Rpc` from the public API.
46
See [PR 6091](https://github.com/libp2p/rust-libp2p/pull/6091)

protocols/gossipsub/src/behaviour.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,6 @@ pub struct Behaviour<D = IdentityTransform, F = AllowAllSubscriptionFilter> {
322322
/// Counts the number of `IWANT` that we sent the each peer since the last heartbeat.
323323
count_sent_iwant: HashMap<PeerId, usize>,
324324

325-
/// Short term cache for published message ids. This is used for penalizing peers sending
326-
/// our own messages back if the messages are anonymous or use a random author.
327-
published_message_ids: DuplicateCache<MessageId>,
328-
329325
/// The filter used to handle message subscriptions.
330326
subscription_filter: F,
331327

@@ -449,7 +445,6 @@ where
449445
count_received_ihave: HashMap::new(),
450446
count_sent_iwant: HashMap::new(),
451447
connected_peers: HashMap::new(),
452-
published_message_ids: DuplicateCache::new(config.published_message_ids_cache_time()),
453448
config,
454449
subscription_filter,
455450
data_transform,
@@ -736,14 +731,6 @@ where
736731
// Consider the message as delivered for gossip promises.
737732
self.gossip_promises.message_delivered(&msg_id);
738733

739-
// If the message is anonymous or has a random author add it to the published message ids
740-
// cache.
741-
if let PublishConfig::RandomAuthor | PublishConfig::Anonymous = self.publish_config {
742-
if !self.config.allow_self_origin() {
743-
self.published_message_ids.insert(msg_id.clone());
744-
}
745-
}
746-
747734
// Send to peers we know are subscribed to the topic.
748735
let mut publish_failed = true;
749736
for peer_id in recipient_peers.iter() {
@@ -1719,7 +1706,7 @@ where
17191706
own_id != propagation_source
17201707
&& raw_message.source.as_ref().is_some_and(|s| s == own_id)
17211708
} else {
1722-
self.published_message_ids.contains(msg_id)
1709+
false
17231710
};
17241711

17251712
if self_published {

protocols/gossipsub/src/config.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ pub struct Config {
127127
max_ihave_length: usize,
128128
max_ihave_messages: usize,
129129
iwant_followup_time: Duration,
130-
published_message_ids_cache_time: Duration,
131130
connection_handler_queue_len: usize,
132131
connection_handler_publish_duration: Duration,
133132
connection_handler_forward_duration: Duration,
@@ -444,11 +443,6 @@ impl Config {
444443
self.protocol.protocol_ids.contains(&FLOODSUB_PROTOCOL)
445444
}
446445

447-
/// Published message ids time cache duration. The default is 10 seconds.
448-
pub fn published_message_ids_cache_time(&self) -> Duration {
449-
self.published_message_ids_cache_time
450-
}
451-
452446
/// The max number of messages a `ConnectionHandler` can buffer. The default is 5000.
453447
pub fn connection_handler_queue_len(&self) -> usize {
454448
self.connection_handler_queue_len
@@ -546,7 +540,6 @@ impl Default for ConfigBuilder {
546540
max_ihave_length: 5000,
547541
max_ihave_messages: 10,
548542
iwant_followup_time: Duration::from_secs(3),
549-
published_message_ids_cache_time: Duration::from_secs(10),
550543
connection_handler_queue_len: 5000,
551544
connection_handler_publish_duration: Duration::from_secs(5),
552545
connection_handler_forward_duration: Duration::from_secs(1),
@@ -1008,15 +1001,6 @@ impl ConfigBuilder {
10081001
self
10091002
}
10101003

1011-
/// Published message ids time cache duration. The default is 10 seconds.
1012-
pub fn published_message_ids_cache_time(
1013-
&mut self,
1014-
published_message_ids_cache_time: Duration,
1015-
) -> &mut Self {
1016-
self.config.published_message_ids_cache_time = published_message_ids_cache_time;
1017-
self
1018-
}
1019-
10201004
/// The max number of messages a `ConnectionHandler` can buffer. The default is 5000.
10211005
pub fn connection_handler_queue_len(&mut self, len: usize) -> &mut Self {
10221006
self.config.connection_handler_queue_len = len;
@@ -1177,10 +1161,6 @@ impl std::fmt::Debug for Config {
11771161
let _ = builder.field("max_ihave_length", &self.max_ihave_length);
11781162
let _ = builder.field("max_ihave_messages", &self.max_ihave_messages);
11791163
let _ = builder.field("iwant_followup_time", &self.iwant_followup_time);
1180-
let _ = builder.field(
1181-
"published_message_ids_cache_time",
1182-
&self.published_message_ids_cache_time,
1183-
);
11841164
let _ = builder.field(
11851165
"idontwant_message_size_threshold",
11861166
&self.idontwant_message_size_threshold,

0 commit comments

Comments
 (0)