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