Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: bigphoenixman on November 20, 2017, 11:22:52 AM



Title: why every blk00000.dat is different in every wallet?
Post by: bigphoenixman on November 20, 2017, 11:22:52 AM
I am a new one studying bitcoin source. I think that maybe writing a blockchain parser is first step. I realize that every blk00000.dat is different.  I got 2 different blk00000.dat.  I compared the files as below.
http://chuantu.biz/t6/152/1511169018x-1566660940.png
You can see the Magic Number, Size, Version, and the PreHash are different.
I had read https://github.com/bitcoin/bitcoin/issues/6613 (https://github.com/bitcoin/bitcoin/issues/6613), but I am still confused.
If there is a key to XOR to make difference, why the blocks before do not XOR? And obviously, Magic Number, Size, Version do not XOR, which field will be XOR?

Thanks a lot!!!!
 



Title: Re: why every blk00000.dat is different in every wallet?
Post by: achow101 on November 20, 2017, 03:15:05 PM
Bitcoin Core downloads and stores in blocks in the order that they are received, not the order that they are in the blockchain. Bitcoin Core downloads multiple blocks simultaneously, so it is likely that blocks will be received and written to disk in a different order from the actual blockchain and in a different order from node to node.


Title: Re: why every blk00000.dat is different in every wallet?
Post by: aestrum on November 20, 2017, 06:37:27 PM
Content is XORed with random key, so that antivirus software does not trigger.


Title: Re: why every blk00000.dat is different in every wallet?
Post by: achow101 on November 20, 2017, 06:42:17 PM
Content is XORed with random key, so that antivirus software does not trigger.
The block files themselves are not XORed with the random key; the databases are.


Title: Re: why every blk00000.dat is different in every wallet?
Post by: aestrum on November 20, 2017, 06:49:30 PM
Yes, right, I confused it with chainstate db, which is XORed.


Title: Re: why every blk00000.dat is different in every wallet?
Post by: jnano on November 20, 2017, 07:15:44 PM
Wouldn't it make sense to normalize the block storage format?
That would make it practical to do various operations between computers, like fill missing data or compare/verify.

Why XOR the chainstate data or (index?) database files?


Title: Re: why every blk00000.dat is different in every wallet?
Post by: achow101 on November 20, 2017, 07:58:00 PM
Wouldn't it make sense to normalize the block storage format?
That would make it practical to do various operations between computers, like fill missing data or compare/verify.

The block storage and file formats are normalized. What you can't do is ensure that every single node has exactly the same data in exactly the same order. This is because during normal operation, orphan blocks will cause nodes to receive different blocks in different orders. Some nodes might see a block which another node does not see at all. Or they might see two different blocks and write them in the same position. Because of orphans, it is not possible to make all nodes have exactly the same data in exactly the same order.

During initial sync, having to write the blocks to disk in blockchain order rather than order received will result in a slower sync.

Why XOR the chainstate data or (index?) database files?
To prevent antivitus software from messing with the database files because sometimes they contain virus signatures because virus signatures are embedded into the blockchain. Having the database files corrupted will require the entire database to be rebuilt which will take a long time.


Title: Re: why every blk00000.dat is different in every wallet?
Post by: jnano on November 20, 2017, 08:18:34 PM
Well, maybe it could have an optional flag to do store blocks in final blockchain order, or to trigger a one-time normalization pass on existing data.
And if orphan blocks are needed, keep them separate from the main chain.

I thought the AV-triggering data would be in the block files. Or what did you mean by databases?
Is the chainstate data XORed as well? I thought that's just the global UTXO balance, with no arbitrary data.


Title: Re: why every blk00000.dat is different in every wallet?
Post by: bigphoenixman on November 21, 2017, 12:29:10 AM
Bitcoin Core downloads and stores in blocks in the order that they are received, not the order that they are in the blockchain. Bitcoin Core downloads multiple blocks simultaneously, so it is likely that blocks will be received and written to disk in a different order from the actual blockchain and in a different order from node to node.

Thank you :)