Is it true that a full bitcoin database is not equal on each node?
I mean database (files) in
blocks dir, which create official bitcoin client locally.
What is that bitcoin database?
Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It only takes a minute to sign up.Sign up to join this community
No, they are not identical. There are various reasons for this:
Different nodes may see blocks in a different order. Whenever a fork occurs, by definition some nodes on the network will have seen one block first, and others saw the other first. If they all saw the same blocks first, there wouldn't be any fork. As Bitcoin Core stores blocks in append-only block files, the order on disk reflects the order in which those blocks were seen in the network. Branches in forks that are reorganized out are kept on disk.
Different nodes may not even see all blocks another block sees. If there is a fork between block A and B, and A eventually is built upon further, the nodes that saw A first, and are not connected to any peers that saw B first, will likely never see B at all. This is true in particular for newly synchronized nodes, which typically don't hear about historical forks, and only downloaded the branch that won.
Different versions of Bitcoin Core manage the block files differently. Earlier versions would leave partially written blocks in the files when a crash occurred while writing a new block. Newer versions will reuse that space.
However, despite all this, the active branch of the blockchain (which is the most-work chain that is valid according to the consensus rules) will converge over time across different nodes. This does not happen instantly (as forks may need resolving, which can take minutes or even hours), and does not imply that the files on disk are identical for the reasons above.
All nodes pertaining to the same chain will have the same blocks database. That's the principle at the base of the blockchain being distributed.
Two nodes' databases may differ in the last block saved if a stale block is created.
One may have a different block in top of the chain until it realizes that the network has chosen another block. At that point the node will sync and its database will be the same as every other full node.
Sorry, my bad, I had read somewhere that all the stale blocks created were deleted after a while, so I tought that everyone had the smae *blk files apart from the last ones. Maybe that site was oversimplifying it.
Thanks for correcting me and letting me understand it correctly.