I've noticed that bitcoind
will permanently save unverified blocks that it receives even if they turn out to be small blockchain forks, likely occurring from the relatively simultaneous discovery of two blocks of equal height. This doesn't cause a problem for Bitcoin Core's functionality, as there is surely a process written into the source that ignores such small forks, however, it's curious to me that the data persists in the data saved to the .dat
and .ldb
files in .bitcoin/blocks/
and .bitcoin/blocks/index
nonetheless. Is there a way to prune these invalid blocks that belong to small forks in the blockchain without -reindex
ing the entire blockchain? Would -reindex
even remove them?
-
There’s a negligible impact of that. Less than 1% of blocks are stale.– ClarisFeb 28, 2018 at 2:27
2 Answers
They're kept because it is complicated to remove them (it would require rewriting the block storage files), and there is hardly any cost to keeping them (they're a small fraction of the total). Furthermore, close to the tip we want to have forks available, in order to be able to reorganize quickly if one of them ends up becoming the main chain.
More technically, the $DATADIR/blocks directory for Bitcoin Core is not a representation of the blockchain. It's a store of all valid blocks we've ever downloaded. Which out of them end up being considered the main chain is a different issue, and dealt with independently.
Also note that in pruning mode all old blocks are removed - including these small forks.
I cannot think of any convenient way to do this.
The only method that comes to mind is to create for yourself a bootstrap.dat
file from your own up to date node, then exit Bitcoin Core and manually clear out all the relevant db files before importing from the bootstrap.dat
.
-
Are these small forks called "orphans"? How come they only seem to appear when you've been actually running a node? Is it because node's don't rebroadcast orphaned blocks, but do save them indefinitely?– BrannonFeb 27, 2018 at 23:41