Bitcoin Core LevelDB Index saves forked blocks

0

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 -reindexing the entire blockchain? Would -reindex even remove them?

Brannon

Posted 2018-02-27T20:03:20.933

Reputation: 125

There’s a negligible impact of that. Less than 1% of blocks are stale.Anonymous 2018-02-28T02:27:00.610

Answers

1

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.

Pieter Wuille

Posted 2018-02-27T20:03:20.933

Reputation: 54 032

0

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.

Willtech

Posted 2018-02-27T20:03:20.933

Reputation: 2 657

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?Brannon 2018-02-27T23:41:11.837