-
Notifications
You must be signed in to change notification settings - Fork 35
fix(network): align gossipsub max_transmit_size with consensus spec #717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1439,7 +1439,7 @@ impl Behaviour { | |
| .validation_mode(gossipsub::ValidationMode::Anonymous) | ||
| .history_length(6) | ||
| .duplicate_cache_time(Duration::from_secs(3 * 4 * 2)) | ||
| .max_transmit_size(2 * 1024 * 1024) // 2 MiB for blocks/ aggregated payloads | ||
| .max_transmit_size(crate::req_resp::configurations::max_message_size()) | ||
| .message_id_fn(message_id_fn) // content-address messages. No two messages of the same content will be propagated. | ||
|
Comment on lines
1439
to
1443
|
||
| .build() | ||
| .unwrap(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,15 +2,23 @@ | |||||||||||||||||||||||||||||||||
| /// as we still need rust-libp2p until we fully migrate to zig-libp2p. It needs the custom RPC protocol implementation. | ||||||||||||||||||||||||||||||||||
| use std::time::Duration; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /// Maximum allowed size for a single RPC payload (compressed). | ||||||||||||||||||||||||||||||||||
| pub const MAX_MESSAGE_SIZE: usize = 4 * 1024 * 1024; // 4 MiB | ||||||||||||||||||||||||||||||||||
| /// Maximum uncompressed payload size (10 MiB), per Ethereum consensus spec. | ||||||||||||||||||||||||||||||||||
| pub const MAX_PAYLOAD_SIZE: usize = 10 * 1024 * 1024; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /// Snappy worst-case compressed length for a payload of size `n`. | ||||||||||||||||||||||||||||||||||
| pub const fn max_compressed_len(n: usize) -> usize { | ||||||||||||||||||||||||||||||||||
| 32 + n + n / 6 | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /// Spec-derived maximum message size: snappy worst-case of MAX_PAYLOAD_SIZE + 1024 bytes | ||||||||||||||||||||||||||||||||||
| /// framing overhead, with a floor of 1 MiB. | ||||||||||||||||||||||||||||||||||
| /// Matches ream / grandine / lighthouse: `max(max_compressed_len(MAX_PAYLOAD_SIZE) + 1024, 1 MiB)`. | ||||||||||||||||||||||||||||||||||
| pub fn max_message_size() -> usize { | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+13
to
+16
|
||||||||||||||||||||||||||||||||||
| /// Spec-derived maximum message size: snappy worst-case of MAX_PAYLOAD_SIZE + 1024 bytes | |
| /// framing overhead, with a floor of 1 MiB. | |
| /// Matches ream / grandine / lighthouse: `max(max_compressed_len(MAX_PAYLOAD_SIZE) + 1024, 1 MiB)`. | |
| pub fn max_message_size() -> usize { | |
| /// Maximum uncompressed message size accepted by req/resp codecs. | |
| /// This is the consensus-spec payload limit and must be used when validating | |
| /// a decoded `uncompressed_len` varint before allocation/decompression. | |
| pub const fn max_message_size() -> usize { | |
| MAX_PAYLOAD_SIZE | |
| } | |
| /// Maximum compressed/on-wire message size: snappy worst-case of | |
| /// `MAX_PAYLOAD_SIZE` + 1024 bytes framing overhead, with a floor of 1 MiB. | |
| /// Matches ream / grandine / lighthouse: | |
| /// `max(max_compressed_len(MAX_PAYLOAD_SIZE) + 1024, 1 MiB)`. | |
| pub fn max_compressed_message_size() -> usize { |
Copilot
AI
Apr 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
max_compressed_len uses unchecked usize addition; for large n this can wrap in release builds. Since this is a pub const fn, consider using checked/saturating arithmetic (and/or documenting expected bounds) to avoid overflow-driven miscalculation.
| 32 + n + n / 6 | |
| } | |
| /// Spec-derived maximum message size: snappy worst-case of MAX_PAYLOAD_SIZE + 1024 bytes | |
| /// framing overhead, with a floor of 1 MiB. | |
| /// Matches ream / grandine / lighthouse: `max(max_compressed_len(MAX_PAYLOAD_SIZE) + 1024, 1 MiB)`. | |
| pub fn max_message_size() -> usize { | |
| std::cmp::max(max_compressed_len(MAX_PAYLOAD_SIZE) + 1024, 1024 * 1024) | |
| 32usize.saturating_add(n).saturating_add(n / 6) | |
| } | |
| /// Spec-derived maximum message size: snappy worst-case of MAX_PAYLOAD_SIZE + 1024 bytes | |
| /// framing overhead, with a floor of 1 MiB. | |
| /// Matches ream / grandine / lighthouse: `max(max_compressed_len(MAX_PAYLOAD_SIZE) + 1024, 1 MiB)`. | |
| pub fn max_message_size() -> usize { | |
| std::cmp::max(max_compressed_len(MAX_PAYLOAD_SIZE).saturating_add(1024), 1024 * 1024) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
find ... | head -1can pick an arbitraryrec_aggregationdirectory if multiple checkouts exist (e.g., due to cached layers or multiple git deps), which would stage the wrong source tree and make the runtime fingerprint check fail. Consider validating there is exactly one match (and erroring with a clear message otherwise), or matching more precisely (e.g., locate the directory containingrec_aggregation/Cargo.toml).