Bitcoin full database is not equal on each node

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?

D L

Posted 2017-08-23T07:25:55.837

Reputation: 478

Answers

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.

Pieter Wuille

Posted 2017-08-23T07:25:55.837

Reputation: 54 032

so why database that Bitcoin Core download a year ago (until now) is the same with database that downloaded a week ago?D L 2017-08-28T05:20:25.423

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 2017-08-28T05:30:49.253

but I have those two databases (files from blk00000.dat to blk00974.dat). And they are identicalD L 2017-08-28T05:45:18.803

The files created while syncing the historical chain will be. The files creates while just running normally won't necessarily be.Pieter Wuille 2017-08-28T05:47:06.417

So the question is about files in blocks dir. They are the equal?D L 2017-08-28T06:37:36.347

As I answered many times now: no, they are not necessarily identical. I'm afraid there is a language barrier that prevents me from explaining this.Pieter Wuille 2017-08-28T07:11:03.003

You say The files created while syncing the historical chain will be. So I tell about this files.D L 2017-08-28T07:15:32.553

I don't know what more to say.Pieter Wuille 2017-09-01T22:58:05.023

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.

Ivano Donadi

Posted 2017-08-23T07:25:55.837

Reputation: 219

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 2017-08-23T07:40:17.803

those files are the block database, which, as I stated in my answer, is shared and equal in all nodesIvano Donadi 2017-08-23T08:01:41.377

2This 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 2017-08-23T16:23:09.790

Sorry, I had read somewhere that stale blocks were deleted after a while, so I thought that the files returned to be the sameIvano Donadi 2017-08-24T05:23:34.837

When running with pruning, old stale blocks are indeed deleted (but so are non-stale ones).Pieter Wuille 2017-08-27T21:02:39.913