I have to compose a "getblocks" command found in https://en.bitcoin.it/wiki/Protocol_specification#getblocks

The "getblocks" command contains the "block locator hashes". In essence, I inform a remote node of block hashes that I'm aware of already. There is a rule of how to construct the block locator. Except I’ve no idea of what “pushing”, “going back” or “newest back” means. I cannot figure out the order of block hashes in what I call a locatorArray.

Let’s assume I want to advertise three block hashes:

  • Block hash of block number zero.
  • Block hash of block number one.
  • Block hash of block number two.

Let’s assume I have an array of three elements. For example, I might walk through the array in a for loop as follows:

for ( int i = 0; i < locatorArrayLength; i++ )


The block hash of which block number should be in locatorArray[0]?
The block hash of which block number should be in locatorArray[2]?

  • Where did this data come from, the daemon, an API? Some context would be helpful.
    – morsecoder
    Oct 31 '14 at 17:07
  • I don't understand what data you want in locatorArray.
    – Nick ODell
    Oct 31 '14 at 17:12
  • I've made the statement of my problem more lucid.
    – u2843
    Oct 31 '14 at 17:43
  • @u2843 Did you read the snippet of code provided alongside the documentation?
    – Nick ODell
    Oct 31 '14 at 17:54
  • @Nick ODell I didn't read it. I looked at it. I don't know the language it's written in. I've no idea of what's going on in there. I don't need to know the mechanics of the code. All I care about is whether, using my example, the block number zero is in locatorArray[0] and block number two is in locatorArray[2], or block number two is in locatorArray[0] and block number zero is in locatorArray[2].
    – u2843
    Oct 31 '14 at 18:13

The code on that wiki page is how Bitcoin Core constructs block locators, and it's a good method, but the method isn't enforced by the protocol. All you need to do is list a bunch of block hashes that you know about, ordered by descending block height. So in your example your locator could be (2,1,0), (2,1), (1), etc., but not (1, 2).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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