Skip to content

Commit b800df5

Browse files
committed
fix(gossipsub): tweak configs to reduce duplicated msgs
1 parent e7fe13d commit b800df5

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

crates/p2p/src/swarm/behavior.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Request-Response [`Behaviour`] and [`NetworkBehaviour`] for the P2P protocol.
22
3-
use std::collections::HashSet;
3+
use std::{collections::HashSet, time::Duration};
44

55
use blake3::hash;
66
use libp2p::{
@@ -69,19 +69,15 @@ impl Behaviour {
6969
.validate_messages()
7070
.max_transmit_size(MAX_TRANSMIT_SIZE)
7171
// Avoids spamming the network and nodes with messages
72-
.idontwant_on_publish(true)
73-
// We want a unique message id for each message, so we use the hash of the
74-
// message data instead of the default one, that is the concatenation of the
75-
// PeerId and the sequence number of the message.
76-
//
77-
// NOTE(@storopoli): I don't trust the default one, since we are not using the
78-
// LibP2P's Message template, hence the sequence number might
79-
// not exist, and in that case it is always be set to 0 by
80-
// default.
81-
.message_id_fn(|msg| {
82-
let hash = hash(msg.data.as_ref());
83-
MessageId::new(hash.as_bytes())
84-
})
72+
.duplicate_cache_time(Duration::from_secs(60 * 5)) // default is 1 min
73+
.published_message_ids_cache_time(Duration::from_secs(60)) // default is 10
74+
.max_ihave_messages(100) // default is 10
75+
.gossip_retransimission(1) // default is 3
76+
.iwant_followup_time(Duration::from_secs(2)) // default is 3
77+
.gossip_lazy(2) // default is 6
78+
.gossip_factor(0.1) // default is 0.25
79+
.history_gossip(1) // default is 3
80+
.history_length(3) // default is 5
8581
.build()
8682
.expect("gossipsub config at this stage must be valid"),
8783
None,

0 commit comments

Comments
 (0)