Skip to content

Commit c7e8129

Browse files
kalabukdimadariusc93jxs
authored
feat(gossipsub): apply max_transmit_size to the published message (#5642)
## Description When trying to publish a message using gossipsub's `publish` method, it should be possible to predict whether it will fit in the limit defined by the `max_transmit_size` config option. If this limit applies to the final protobuf payload, it's not possible to know that in advance because the size of the added fields is not fixed. This change makes the limit apply to the passed message size instead of the final wire size. ## Notes & open questions This is a minor version change because it changes the meaning of the existing config option. However, for the existing clients the limit will only become more permissive, so it shouldn't break anything. ## Change checklist <!-- Please add a Changelog entry in the appropriate crates and bump the crate versions if needed. See <https://github.com/libp2p/rust-libp2p/blob/master/docs/release.md#development-between-releases>--> - [x] I have performed a self-review of my own code - [x] I have made corresponding changes to the documentation - [ ] I have added tests that prove my fix is effective or that my feature works - [x] A changelog entry has been made in the appropriate crates --------- Co-authored-by: Darius Clark <[email protected]> Co-authored-by: João Oliveira <[email protected]>
1 parent 84c617f commit c7e8129

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ libp2p-core = { version = "0.42.0", path = "core" }
8383
libp2p-dcutr = { version = "0.12.0", path = "protocols/dcutr" }
8484
libp2p-dns = { version = "0.42.0", path = "transports/dns" }
8585
libp2p-floodsub = { version = "0.45.0", path = "protocols/floodsub" }
86-
libp2p-gossipsub = { version = "0.47.1", path = "protocols/gossipsub" }
86+
libp2p-gossipsub = { version = "0.48.0", path = "protocols/gossipsub" }
8787
libp2p-identify = { version = "0.45.1", path = "protocols/identify" }
8888
libp2p-identity = { version = "0.2.9" }
8989
libp2p-kad = { version = "0.47.0", path = "protocols/kad" }

protocols/gossipsub/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.48.0
2+
3+
- Apply `max_transmit_size` to the inner message instead of the final payload.
4+
See [PR 5642](https://github.com/libp2p/rust-libp2p/pull/5642).
5+
16
## 0.47.1
27

38
- Attempt to publish to at least mesh_n peers when flood publish is disabled.

protocols/gossipsub/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "libp2p-gossipsub"
33
edition = "2021"
44
rust-version = { workspace = true }
55
description = "Gossipsub protocol for libp2p"
6-
version = "0.47.1"
6+
version = "0.48.0"
77
authors = ["Age Manning <[email protected]>"]
88
license = "MIT"
99
repository = "https://github.com/libp2p/rust-libp2p"

protocols/gossipsub/src/behaviour.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,11 @@ where
583583
.data_transform
584584
.outbound_transform(&topic, data.clone())?;
585585

586+
// check that the size doesn't exceed the max transmission size.
587+
if transformed_data.len() > self.config.max_transmit_size() {
588+
return Err(PublishError::MessageTooLarge);
589+
}
590+
586591
let raw_message = self.build_raw_message(topic, transformed_data)?;
587592

588593
// calculate the message id from the un-transformed data
@@ -593,11 +598,6 @@ where
593598
topic: raw_message.topic.clone(),
594599
});
595600

596-
// check that the size doesn't exceed the max transmission size
597-
if raw_message.raw_protobuf_len() > self.config.max_transmit_size() {
598-
return Err(PublishError::MessageTooLarge);
599-
}
600-
601601
// Check the if the message has been published before
602602
if self.duplicate_cache.contains(&msg_id) {
603603
// This message has already been seen. We don't re-publish messages that have already

protocols/gossipsub/src/config.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ impl Config {
174174

175175
/// The maximum byte size for each gossipsub RPC (default is 65536 bytes).
176176
///
177-
/// This represents the maximum size of the entire protobuf payload. It must be at least
177+
/// This represents the maximum size of the published message. It is additionally wrapped
178+
/// in a protobuf struct, so the actual wire size may be a bit larger. It must be at least
178179
/// large enough to support basic control messages. If Peer eXchange is enabled, this
179180
/// must be large enough to transmit the desired peer information on pruning. It must be at
180181
/// least 100 bytes. Default is 65536 bytes.

0 commit comments

Comments
 (0)