<p><code>CSizeComputer</code> 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.</p>

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

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

CC BY-SA 3.0
2017-06-09T23:31:59.053Z
2017-06-09T23:31:59.053Z
Pieter Wuille
<p>I was able to follow the code to <a href="https://github.com/bitcoin/bitcoin/blob/master/src/validation.cpp#L2681" rel="nofollow noreferrer">validation.cpp</a>:</p>

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

<p>and <a href="https://github.com/bitcoin/bitcoin/blob/master/src/serialize.h#L954" rel="nofollow noreferrer">serialize.h</a>:</p>

<pre><code>template &lt;typename T&gt;
size_t GetSerializeSize(const T&amp; t, int nType, int nVersion = 0)
{
    return (CSizeComputer(nType, nVersion) &lt;&lt; t).size();
}
</code></pre>

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

CC BY-SA 3.0
2017-06-09T23:18:53.003Z
possible duplicate of https://bitcoin.stackexchange.com/questions/41196/how-is-the-size-of-a-block-calculated
Nick ODell
CC BY-SA 3.0
2017-06-09T23:32:29.900Z
I'm not treating it as a duplicate as a question about Bitcoin Core's serialization code is included.
Pieter Wuille
<bitcoin-core-development><consensus><block-header><blocksize>
Does the 1 MB block size limit include the header?
Rich Apodaca
# Does the 1 MB block size limit include the header?

(Asked by: username_0 on 2017-06-09)

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 
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?

**Tags:** bitcoin-core-development, consensus, block-header, blocksize

> **Comments:**
> **username_1**: possible duplicate of https://bitcoin.stackexchange.com/questions/41196/how-is-the-size-of-a-block-calculated  
> **username_2**: I'm not treating it as a duplicate as a question about Bitcoin Core's serialization code is included.  

---

## 1 answers

### Answer by username_2 on 2017-06-09. Score: 3 | Accepted answer

`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.


---

