0

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?

Cosmos
  • 199
  • 7

1 Answers1

1

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.

Ava Chow
  • 70,382
  • 5
  • 81
  • 161
  • 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 Dec 21 '23 at 02:15
  • Yes, if you provided just hash_stop then you would get just that header. There is no hash_count. – Ava Chow Dec 21 '23 at 04:01
  • 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 Dec 21 '23 at 09:10
  • Ah, within the code, there is no separate hash_count. It's just part of the serialization for a block locator object. – Ava Chow Dec 21 '23 at 13:59
  • Thanks. For future readers: https://bitcoin.stackexchange.com/a/121090/146389 – Cosmos Dec 21 '23 at 15:23