7

What does "Activating Best Chain" mean? My Bitcoin Core doesn't freeze, it just takes a while. I'm curious as to what it's doing.

10

Bitcoin Core maintains two databases:

  • The block index
  • The chain state (or UTXO set)

The first one just contains a list of all blocks we know about, valid and invalid. It contains all forks we have ever heard about, and all branches that result from it. It also contains information about where on disk these are stored. It does however not contain any information about which blocks we consider part of the "best chain".

The second one contains a snapshot of all existing unspent transaction outputs up to one particular block (and it also stores the hash of this block it is "synchronized" to). The process of validating blocks consists of "applying" the effects of blocks to this state, and possibly undoing those effects when the block turns out to be invalid, or we need to reorganize to another branch.

At startup, it is possible that the first database contains blocks that could be valid but aren't part of the snapshot the second database represents. This can happen when you manually overwrite the block index (restoring from a backup, for example), but more commonly: because Bitcoin crashed after downloading some blocks that ended up being written to the block index, but the resulting chain state was never dumped to disk. When this happens, we will activate the best chain, loading blocks from the second database and applying them to the first (while doing full validation on them in the process).

Since Bitcoin Core heavily caches the chain state in memory, it is possible that there are hundreds or thousands of blocks missing from the chain state after an unclean shutdown. It can take a while to validate them again.

TL;DR: It's verifying blocks that were downloaded already but not processed yet (because the result of processing wasn't properly written to disk, most likely).

  • Thank you, I think I understand. So it is looking through the local database and selecting the longest chain that was properly written? – H. C. Barton Nov 26 '15 at 17:49
  • Selecting, processing, verifying, and applying its effects. – Pieter Wuille Nov 26 '15 at 17:50
  • 1
    This sounds like a good answer. However, I have noticed that it doesn't always take a bad shutdown to make it say "Activating Best Chain", sometimes terminating it cleanly before it fully synchronizes can make it say that when it comes back on. Also, most bad shutdowns, at least for me, kill everything and make it start back at 2009. – H. C. Barton Mar 21 '16 at 2:54
  • I've noticed the same as H.C.Barton, that is, I've got the "Activating Best Chain" message after a clean shut down. In this case, @PieterWuille: do you think this is a bug? – knocte Jun 2 '16 at 10:46
  • No it is not. It can mean that you downloaded some blocks, but you shut down Bitcoin Core before they were fully processed. In 0.13, the "Activating best chain" step will run in the background while the rest of the application is running already. – Pieter Wuille Jun 2 '16 at 11:03
3

Appending blocks to the longest blockchain fork.

         _ _ _ _ _ _ _this is the best chain
 _ _ _ _/
        \_ _ this is NOT
  • 1
    So it's going online and finding a blockchain fork to start downloading?Or is it finding the longest chain on the hard drive? If so, why would there be more than one chain in your local blockchain? – H. C. Barton Nov 26 '15 at 16:34
  • This is technically correct but very brief and confusing :) – Pieter Wuille Nov 26 '15 at 16:55

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.