From 2baa34de0ca2f9ada144a7845aeea43f927b0e24 Mon Sep 17 00:00:00 2001 From: Dzmitry Kalabuk Date: Mon, 21 Oct 2024 12:18:21 +0300 Subject: [PATCH 1/3] Apply `max_transmit_size` to the inner message instead of the final payload --- Cargo.lock | 2 +- Cargo.toml | 2 +- protocols/gossipsub/CHANGELOG.md | 5 +++++ protocols/gossipsub/Cargo.toml | 2 +- protocols/gossipsub/src/behaviour.rs | 10 +++++----- protocols/gossipsub/src/config.rs | 3 ++- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 40ff97009de..7395651f82e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2741,7 +2741,7 @@ dependencies = [ [[package]] name = "libp2p-gossipsub" -version = "0.47.1" +version = "0.48.0" dependencies = [ "async-std", "asynchronous-codec", diff --git a/Cargo.toml b/Cargo.toml index 7b52e4a7b42..1e33c773f89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -83,7 +83,7 @@ libp2p-core = { version = "0.42.0", path = "core" } libp2p-dcutr = { version = "0.12.0", path = "protocols/dcutr" } libp2p-dns = { version = "0.42.0", path = "transports/dns" } libp2p-floodsub = { version = "0.45.0", path = "protocols/floodsub" } -libp2p-gossipsub = { version = "0.47.1", path = "protocols/gossipsub" } +libp2p-gossipsub = { version = "0.48.0", path = "protocols/gossipsub" } libp2p-identify = { version = "0.45.1", path = "protocols/identify" } libp2p-identity = { version = "0.2.9" } libp2p-kad = { version = "0.47.0", path = "protocols/kad" } diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index c47a9f40f66..d7ca9c93daa 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.48.0 + +- Apply `max_transmit_size` to the inner message instead of the final payload. + See [Discussion 5598](https://github.com/libp2p/rust-libp2p/discussions/5598). + ## 0.47.1 - Attempt to publish to at least mesh_n peers when flood publish is disabled. diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index 665f757fcb3..734ac36a231 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-gossipsub" edition = "2021" rust-version = { workspace = true } description = "Gossipsub protocol for libp2p" -version = "0.47.1" +version = "0.48.0" authors = ["Age Manning "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 16adb555a44..a9b9c1942f8 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -583,6 +583,11 @@ where .data_transform .outbound_transform(&topic, data.clone())?; + // check that the size doesn't exceed the max transmission size + if transformed_data.len() > self.config.max_transmit_size() { + return Err(PublishError::MessageTooLarge); + } + let raw_message = self.build_raw_message(topic, transformed_data)?; // calculate the message id from the un-transformed data @@ -593,11 +598,6 @@ where topic: raw_message.topic.clone(), }); - // check that the size doesn't exceed the max transmission size - if raw_message.raw_protobuf_len() > self.config.max_transmit_size() { - return Err(PublishError::MessageTooLarge); - } - // Check the if the message has been published before if self.duplicate_cache.contains(&msg_id) { // This message has already been seen. We don't re-publish messages that have already diff --git a/protocols/gossipsub/src/config.rs b/protocols/gossipsub/src/config.rs index febe2514a30..1ee2e940661 100644 --- a/protocols/gossipsub/src/config.rs +++ b/protocols/gossipsub/src/config.rs @@ -174,7 +174,8 @@ impl Config { /// The maximum byte size for each gossipsub RPC (default is 65536 bytes). /// - /// This represents the maximum size of the entire protobuf payload. It must be at least + /// This represents the maximum size of the published message. It is additionally wrapped + /// in a protobuf struct, so the actual wire size may be a bit larger. It must be at least /// large enough to support basic control messages. If Peer eXchange is enabled, this /// must be large enough to transmit the desired peer information on pruning. It must be at /// least 100 bytes. Default is 65536 bytes. From d6881e733408859f125fc943162ccc31e3d60fcf Mon Sep 17 00:00:00 2001 From: Dzmitry Kalabuk Date: Tue, 22 Oct 2024 17:43:31 +0300 Subject: [PATCH 2/3] Update protocols/gossipsub/CHANGELOG.md Co-authored-by: Darius Clark --- protocols/gossipsub/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index d7ca9c93daa..cdd170c0d4b 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -1,7 +1,7 @@ ## 0.48.0 - Apply `max_transmit_size` to the inner message instead of the final payload. - See [Discussion 5598](https://github.com/libp2p/rust-libp2p/discussions/5598). + See [PR 5642](https://github.com/libp2p/rust-libp2p/pull/5642). ## 0.47.1 From 15aaf3a09de3dd7dd6c721793d0dd67265a1cebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Fri, 25 Oct 2024 10:43:10 +0100 Subject: [PATCH 3/3] Update protocols/gossipsub/src/behaviour.rs --- protocols/gossipsub/src/behaviour.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index a9b9c1942f8..6ddb25316e5 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -583,7 +583,7 @@ where .data_transform .outbound_transform(&topic, data.clone())?; - // check that the size doesn't exceed the max transmission size + // check that the size doesn't exceed the max transmission size. if transformed_data.len() > self.config.max_transmit_size() { return Err(PublishError::MessageTooLarge); }