<p><code>getheaders</code> only checks that <code>hash_stop</code> is part of the main chain if <code>locator</code> is empty. If it is, then it returns just that particular block header.</p>
<p><code>getblocks</code> does not do any validation on <code>hash_stop</code>.</p>
<p>Both <code>getheaders</code> and <code>getblocks</code> will compare the block hashes exactly, so it only stops when it either reaches the limit, or sees a block hash that exactly matches <code>hash_stop</code>. If the <code>hash_stop</code> is not in the main chain after <code>locator</code>, then the maximum number of items will be returned.</p>

CC BY-SA 4.0
2023-12-21T02:15:59.450Z
From your first paragraph, it looks like `getheaders`, by setting `hash_count` to 0 and then providing hash (which represents `hash_stop`) is a way to obtain just one concrete header of some block? Before we could only get the whole block.
Cosmos
CC BY-SA 4.0
2023-12-21T04:01:47.930Z
Yes, if you provided just `hash_stop` then you would get just that header. There is no `hash_count`.
Ava Chow
CC BY-SA 4.0
2023-12-21T09:10:40.510Z
`getheaders`/`getblocks` messages, according to bitcoin wiki, includes `hash_count` (https://en.bitcoin.it/wiki/Protocol_documentation#getheaders). Bitcoin for developers also mentions `hash_count` (https://developer.bitcoin.org/reference/p2p_networking.html#getblocks)
Cosmos
CC BY-SA 4.0
2023-12-21T13:59:00.290Z
Ah, within the code, there is no separate `hash_count`. It's just part of the serialization for a block locator object.
Ava Chow
CC BY-SA 4.0
2023-12-21T15:23:08.167Z
Thanks. For future readers: https://bitcoin.stackexchange.com/a/121090/146389
Cosmos
CC BY-SA 4.0
2023-12-21T01:51:26.440Z
2023-12-21T01:51:26.440Z
Ava Chow
<p>What happens when <code>hash_stop</code> contains a hash that the node that receives the <code>getblocks</code>/<code>getheaders</code> message doesn't have, or does, but that hash (that is, the block whose hash it is) is somewhere earlier in the chain (behind the hash in block locator)? Is the maximum number of elements (childs) then returned, which is 500 for <code>getblocks</code> and 2000 for <code>getheaders</code>?</p>

<p2p>
What happens when hash_stop in getblocks/getheaders messages has a wrong/nonexistent hash?
Cosmos
# What happens when hash_stop in getblocks/getheaders messages has a wrong/nonexistent hash?

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

What happens when `hash_stop` contains a hash that the node that receives the `getblocks`/`getheaders` message doesn't have, or does, but that hash (that is, the block whose hash it is) is somewhere earlier in the chain (behind the hash in block locator)? Is the maximum number of elements (childs) then returned, which is 500 for `getblocks` and 2000 for `getheaders`?

**Tags:** p2p


---

## 1 answers

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

`getheaders` only checks that `hash_stop` is part of the main chain if `locator` is empty. If it is, then it returns just that particular block header.

`getblocks` does not do any validation on `hash_stop`.

Both `getheaders` and `getblocks` will compare the block hashes exactly, so it only stops when it either reaches the limit, or sees a block hash that exactly matches `hash_stop`. If the `hash_stop` is not in the main chain after `locator`, then the maximum number of items will be returned.

> **Comments:**
> **username_0**: From your first paragraph, it looks like `getheaders`, by setting `hash_count` to 0 and then providing hash (which represents `hash_stop`) is a way to obtain just one concrete header of some block? Before we could only get the whole block.  
> **username_1**: Yes, if you provided just `hash_stop` then you would get just that header. There is no `hash_count`.  
> **username_0**: `getheaders`/`getblocks` messages, according to bitcoin wiki, includes `hash_count` (https://en.bitcoin.it/wiki/Protocol_documentation#getheaders). Bitcoin for developers also mentions `hash_count` (https://developer.bitcoin.org/reference/p2p_networking.html#getblocks)  
> **username_1**: Ah, within the code, there is no separate `hash_count`. It's just part of the serialization for a block locator object.  
> **username_0**: Thanks. For future readers: https://bitcoin.stackexchange.com/a/121090/146389  

---

