1

What is the work done by the bitcoin core client during the initialization process? Is the block index created locally or downloaded at other partner nodes?

1

The raw block data is downloaded, and nothing else. All block and transaction indexes are created locally. In the process, block hashes are checked and transactions are verified (to various degrees) as to whether they spend valid inputs, are properly signed, and so on.

Each block is checked and added to the index immediately after being downloaded. The software doesn't wait to download all the blocks before starting to index them.

The files in blocks/index contain information to help locate blocks. For instance, it would contain an entry for each block with its hash, other relevant header data, the number of the blk*.dat file where it is stored, and the position within that file. If txindex is enabled, these files also contain one entry per transaction, pointing to the location of the block which contains the transaction, and the position of the transaction within that block.

The index of unspent transaction outputs is found in the chainstate directory.

The best resource to learn about these indexes is to read the Bitcoin Core source code. There is an older writeup at https://en.bitcoin.it/wiki/Bitcoin_Core_0.11_(ch_2):_Data_Storage, but as of 0.15.0 at least the chainstate index has changed significantly (thanks Pieter Wuille). It is also explained at What are the keys used in the blockchain levelDB (ie what are the key:value pairs)?.

  • Do you mean that all blocks are downloaded from a peer or some peers first, and then the local process produces indexes based on the heads of the downloaded blocks? In addition, I want to know whether those .ldb files cached in the directory "/block/index" are transaction indexes or the index information about the location to download the blocks. Which one is the right answer? – Trl Sep 24 '17 at 2:08
  • @Trl: See edit. – Nate Eldredge Sep 24 '17 at 2:18
  • Thank you for recommending this information. Thank you very much! – Trl Sep 24 '17 at 2:43
  • The format of the chainstate database was overhauled in Bitcoin Core 0.15. – Pieter Wuille Sep 25 '17 at 8:53

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.