fix(gossipsub): allow configuring max outbound message size - #3486
Open
paschal533 wants to merge 2 commits into
Open
fix(gossipsub): allow configuring max outbound message size#3486paschal533 wants to merge 2 commits into
paschal533 wants to merge 2 commits into
Conversation
…large messages Publishing a message larger than 4 MiB via pubsub.publish() failed with an opaque InvalidDataLengthError thrown deep inside the it-length-prefixed encoder. There was no way to raise the limit - unlike the inbound side which already exposed maxInboundDataLength. Add a matching maxOutboundDataLength option to GossipsubOpts. Wire it through OutboundStream so encode.single() respects the configured value instead of the hardcoded 4 MiB library default. Also pass it to the sendRpcInBatch() encode path which was previously uncovered. Add an early guard in publish() that fires before any protobuf encoding or network I/O, throwing with an actionable message that names the option and includes both the actual payload size and the current limit. Fixes libp2p#3427
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.
Problem
Publishing a message larger than 4 MiB via
pubsub.publish()fails with an opaque error thrown deep inside the length-prefixed encoder:The
it-length-prefixedencoder has a hardcoded 4 MiB default (MAX_DATA_LENGTH). The gossipsub outbound path never passed options to override it — unlike the inbound path which already exposesmaxInboundDataLength. There was no way to raise the limit.Closes #3427
Changes
src/index.tsAdd
maxOutboundDataLength?: numbertoGossipsubOpts, mirroring the existingmaxInboundDataLengthoption.src/stream.tsAdd
maxDataLength?toOutboundStreamOpts, store it on theOutboundStreaminstance, and pass it toencode.single()so the encoder uses the configured value instead of the library default.src/gossipsub.tsThree changes:
createOutboundStream()— passmaxDataLength: this.opts.maxOutboundDataLengthwhen constructingOutboundStreamsendRpcInBatch()— pass{ maxDataLength: this.opts.maxOutboundDataLength }to its ownencode.single()call (previously uncovered)publish()— add an early guard that fires before any protobuf encoding or network I/O, throwing with a clear, actionable message:test/message-size.spec.ts(new)Four test cases:
maxOutboundDataLength: 8 MiBallows a 6 MiB message throughUser fix
Test plan