<blockquote>
<p>Does the <code>vHave</code> contains a list of contiguous block hashes previous to <code>A</code> and <code>A</code> itself?</p>
</blockquote>
<p>Pretty much.</p>
<p><code>CBlockLocators</code> 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 <code>A</code>, so the list contains hashes farther and farther apart as the blocks get older.</p>
<p>It starts with <code>A</code> 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.</p>
<p>The list ends up having <code>ceil(log2(n)) + 11</code> hashes. Currently that's 31 block hashes.</p>

CC BY-SA 4.0
2022-12-13T00:33:06.443Z
Excellent approach Andrew.
Pegasus
CC BY-SA 4.0
2022-12-13T13:07:21.403Z
Thanks for your answer, just a question, the `n` in the  `ceil(log2(n)) + 11` is the height of the block `A`?
Amir reza Riahi
CC BY-SA 4.0
2022-12-13T18:03:49.743Z
Yes. `n` is the number of blocks in the chain.
Ava Chow
CC BY-SA 4.0
2022-12-12T23:06:35.840Z
2022-12-12T23:19:59.400Z
2022-12-12T23:19:59.400Z
Ava Chow
<p>The <a href="https://github.com/bitcoin/bitcoin/blob/6b24dfe24d2ed50ea0b06ce1919db3dc0e871a03/src/primitives/block.h#L120" rel="nofollow noreferrer">CBlockLocator</a> strucuture's purpose is:</p>
<blockquote>
<p>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.</p>
</blockquote>
<pre><code>/** 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&lt;uint256&gt; vHave;
</code></pre>
<p>But it's not clear to me how does it works. How does the sender specify the Block with <code>A</code> in this structure? Does the <code>vHave</code> contains a list of contiguous block hashes previous to <code>A</code> and <code>A</code> itself?</p>

<bitcoin-core><bitcoin-core-development>
How does CBlockLocator class works?
Amir reza Riahi
# How does CBlockLocator class works?

(Asked by: username_0 on 2022-12-12)

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 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?

**Tags:** bitcoin-core, bitcoin-core-development


---

## 1 answers

### Answer by username_1 on 2022-12-12. Score: 4 | Accepted answer

> 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.

> **Comments:**
> **username_2**: Excellent approach Andrew.  
> **username_0**: Thanks for your answer, just a question, the `n` in the  `ceil(log2(n)) + 11` is the height of the block `A`?  
> **username_1**: Yes. `n` is the number of blocks in the chain.  

---

