<p>Appending blocks to the longest blockchain fork.</p>

<pre><code>         _ _ _ _ _ _ _this is the best chain
 _ _ _ _/
        \_ _ this is NOT
</code></pre>

CC BY-SA 3.0
2015-11-26T16:34:24.437Z
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?
DoaJC_Blogger
CC BY-SA 3.0
2015-11-26T16:55:19.883Z
This is technically correct but very brief and confusing :)
Pieter Wuille
CC BY-SA 3.0
2015-11-26T14:58:32.190Z
2015-11-26T14:58:32.190Z
Farghaly
<p>Bitcoin Core maintains two databases:</p>

<ul>
<li>The block index</li>
<li>The chain state (or UTXO set)</li>
</ul>

<p>The <strong>first</strong> 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 <em>not</em> contain any information about which blocks we consider part of the "best chain".</p>

<p>The <strong>second</strong> 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.</p>

<p>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 <em>activate</em> the best chain, loading blocks from the second database and applying them to the first (while doing full validation on them in the process).</p>

<p>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.</p>

<p>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).</p>

CC BY-SA 3.0
2015-11-26T17:49:28.897Z
Thank you, I think I understand. So it is looking through the local database and selecting the longest chain that was properly written?
DoaJC_Blogger
CC BY-SA 3.0
2015-11-26T17:50:22.567Z
Selecting, processing, verifying, and applying its effects.
Pieter Wuille
CC BY-SA 3.0
2016-03-21T02:54:00.013Z
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.
DoaJC_Blogger
CC BY-SA 3.0
2016-06-02T10:46:50.777Z
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
CC BY-SA 3.0
2016-06-02T11:03:58.347Z
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
CC BY-SA 3.0
2015-11-26T16:49:08.490Z
2015-11-26T18:02:11.797Z
2015-11-26T18:02:11.797Z
Pieter Wuille
<p>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.</p>

<bitcoin-core><synchronization><terminology><best-chain>
What does "Activating Best Chain" mean?
DoaJC_Blogger
# What does "Activating Best Chain" mean?

(Asked by: username_0 on 2015-11-26)

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.

**Tags:** bitcoin-core, synchronization, terminology, best-chain


---

## 2 answers

### Answer by username_2 on 2015-11-26. Score: 10 | Accepted answer

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).

> **Comments:**
> **username_0**: Thank you, I think I understand. So it is looking through the local database and selecting the longest chain that was properly written?  
> **username_2**: Selecting, processing, verifying, and applying its effects.  
> **username_0**: 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.  
> **username_3**: 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, @username_2: do you think this is a bug?  
> **username_2**: 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.  

---

### Answer by username_1 on 2015-11-26. Score: 3

Appending blocks to the longest blockchain fork.

```
         _ _ _ _ _ _ _this is the best chain
 _ _ _ _/
        \_ _ this is NOT

```

> **Comments:**
> **username_0**: 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?  
> **username_2**: This is technically correct but very brief and confusing :)  

---

