Skip to content

Commit 58f66cf

Browse files
apollo_network: changed gossipsub configurations
1 parent 8560f89 commit 58f66cf

File tree

2 files changed

+66
-16
lines changed

2 files changed

+66
-16
lines changed

crates/apollo_network/src/gossipsub_impl.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ impl From<gossipsub::Event> for mixed_behaviour::Event {
2323
message: gossipsub::Message { data, topic, source, .. },
2424
..
2525
} => {
26-
let Some(originated_peer_id) = source else {
27-
error!(
28-
"Received a message from gossipsub without source even though we've \
29-
configured it to reject such messages"
30-
);
31-
return mixed_behaviour::Event::ToOtherBehaviourEvent(
32-
mixed_behaviour::ToOtherBehaviourEvent::NoOp,
33-
);
34-
};
26+
// let Some(originated_peer_id) = source else {
27+
// error!(
28+
// "Received a message from gossipsub without source even though we've \
29+
// configured it to reject such messages"
30+
// );
31+
// return mixed_behaviour::Event::ToOtherBehaviourEvent(
32+
// mixed_behaviour::ToOtherBehaviourEvent::NoOp,
33+
// );
34+
// };
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: 56 additions & 7 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;
@@ -81,8 +83,59 @@ impl MixedBehaviour {
8183
StreamProtocol::try_from_owned(format!("/starknet/kad/{chain_id}/1.0.0"))
8284
.expect("Failed to create StreamProtocol from a string that starts with /");
8385
let kademlia_config = kad::Config::new(protocol_name);
84-
let connection_limits = ConnectionLimits::default().with_max_established_per_peer(Some(1));
86+
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+
.message_id_fn(|message| {
94+
let mut source_string = message.source.as_ref().map(|id| id.to_bytes()).unwrap_or_default();
95+
source_string
96+
.extend_from_slice(&message.sequence_number.unwrap_or_default().to_be_bytes());
97+
source_string.extend_from_slice(&message.data[0..16]);
98+
gossipsub::MessageId::from(source_string)
99+
})
100+
101+
102+
// .max_messages_per_rpc(Some(1))
103+
.history_length(5)
104+
105+
// .connection_handler_queue_len(50_000)
106+
107+
.mesh_n(99) // Target mesh peers
108+
.mesh_n_low(99) // Minimum before adding (default: 5)
109+
.mesh_n_high(99) // Maximum before pruning (default
110+
// .publish_queue_duration(Duration::from_millis(500)) // default: 5s
111+
// .forward_queue_duration(Duration::from_millis(100)) // default: 1s
112+
113+
114+
// .heartbeat_interval(Duration::from_millis(200))
115+
// Set gossip_lazy to 0 - minimum number of peers to gossip to
116+
.gossip_lazy(0)
117+
118+
// Set gossip_factor to 0.0 - factor for dynamic gossip peer selection
119+
.gossip_factor(0.0)
120+
121+
// Set history_gossip to 0 - number of past heartbeats to gossip about
122+
.history_gossip(0)
123+
124+
// Optional: Set max_ihave_length to 0 - maximum IHAVE message IDs per message
125+
.max_ihave_length(0)
126+
127+
// Optional: Set max_ihave_messages to 0 - maximum IHAVE messages per heartbeat
128+
.max_ihave_messages(0)
129+
130+
// Optional: Set gossip_retransmission to 0 - disable IWANT retries
131+
.gossip_retransimission(0)
132+
133+
// Enable IDONTWANT optimization
134+
// .idontwant_message_size_threshold(1000) // Adjust based on your message sizes
135+
.idontwant_on_publish(true) // Prevent echo-back on publish
136+
137+
.build()
138+
.expect("Failed to build gossipsub config");
86139
Self {
87140
limits: connection_limits::Behaviour::new(connection_limits),
88141
peer_manager: peer_manager::PeerManager::new(peer_manager_config),
@@ -123,12 +176,8 @@ impl MixedBehaviour {
123176
),
124177
sqmr: sqmr::Behaviour::new(streamed_bytes_config),
125178
gossipsub: gossipsub::Behaviour::new(
126-
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"),
179+
gossipsub::MessageAuthenticity::Author(local_peer_id),
180+
gossipsub_config,
132181
)
133182
.unwrap_or_else(|err_string| {
134183
panic!(

0 commit comments

Comments
 (0)