wire: use maxprotocol message len on msg reject#2518
Merged
Roasbeef merged 2 commits intobtcsuite:masterfrom Apr 8, 2026
Merged
Conversation
Revert MaxMessagePayload to 32MB and introduce MaxProtocolMessageLength (~4MB) for p2p network message size enforcement. This mirrors Bitcoin Core's separation between MAX_SIZE (32MB serialization bound) and MAX_PROTOCOL_MESSAGE_LENGTH (~4MB network limit) introduced in bitcoin/bitcoin#5843. The previous commit reduced MaxMessagePayload to 4MB, but that constant is also used as a serialization bound for deriving maxTxInPerMessage, maxTxOutPerMessage, and variable-length string limits in contexts beyond network messages (e.g. database deserialization via MsgTx.Deserialize). While consensus limits keep real values well below the 4MB-derived bounds, conflating the two constants is architecturally incorrect and diverges from Bitcoin Core's design. The new MaxProtocolMessageLength is now enforced in all four network read/write paths: WriteMessageN, WriteMessageWithEncodingN, ReadMessageWithEncodingN, and ReadV2MessageN (which previously had no overall message size check).
As we introduced a new MaxProtocolMessageLength, MsgReject max size should also be lowered to MaxProtocolMessageLength. If this isn't lowered and if we ever have a MsgReject message that is bigger than MaxProtocolMessageLength, then the MaxPayloadLength() check on the message will pass but it won't serialize in functions WriteMessageWithEncodingN() and WriteV2MessageN() as both of these functions have a separate check that each message isn't greater than MaxProtocolMessageLength.
erickcestari
approved these changes
Apr 6, 2026
Contributor
erickcestari
left a comment
There was a problem hiding this comment.
LGTM!
By the way, is it worth keeping the reject message? The Core team removed support for it in 2019 (bitcoin/bitcoin#15437). It looks like it adds a lot of complexity, and other nodes don't listen for it either. So we may remove it later.
Member
It's worth keeping for light clients IMO. As otherwise, you have no idea why your transaction wasn't accepted. Light clients don't have a mempool, and mempool policy is somewhat fast moving lately. |
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.
Change Description
As we introduced a new MaxProtocolMessageLength, MsgReject max size
should also be lowered to MaxProtocolMessageLength.
If this isn't lowered and if we ever have a MsgReject message that is
bigger than MaxProtocolMessageLength, then the MaxPayloadLength() check
on the message will pass but it won't serialize in functions
WriteMessageWithEncodingN() and WriteV2MessageN() as both of these
functions have a separate check that each message isn't greater than
MaxProtocolMessageLength.
I really doubt that we'll ever trigger this but the code is technically incorrect and we should change this.
Follow up to #2504
Steps to Test
cd wire; go test
Pull Request Checklist
Testing
Code Style and Documentation
📝 Please see our Contribution Guidelines for further guidance.