user63817: In Bitcoin Core, MAX_SIZE defines the maximum valid P2P message payload size to be 32MB. Is it realistic that a peer sends a message payload close to 32MB? What is the maximum, but still realistic message payload size?

user208: Since Bitcoin Core pull request 5843, incoming messages larger than MAX_PROTOCOL_MESSAGE_LENGTH are rejected. This constant was initially set to 2 MiB, but later (as part of the segwit changes) increased to 4 MB.
Its purpose is memory DoS protection. An attacker that manages to open many connections to a victim node could otherwise e.g. start sending messages of 32 MiB (MAX_SIZE for all serialized objects), but never send the last byte. Those just-below-32MiB messages would need to be kept in memory before until the last byte arrives, before processing them. Limiting the maximum valid message size significantly reduces the impact of such an attack.

63817: <p>In Bitcoin Core, <a href="https://github.com/bitcoin/bitcoin/blob/7c72eabb57bde83abfc4bd5af70b884390ef847d/src/serialize.h#L31" rel="noreferrer"><code>MAX_SIZE</code></a> defines the maximum valid P2P message payload size to be 32MB. Is it realistic that a peer sends a message payload close to 32MB? What is the maximum, but still realistic message payload size?</p>
 208: <p>Since Bitcoin Core <a href="https://github.com/bitcoin/bitcoin/pull/5843" rel="noreferrer">pull request 5843</a>, incoming messages larger than MAX_PROTOCOL_MESSAGE_LENGTH are rejected. This constant was initially set to 2 MiB, but later (as part of the segwit changes) increased to 4 MB.</p>
<p>Its purpose is memory DoS protection. An attacker that manages to open many connections to a victim node could otherwise e.g. start sending messages of 32 MiB (MAX_SIZE for all serialized objects), but never send the last byte. Those just-below-32MiB messages would need to be kept in memory before until the last byte arrives, before processing them. Limiting the maximum valid message size significantly reduces the impact of such an attack.</p>
