IDONTWANT message optimisation to cutoff for smaller messages (#6456)

* idontwant message opitmising

* requested changes and linter appeasing

* added the config cli flag

* Merge branch 'unstable' into fix/idontwant-optimise

* cli docs generated

* const declaration

* Hide extra technical cli flag

* passing ci

* Merge branch 'unstable' into fix/idontwant-optimise
This commit is contained in:
hopinheimer
2024-10-17 04:27:56 -04:00
committed by GitHub
parent 7091c789c9
commit 606a113cff
7 changed files with 110 additions and 5 deletions

View File

@@ -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 {
@@ -370,6 +371,16 @@ impl Config {
pub fn forward_queue_duration(&self) -> Duration {
self.connection_handler_forward_duration
}
// 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.2
// (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 {
@@ -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,
}
@@ -825,6 +837,17 @@ impl ConfigBuilder {
self
}
// 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.2
// (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
@@ -895,6 +918,10 @@ 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()
}
}