<p>This is a matter of terminology, but all these descriptions are equivalent.</p>
<p>The locator is a vector of hashes. In Bitcoin's serialization framework, vectors are always serialized by first writing the number of objects, and then the serialization of those objects themselves, concatenated. This applies in many places:</p>
<ul>
<li>The block hashes in a locator</li>
<li>The list of inventory objects in <code>inv</code> and <code>getdata</code></li>
<li>The list of addresses in <code>addr</code> and <code>addrv2</code></li>
<li>Transactions in a block</li>
<li>Transaction inputs in a transaction</li>
<li>Transaction outputs in a transaction</li>
<li>Bytes in a script</li>
<li>Number of witness items in a witness stack</li>
<li>...</li>
</ul>
<p>Some descriptions of the protocol treat this count as a separate &quot;field&quot; before the object, while others treat it as part of the object itself. To someone familiar with the Bitcoin Core source code, the latter feels probably more familiar, as there is no actual variable &quot;hash_count&quot; in the implementation; it's just the length of the locator object that goes in and comes out.</p>

CC BY-SA 4.0
2023-12-21T13:01:55.563Z
2023-12-21T14:02:23.213Z
2023-12-21T14:02:23.213Z
Pieter Wuille
<p><em>Ava Chow</em> said it does not exist (<a href="https://bitcoin.stackexchange.com/a/121083/146389">link</a>). If <code>hash_count</code> does not exist, how will the receiving peer know how many locators are in the message?</p>
<p>I am not sure if he maybe thought that <code>hash_count</code> does not exist for <code>hash_stop</code> or it does not even exist for <code>locators</code>.</p>
<p>Bitcoin wiki says it exists for both <code>getheaders</code> and <code>getblocks</code>:</p>
<ul>
<li><a href="https://en.bitcoin.it/wiki/Protocol_documentation#getheaders" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/Protocol_documentation#getheaders</a></li>
<li><a href="https://en.bitcoin.it/wiki/Protocol_documentation#getblocks" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/Protocol_documentation#getblocks</a></li>
</ul>
<p><a href="https://i.sstatic.net/J3pFt.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/J3pFt.png" alt="enter image description here" /></a></p>
<p>Bitcoin for developers also mentions <code>hash_count</code> field:</p>
<ul>
<li><a href="https://developer.bitcoin.org/reference/p2p_networking.html#getblocks" rel="nofollow noreferrer">https://developer.bitcoin.org/reference/p2p_networking.html#getblocks</a></li>
</ul>
<p><a href="https://i.sstatic.net/D5OhN.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/D5OhN.png" alt="enter image description here" /></a></p>
<p>If <code>hash_count</code> is no longer used, when did that change in bitcoin core happen and how was compatibility with old nodes maintained?</p>

<p2p>
Does hash_count field exists in getheaders/getblocks messages?
Cosmos
# Does hash_count field exists in getheaders/getblocks messages?

(Asked by: username_0 on 2023-12-21)

*Ava Chow* said it does not exist ([link](https://bitcoin.stackexchange.com/a/121083/146389)). If `hash_count` does not exist, how will the receiving peer know how many locators are in the message?

I am not sure if he maybe thought that `hash_count` does not exist for `hash_stop` or it does not even exist for `locators`.

Bitcoin wiki says it exists for both `getheaders` and `getblocks`:

* <https://en.bitcoin.it/wiki/Protocol_documentation#getheaders>
* <https://en.bitcoin.it/wiki/Protocol_documentation#getblocks>

[![enter image description here](https://i.sstatic.net/J3pFt.png)](https://i.sstatic.net/J3pFt.png)

Bitcoin for developers also mentions `hash_count` field:

* <https://developer.bitcoin.org/reference/p2p_networking.html#getblocks>

[![enter image description here](https://i.sstatic.net/D5OhN.png)](https://i.sstatic.net/D5OhN.png)

If `hash_count` is no longer used, when did that change in bitcoin core happen and how was compatibility with old nodes maintained?

**Tags:** p2p


---

## 1 answers

### Answer by username_1 on 2023-12-21. Score: 3 | Accepted answer

This is a matter of terminology, but all these descriptions are equivalent.

The locator is a vector of hashes. In Bitcoin's serialization framework, vectors are always serialized by first writing the number of objects, and then the serialization of those objects themselves, concatenated. This applies in many places:

* The block hashes in a locator
* The list of inventory objects in `inv` and `getdata`
* The list of addresses in `addr` and `addrv2`
* Transactions in a block
* Transaction inputs in a transaction
* Transaction outputs in a transaction
* Bytes in a script
* Number of witness items in a witness stack
* ...

Some descriptions of the protocol treat this count as a separate "field" before the object, while others treat it as part of the object itself. To someone familiar with the Bitcoin Core source code, the latter feels probably more familiar, as there is no actual variable "hash\_count" in the implementation; it's just the length of the locator object that goes in and comes out.


---

