Does the 1 MB block size limit include the header?



I was able to follow the code to validation.cpp:

// Size limits
if (block.vtx.empty() || block.vtx.size() > MAX_BLOCK_BASE_SIZE || ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) > MAX_BLOCK_BASE_SIZE)
    return state.DoS(100, false, REJECT_INVALID, "bad-blk-length", false, "size limits failed");

and serialize.h:

template <typename T>
size_t GetSerializeSize(const T& t, int nType, int nVersion = 0)
    return (CSizeComputer(nType, nVersion) << t).size();

But for the life of me I can't figure out what CSizeComputer is doing. Does GetSerializeSize include the block header in the value it returns?

Rich Apodaca

Posted 2017-06-09T21:33:51.680

Reputation: 2 076

possible duplicate of

– Nick ODell – 2017-06-09T23:18:53.003

2I'm not treating it as a duplicate as a question about Bitcoin Core's serialization code is included. – Pieter Wuille – 2017-06-09T23:32:29.900



CSizeComputer is a serialization stream that discards all data written, and just counts how many bytes were produced. It is inlined, and the compiler in most cases actually avoids computing the bytes.

So, GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) just computes how many bytes would be produced when serializing a block for the network ignoring witnesses.

As blocks on the network indeed are prefixed by their header (and transaction count), those do contribute towards the maximum block size.

Pieter Wuille

Posted 2017-06-09T21:33:51.680

Reputation: 64 874