Skip to content

Commit b17e4f7

Browse files
apollo_network: changed gossipsub configurations
1 parent f257c14 commit b17e4f7

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 as propeller;
67
use libp2p::connection_limits::ConnectionLimits;
@@ -86,6 +87,57 @@ impl MixedBehaviour {
8687
let kademlia_config = kad::Config::new(protocol_name);
8788
let connection_limits = ConnectionLimits::default(); // .with_max_established_per_peer(Some(1));
8889

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

0 commit comments

Comments
 (0)