wire: separate protocol message limit from serialization bound#2504
wire: separate protocol message limit from serialization bound#2504erickcestari wants to merge 1 commit intobtcsuite:masterfrom
Conversation
kcalvinalvin
left a comment
There was a problem hiding this comment.
Shouldn't we also replace with MaxMessagePayload here:
Lines 172 to 180 in b950e5b
wire/message.go
Outdated
| if len(plaintext) > MaxProtocolMessageLength { | ||
| return nil, nil, fmt.Errorf("payload exceeds max protocol "+ | ||
| "message length - %d bytes, max %d", len(plaintext), | ||
| MaxProtocolMessageLength) |
There was a problem hiding this comment.
nit: Everywhere else we return messageError() but here we return fmt.Errof(). Might be worth aligning to avoid error type check errors later down the road
There was a problem hiding this comment.
ReadV2MessageN function it's only using fmt.Errorf(), but I'll refactor to return messageError() instead.
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).
9c64dec to
5e96c5b
Compare
Sure, but I thinks is work for a follow-up PR to audit all |
Revert
MaxMessagePayloadto 32MiB and introduceMaxProtocolMessageLength(~4MB) for p2p network message size enforcement. This mirrors Bitcoin Core's separation betweenMAX_SIZE(32MiB serialization bound) andMAX_PROTOCOL_MESSAGE_LENGTH(~4MB network limit) introduced in bitcoin/bitcoin#5843.The previous commit reduced
MaxMessagePayloadto 4MB, but that constant is also used as a serialization bound for derivingmaxTxInPerMessage,maxTxOutPerMessage, and variable-length string limits in contexts beyond network messages (e.g. database deserialization viaMsgTx.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
MaxProtocolMessageLengthis now enforced in all four network read/write paths:WriteMessageN,WriteMessageWithEncodingN,ReadMessageWithEncodingN, andReadV2MessageN(which previously had no overall message size check).closes #2503