Why block index or block height is not included in the block header?
Do we have to go through the whole chain if we want to know how many blocks are there in a chain?
On the other hand, if some blocks have the same hash, how to find them and get their content individually?

up vote 2 down vote accepted

The chances of two blocks having the same hash are extraordinarily low. Having the same hash would essentially ensure that they must be the same block (two copies of the same block with the same transactions at the same height with the same ancestor).

While the blocks themselves do not contain the height, most full node software keeps track of the height of each block. In Bitcoin Core you can use getblockchaininfo to see how many blocks your node has or, getblockcount to see how many blocks your node knows about.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.