Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: Frodek on May 06, 2016, 06:43:33 PM



Title: What is binary format blk00NNN.dat files
Post by: Frodek on May 06, 2016, 06:43:33 PM
Blocks are described here : https://en.bitcoin.it/wiki/Block (https://en.bitcoin.it/wiki/Block)
There are chains of blocks , summary size < 128 MiB?


Title: Re: What is binary format blk00NNN.dat files
Post by: achow101 on May 06, 2016, 06:58:59 PM
The blocks are written to the disk exactly in the way that Bitcoin Core receives them. It just writes the actually block messages. What exactly are you asking?


Title: Re: What is binary format blk00NNN.dat files
Post by: Frodek on May 06, 2016, 07:36:31 PM
If I must read  specific block for example 200000, in which file and which position in this file this block begin?
I must read indices, where described is indices format?
In https://en.bitcoin.it/wiki/Block (https://en.bitcoin.it/wiki/Block) I can't see block heights
I can't see block hash, only previous hash.
In blockchain are also blocks from alternative branch?


Title: Re: What is binary format blk00NNN.dat files
Post by: achow101 on May 06, 2016, 07:56:41 PM
If I must read  specific block for example 200000, in which file and which position in this file this block begin?
I must read indices, where described is indices format?
In https://en.bitcoin.it/wiki/Block (https://en.bitcoin.it/wiki/Block) I can't see block heights
I can't see block hash, only previous hash.
In blockchain are also blocks from alternative branch?

The indices for the blocks are in a separate LevelDB database. The blk*.dat files are simply where the blocks are stored, but it means nothing to the software without the database which indexes the blocks. Those indices are kept in the index folder inside of the blocks folder. Bitcoin Core will write to the disk every valid block it receives, so this does include forks and stale blocks in case of blockchain reorgs.


Title: Re: What is binary format blk00NNN.dat files
Post by: Frodek on May 06, 2016, 08:12:30 PM
Is where description of indices files? I must maybe use https://github.com/google/leveldb (https://github.com/google/leveldb) to read.


Title: Re: What is binary format blk00NNN.dat files
Post by: achow101 on May 06, 2016, 08:45:33 PM
Is where description of indices files? I must maybe use https://github.com/google/leveldb (https://github.com/google/leveldb) to read.
There is no description of the format of leveldb files that I know of. You will have to write your own client which uses LevelDB in order to read the data from those db files.


Title: Re: What is binary format blk00NNN.dat files
Post by: Frodek on May 07, 2016, 04:15:01 AM
Maybe is possible to avoid reading indices?
I first read headers of all block, next I compute hash (how fields use specifically to compute hash besides nonce?, next I will build chain tree and select the longest chain.


Title: Re: What is binary format blk00NNN.dat files
Post by: achow101 on May 07, 2016, 04:24:51 AM
Maybe is possible to avoid reading indices?
I first read headers of all block, next I compute hash (how fields use specifically to compute hash besides nonce?, next I will build chain tree and select the longest chain.

Sure, you can do it that way too. Each block is the 4 byte magic bytes, then the size of the block, then the block in raw format. The first 80 bytes is the header and that is hashed using sha256d. The output is then represented using little endian. The rest of the block is just the transactions. For full info on the serialized format, see https://bitcoin.org/en/developer-reference#serialized-blocks


Title: Re: What is binary format blk00NNN.dat files
Post by: Frodek on May 07, 2016, 05:04:22 AM
I can not understand how to obtain multiple leading zeros in hash, while nonce is only 32-bit value
Miners manipulates hash of Merkle tree?


Title: Re: What is binary format blk00NNN.dat files
Post by: shorena on May 07, 2016, 06:46:37 AM
I can not understand how to obtain multiple leading zeros in hash, while nonce is only 32-bit value
Miners manipulates hash of Merkle tree?

Yes, the merkle tree is indirectly "manipulated" by adding or removing transactions. The timestamp and the coinbase input can also be modified.