Bitcoind block chain structure Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Bitcoind block chain structure without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I am trying to understand the structure of the underlying block chain stored in the core implementation (or rather just the BLK files used by a fullnode). My question is ; does the block chain store the complete tree structure , i.e all the forks which were encountered? Or does it purge the entries once a fork is resolved.

If i were to read the blk files sequentially , can i assume that every single block read is correctly ordered and no forks are present?

Thanks!

Answer

the BLK files are not an API. You shouldn’t directly read those files. What you should do is requesting the headers/block via the JSON RPC interface (or the REST interface).

You can get the genesis block hash via:

bitcoin-cli getblockhash 0

Then you can get a block (without transactions):

bitcoin-cli getblock <hash>

Then get the next block by looking at the nextblockhash item in the block JSON response, etc.

Also, consider using the REST interface. There you can get binary responses which are much faster (no JSON encoding/decoding overhead).

We are here to answer your question about Bitcoind block chain structure - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji