Skip to content

Commit 91f672d

Browse files
apollo_network: changed gossipsub configurations
1 parent e89d64b commit 91f672d

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 apollo_propeller::metrics::PropellerMetrics;
67
use apollo_propeller::{self as propeller};
@@ -88,6 +89,57 @@ impl MixedBehaviour {
8889
let kademlia_config = kad::Config::new(protocol_name);
8990
let connection_limits = ConnectionLimits::default(); // .with_max_established_per_peer(Some(1));
9091

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

0 commit comments

Comments
 (0)