Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions beacon_node/lighthouse_network/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1812,9 +1812,6 @@ where
// Calculate the message id on the transformed data.
let msg_id = self.config.message_id(&message);

// Broadcast IDONTWANT messages.
self.send_idontwant(&raw_message, &msg_id, propagation_source);

// Check the validity of the message
// Peers get penalized if this message is invalid. We don't add it to the duplicate cache
// and instead continually penalize peers that repeatedly send this message.
Expand All @@ -1828,8 +1825,13 @@ where
peer_score.duplicated_message(propagation_source, &msg_id, &message.topic);
}
self.mcache.observe_duplicate(&msg_id, propagation_source);

return;
}

// Broadcast IDONTWANT messages.
self.send_idontwant(&raw_message, &msg_id, propagation_source);

tracing::debug!(
message=%msg_id,
"Put message in duplicate_cache and resolve promises"
Expand Down Expand Up @@ -2699,6 +2701,10 @@ where
return;
};

if message.raw_protobuf_len() < self.config.idontwant_message_size_threshold(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this check to line 1833? So that it's explicit that we are only calling send_idontwant if the message size is inferior to the threshold instead of having the function decide that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also the the logic was a little off. I have changed it and written passing test for the same

return;
}

let iwant_peers = self.gossip_promises.peers_for_message(msg_id);

let recipient_peers = mesh_peers
Expand Down
24 changes: 24 additions & 0 deletions beacon_node/lighthouse_network/gossipsub/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub struct Config {
connection_handler_queue_len: usize,
connection_handler_publish_duration: Duration,
connection_handler_forward_duration: Duration,
idontwant_message_size_threshold: usize,
}

impl Config {
Expand Down Expand Up @@ -370,6 +371,16 @@ impl Config {
pub fn forward_queue_duration(&self) -> Duration {
self.connection_handler_forward_duration
}

// Controls the message size threshold for which IDONTWANT messages are sent.
// Sending IDONTWANT messages for small messages can have a negative effect to the overall
// traffic and CPU load. This acts as a lower bound cutoff for the message size to which
// IDONTWANT won't be sent to peers. Only works if the peers support Gossipsub1.3
// (see https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.2.md#idontwant-message)
// default is 1kB
pub fn idontwant_message_size_threshold(&self) -> usize{
self.idontwant_message_size_threshold
}
}

impl Default for Config {
Expand Down Expand Up @@ -440,6 +451,7 @@ impl Default for ConfigBuilder {
connection_handler_queue_len: 5000,
connection_handler_publish_duration: Duration::from_secs(5),
connection_handler_forward_duration: Duration::from_millis(1000),
idontwant_message_size_threshold: 1000,
},
invalid_protocol: false,
}
Expand Down Expand Up @@ -825,6 +837,17 @@ impl ConfigBuilder {
self
}

// Controls the message size threshold for which IDONTWANT messages are sent.
// Sending IDONTWANT messages for small messages can have a negative effect to the overall
// traffic and CPU load. This acts as a lower bound cutoff for the message size to which
// IDONTWANT won't be sent to peers. Only works if the peers support Gossipsub1.3
// (see https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.2.md#idontwant-message)
// default is 1kB
pub fn idontwant_message_size_threshold(&mut self, size: usize) -> &mut Self {
self.config.idontwant_message_size_threshold = size;
self
}

/// Constructs a [`Config`] from the given configuration and validates the settings.
pub fn build(&self) -> Result<Config, ConfigBuilderError> {
// check all constraints on config
Expand Down Expand Up @@ -895,6 +918,7 @@ impl std::fmt::Debug for Config {
"published_message_ids_cache_time",
&self.published_message_ids_cache_time,
);
let _ = builder.field("idontwant_message_size_threhold",&self.idontwant_message_size_threshold);
builder.finish()
}
}
Expand Down
Loading