Handling Duplicate Messages in libp2p with gossipsub #5278
-
Description: I'm using libp2p with gossipsub for message publication and subscription in my application. I have configured gossipsub with a duplicate cache time of 1 second, intending to allow duplicate messages after this interval. However, I'm encountering a "Duplicate" error when publishing messages even after the specified time interval has passed. Code Snippet: let gossipsub_config = gossipsub::ConfigBuilder::default()
.heartbeat_interval(Duration::from_secs(10))
.validation_mode(gossipsub::ValidationMode::Strict)
.duplicate_cache_time(Duration::from_secs(1))
.published_message_ids_cache_time(Duration::from_secs(1))
.message_id_fn(message_id_fn)
.build()
.map_err(|msg| io::Error::new(io::ErrorKind::Other, msg))?; Questions:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hi, have you seen #2587 (comment) ? rust-libp2p/protocols/gossipsub/src/behaviour.rs Lines 607 to 616 in ab4f664 but rust-libp2p/protocols/gossipsub/src/time_cache.rs Lines 172 to 179 in ab4f664 rust-libp2p/protocols/gossipsub/src/time_cache.rs Lines 133 to 144 in ab4f664 not when contains() is called:rust-libp2p/protocols/gossipsub/src/time_cache.rs Lines 181 to 184 in ab4f664 I'd say you are probably trying to send the same message sequentially |
Beta Was this translation helpful? Give feedback.
-
Duplicates on gossipsub should be expressly forbidden. In an ideal world, gossipsub should never permit duplicates, however we are limited in resources (i.e RAM) such that we can't remember all messages for an infinite amount of time. Given these constraints, sometimes a duplicate can get through, in Rust, we loosely time-bound the message. The time-bound ensures that no duplicates will happen within that time (i.e 1 second) but may prevent duplicates longer. With unlimited resources, we'd set this time limit to infinity. This begs the question, why do you want duplicates? Duplicates are a source of amplification and excess bandwidth use in gossipsub. We don't want old messages permanently being slowly bouncing around the network and re-transmitted forever, so having a large enough cache prevents this. A message is determined by its message-id. In your code-snippet you have changed the default message to something else but have not said what it is. The default message-id has a sequence number associated with it. So if you had a chat app, and wanted to send the message "hey" and then send "hey" again immediately after, this would be fine. These messages are not duplicates because the message-id will be different. If you have a message whose contents need to be re-transmitted regularly, it sounds like your message-id is not correctly built for it.
Yep, sounds like you need to change your message-id so that it is unique per message you want to transmit.
I don't really follow this. Gossipsub works fine with public addresses. This is part of libp2p, you can dial any public multiaddr. I think there is minimal difference in libp2p between public/private addresses. |
Beta Was this translation helpful? Give feedback.
-
To add to above, the default rust-libp2p/protocols/gossipsub/src/config.rs Lines 389 to 402 in b890b29 However, if youre going based on the chat example the message id would likely be the same if the message is the same because it generates it from the hash rust-libp2p/examples/chat/src/main.rs Lines 55 to 59 in b890b29 I would suggest omitting that segment of code as well as the |
Beta Was this translation helpful? Give feedback.
Hi, have you seen #2587 (comment) ?
But basically, when publishing via
gossipsub
, it checks onDuplicateCache
if contains the entry:rust-libp2p/protocols/gossipsub/src/behaviour.rs
Lines 607 to 616 in ab4f664
but
DuplicateCache
only removes stale entries when you insert a new mess…