1

The CBlockLocator strucuture's purpose is:

Describes a place in the block chain to another node such that if the other node doesn't have the same branch, it can find a recent common trunk. The further back it is, the further before the fork it may be.

/** Describes a place in the block chain to another node such that if the
 * other node doesn't have the same branch, it can find a recent common trunk.
 * The further back it is, the further before the fork it may be.
 */
struct CBlockLocator
{
    std::vector<uint256> vHave;

But it's not clear to me how does it works. How does the sender specify the Block with A in this structure? Does the vHave contains a list of contiguous block hashes previous to A and A itself?

1 Answer 1

4

Does the vHave contains a list of contiguous block hashes previous to A and A itself?

Pretty much.

CBlockLocators are just a list of block hashes, with most recent blocks first. Of course, it would be expensive to send all of the block hashes that precede A, so the list contains hashes farther and farther apart as the blocks get older.

It starts with A and the 9 blocks that came before it. The vast majority of reorgs will be within these 10 blocks, so it just lists all 10 and there's a pretty high likelihood that the forking point will be in there. But after that, hashes start being spaced out exponentially. It starts with 2 blocks before the last in the list, then 4, then 8, and so on, until the genesis block is reached.

The list ends up having ceil(log2(n)) + 11 hashes. Currently that's 31 block hashes.

3
  • Excellent approach Andrew.
    – Pegasus
    Dec 13, 2022 at 0:33
  • Thanks for your answer, just a question, the n in the ceil(log2(n)) + 11 is the height of the block A? Dec 13, 2022 at 13:07
  • 1
    Yes. n is the number of blocks in the chain.
    – Ava Chow
    Dec 13, 2022 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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