Skip to content

Commit 8a61ed7

Browse files
apollo_network: changed gossipsub configurations
1 parent 8af0e4d commit 8a61ed7

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

crates/apollo_network/src/gossipsub_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ impl From<gossipsub::Event> for mixed_behaviour::Event {
3232
mixed_behaviour::ToOtherBehaviourEvent::NoOp,
3333
);
3434
};
35+
// let originated_peer_id = source.unwrap_or_else(PeerId::random);
3536
mixed_behaviour::Event::ExternalEvent(mixed_behaviour::ExternalEvent::GossipSub(
3637
ExternalEvent::Received {
3738
originated_peer_id,

crates/apollo_network/src/mixed_behaviour.rs

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
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;
7+
use libp2p::gossipsub::ValidationMode;
68
use libp2p::identity::Keypair;
79
use libp2p::kad::store::MemoryStore;
810
use libp2p::swarm::behaviour::toggle::Toggle;
@@ -83,6 +85,49 @@ impl MixedBehaviour {
8385
let kademlia_config = kad::Config::new(protocol_name);
8486
let connection_limits = ConnectionLimits::default().with_max_established_per_peer(Some(1));
8587

88+
let gossipsub_config = gossipsub::ConfigBuilder::default()
89+
.max_transmit_size(1 << 34)
90+
.flood_publish(false)
91+
.heartbeat_interval(Duration::from_millis(700))
92+
// .validation_mode(ValidationMode::None)
93+
94+
// .max_messages_per_rpc(Some(1))
95+
.history_length(5)
96+
97+
// .connection_handler_queue_len(50_000)
98+
99+
.mesh_n(12) // Target mesh peers
100+
.mesh_n_low(8) // Minimum before adding (default: 5)
101+
.mesh_n_high(20) // Maximum before pruning (default
102+
// .publish_queue_duration(Duration::from_millis(500)) // default: 5s
103+
// .forward_queue_duration(Duration::from_millis(100)) // default: 1s
104+
105+
106+
// .heartbeat_interval(Duration::from_millis(200))
107+
// Set gossip_lazy to 0 - minimum number of peers to gossip to
108+
.gossip_lazy(0)
109+
110+
// Set gossip_factor to 0.0 - factor for dynamic gossip peer selection
111+
.gossip_factor(0.0)
112+
113+
// Set history_gossip to 0 - number of past heartbeats to gossip about
114+
.history_gossip(0)
115+
116+
// Optional: Set max_ihave_length to 0 - maximum IHAVE message IDs per message
117+
.max_ihave_length(0)
118+
119+
// Optional: Set max_ihave_messages to 0 - maximum IHAVE messages per heartbeat
120+
.max_ihave_messages(0)
121+
122+
// Optional: Set gossip_retransmission to 0 - disable IWANT retries
123+
.gossip_retransimission(0)
124+
125+
// Enable IDONTWANT optimization
126+
// .idontwant_message_size_threshold(1000) // Adjust based on your message sizes
127+
.idontwant_on_publish(true) // Prevent echo-back on publish
128+
129+
.build()
130+
.expect("Failed to build gossipsub config");
86131
Self {
87132
limits: connection_limits::Behaviour::new(connection_limits),
88133
peer_manager: peer_manager::PeerManager::new(peer_manager_config),
@@ -124,11 +169,7 @@ impl MixedBehaviour {
124169
sqmr: sqmr::Behaviour::new(streamed_bytes_config),
125170
gossipsub: gossipsub::Behaviour::new(
126171
gossipsub::MessageAuthenticity::Signed(keypair),
127-
gossipsub::ConfigBuilder::default()
128-
// TODO(shahak): try to reduce this bound.
129-
.max_transmit_size(1 << 34)
130-
.build()
131-
.expect("Failed to build gossipsub config"),
172+
gossipsub_config,
132173
)
133174
.unwrap_or_else(|err_string| {
134175
panic!(

0 commit comments

Comments
 (0)