1

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?

2

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.

  • so why database that Bitcoin Core download a year ago (until now) is the same with database that downloaded a week ago? – D L Aug 28 '17 at 5:20
  • It isn't. I've answered that. The best chain they agree on will be identical (with very high probability), but their database will not. – Pieter Wuille Aug 28 '17 at 5:30
  • but I have those two databases (files from blk00000.dat to blk00974.dat). And they are identical – D L Aug 28 '17 at 5:45
  • The files created while syncing the historical chain will be. The files creates while just running normally won't necessarily be. – Pieter Wuille Aug 28 '17 at 5:47
  • So the question is about files in blocks dir. They are the equal? – D L Aug 28 '17 at 6:37
0

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.

Edit

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.

  • I mean files blk*.dat, except the last one (that is not full). Is this files are the same on all, or they differs? – D L Aug 23 '17 at 7:40
  • those files are the block database, which, as I stated in my answer, is shared and equal in all nodes – Ivano Donadi Aug 23 '17 at 8:01
  • 2
    This is incorrect. While the longest chain will frequently be identical across nodes, the blk* files likely will not, as those also contain all forks your node has seen, and in what order. Different nodes see different forks. – Pieter Wuille Aug 23 '17 at 16:23
  • Sorry, I had read somewhere that stale blocks were deleted after a while, so I thought that the files returned to be the same – Ivano Donadi Aug 24 '17 at 5:23
  • When running with pruning, old stale blocks are indeed deleted (but so are non-stale ones). – Pieter Wuille Aug 27 '17 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.