Why does bitcoin sync inventories?

3

I read the bitcoin docs describing how btc syncs. During IBD it gets the inventories up to the tip with getblock. Why does it not skip this step and get the blocks, generating the inventories as it gets each block? Surely getting inventories is slow, unneeded and inefficient? I believe bitcoin daemon over version 0.10.0 now sync headers rather than inventories, i am talking about pre 0.10.0.

Leo Cornelius

Posted 2020-03-08T18:19:49.610

Reputation: 332

Your question contains too many misconceptions for me to answer... what do you mean by "skipping this step"? Syncing inventories exactly how the nodes learns about and downloads the blocks. I don't know what is slow, unneeded, or inefficient about it. – Pieter Wuille – 2020-03-08T23:56:25.710

@Wuille why would I need to download inventory’s to learn about the blocks? What does a number and a hash tell me that I can’t get from syncing the block data it’s self. Perhaps I have misunderstood the docs? – Leo Cornelius – 2020-03-09T05:49:27.237

The inventory is how you learn the block exists at all. It's how you figure out "oh this peer knows a block I don't have yet, let me ask for it". – Pieter Wuille – 2020-03-09T05:59:00.200

@pieter wuille ah I see. I was under the perception your node already knew this. Thanks :) this has answered the question. Feel free to put it into a response and I will mark it as correct! – Leo Cornelius – Leo Cornelius – 2020-03-09T06:58:15.847

Bitcoin 0.1 didn’t even have inventory messages. You mean 0.10. – Anonymous – 2020-03-09T09:04:44.223

Answers

1

Pre 0.10 versions synced inventories as it was the way they composed a list of blocks that they then recursively request from the peer. It provides multiple benefits over just asking for all blocks since timestamp x (where is the timestamp of the last block we had).

The biggest one being that it allows you to check the peer is on the same chain as the checkpoint you are using, this means you can check the peer is on the correct chain (eg the one your checkpoints state is correct) before downloading blocks, which are considerably larger than just hashes.

Leo Cornelius

Posted 2020-03-08T18:19:49.610

Reputation: 26