What is the order of block hashes in block-locator array?

0

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

u2843

Posted 2014-10-31T16:25:37.200

Reputation: 95

Where did this data come from, the daemon, an API? Some context would be helpful.morsecoder 2014-10-31T17:07:22.683

I don't understand what data you want in locatorArray.Nick ODell 2014-10-31T17:12:46.893

I've made the statement of my problem more lucid.u2843 2014-10-31T17:43:51.723

@u2843 Did you read the snippet of code provided alongside the documentation?Nick ODell 2014-10-31T17:54:30.947

@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 2014-10-31T18:13:41.603

Answers

1

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

theymos

Posted 2014-10-31T16:25:37.200

Reputation: 8 228