Skip to content

Commit d07ab5f

Browse files
apollo_network: changed gossipsub configurations
1 parent 63cf480 commit d07ab5f

File tree

1 file changed

+54
-6
lines changed

1 file changed

+54
-6
lines changed

crates/apollo_network/src/mixed_behaviour.rs

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// TODO(shahak): Erase main_behaviour and make this a separate module.
22

33
use std::convert::Infallible;
4+
use std::time::Duration;
45

56
use libp2p::connection_limits::ConnectionLimits;
67
use libp2p::identity::Keypair;
@@ -94,6 +95,57 @@ impl MixedBehaviour {
9495
let kademlia_config = kad::Config::new(protocol_name);
9596
let connection_limits = ConnectionLimits::default(); // .with_max_established_per_peer(Some(1));
9697

98+
let gossipsub_config = gossipsub::ConfigBuilder::default()
99+
.max_transmit_size(1 << 34)
100+
.flood_publish(false)
101+
.heartbeat_interval(Duration::from_millis(700))
102+
// .validation_mode(ValidationMode::None)
103+
.message_id_fn(|message| {
104+
let mut source_string = message.source.as_ref().map(|id| id.to_bytes()).unwrap_or_default();
105+
source_string
106+
.extend_from_slice(&message.sequence_number.unwrap_or_default().to_be_bytes());
107+
source_string.extend_from_slice(&message.data[0..16]);
108+
gossipsub::MessageId::from(source_string)
109+
})
110+
111+
112+
// .max_messages_per_rpc(Some(1))
113+
.history_length(5)
114+
115+
// .connection_handler_queue_len(50_000)
116+
117+
.mesh_n(10) // Target mesh peers
118+
.mesh_n_low(10) // Minimum before adding (default: 5)
119+
.mesh_n_high(10) // Maximum before pruning (default
120+
// .publish_queue_duration(Duration::from_millis(500)) // default: 5s
121+
// .forward_queue_duration(Duration::from_millis(100)) // default: 1s
122+
123+
124+
// .heartbeat_interval(Duration::from_millis(200))
125+
// Set gossip_lazy to 0 - minimum number of peers to gossip to
126+
.gossip_lazy(0)
127+
128+
// Set gossip_factor to 0.0 - factor for dynamic gossip peer selection
129+
.gossip_factor(0.0)
130+
131+
// Set history_gossip to 0 - number of past heartbeats to gossip about
132+
.history_gossip(0)
133+
134+
// Optional: Set max_ihave_length to 0 - maximum IHAVE message IDs per message
135+
.max_ihave_length(0)
136+
137+
// Optional: Set max_ihave_messages to 0 - maximum IHAVE messages per heartbeat
138+
.max_ihave_messages(0)
139+
140+
// Optional: Set gossip_retransmission to 0 - disable IWANT retries
141+
.gossip_retransimission(0)
142+
143+
// Enable IDONTWANT optimization
144+
// .idontwant_message_size_threshold(1000) // Adjust based on your message sizes
145+
.idontwant_on_publish(true) // Prevent echo-back on publish
146+
147+
.build()
148+
.expect("Failed to build gossipsub config");
97149
Self {
98150
limits: connection_limits::Behaviour::new(connection_limits),
99151
peer_manager: peer_manager::PeerManager::new(peer_manager_config),
@@ -134,12 +186,8 @@ impl MixedBehaviour {
134186
),
135187
sqmr: sqmr::Behaviour::new(streamed_bytes_config),
136188
gossipsub: gossipsub::Behaviour::new(
137-
gossipsub::MessageAuthenticity::Signed(keypair.clone()),
138-
gossipsub::ConfigBuilder::default()
139-
// TODO(shahak): try to reduce this bound.
140-
.max_transmit_size(1 << 34)
141-
.build()
142-
.expect("Failed to build gossipsub config"),
189+
gossipsub::MessageAuthenticity::Signed(keypair.clone()),
190+
gossipsub_config,
143191
)
144192
.unwrap_or_else(|err_string| {
145193
panic!(

0 commit comments

Comments
 (0)