Repository navigation
Limit control message size of RPCs - #707
Merged
Merged
Conversation
MarcoPolo
force-pushed
the
marco/limit-control-message-size
branch
from
May 29, 2026 22:59
202759d to
b953720
Compare
MarcoPolo
force-pushed
the
marco/migrate-to-google-pb
branch
from
May 30, 2026 00:09
62d9b32 to
b33023e
Compare
MarcoPolo
force-pushed
the
marco/limit-control-message-size
branch
from
May 30, 2026 00:09
b953720 to
5806415
Compare
sukunrt
approved these changes
Jun 29, 2026
Comment on lines
+571
to
+579
| func controlRPCSize(rpc *RPC) int { | ||
| if rpc == nil { | ||
| return 0 | ||
| } | ||
| return proto.Size(&pb.RPC{ | ||
| Subscriptions: rpc.Subscriptions, | ||
| Control: rpc.Control, | ||
| }) | ||
| } |
Member
There was a problem hiding this comment.
maybe set publish and partial to nil here to check the length. This will help avoid allocation.
Member
There was a problem hiding this comment.
it'll also make it similar to the validation on the inbound side.
Contributor
Author
There was a problem hiding this comment.
changed so this func doesn't allocate
Assisted-By: GPT-5.5
Bytes that aren't part of the message data now contribute to the control byte limit.
Assisted-By: GPT-5.5
MarcoPolo
force-pushed
the
marco/limit-control-message-size
branch
from
July 3, 2026 19:31
5806415 to
0d4b712
Compare
7 tasks
lucassaldanha
added a commit
to libp2p/jvm-libp2p
that referenced
this pull request
Aug 28, 2026
Add maxControlMessageSize to PubsubRpcLimits and accumulate the control-plane wire size during the walk validateRpc already performs, rejecting the frame before it reaches ProtobufDecoder if the total exceeds the limit. Subscriptions and control are charged in full, as is every other top-level field, known or unknown. Publish and RPC.partial are charged for their envelope with only their opaque payload lengths exempt (Message.data, partialMessage, partsMetadata), so large payloads stay cheap while envelope-heavy frames do not. Unknown fields consume the budget rather than triggering rejection. go-libp2p retains and re-emits unknown fields, so rejecting them would break interop on the next schema addition anywhere in the ecosystem. Follows the same approach as libp2p/go-libp2p-pubsub#707 and libp2p/rust-libp2p#6468, which both bound control size ahead of decoding rather than counting per-field. Co-authored-by: Enrico Del Fante <enrico.delfante@consensys.net>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a new option to limit to total size of control fields (including subscriptions) when receiving a pb rpc. This fixes an issue where allowing a large message payload should not also allow a large amount of control messages at once.
This depends on #706