0

Ava Chow said it does not exist (link). 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:

enter image description here

Bitcoin for developers also mentions hash_count field:

enter image description here

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

Cosmos
  • 199
  • 7

1 Answers1

3

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.

Pieter Wuille
  • 105,497
  • 9
  • 194
  • 308