<blockquote>
<p>What do the classes <code>ChainstateManager</code>, <code>CChainState</code>, <code>CChain</code> and <code>BlockManager</code> do?</p>
</blockquote>
<p>A graphic from <a href="https://doxygen.bitcoincore.org/class_chainstate_manager.html" rel="nofollow noreferrer">Doxygen</a> showing how the classes interact:</p>
<p><a href="https://i.sstatic.net/6GWr2.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/6GWr2.png" alt="Doxygen graphic" /></a></p>
<p><code>ChainstateManager</code>: Provides an interface for creating and interacting with one or two chainstates</p>
<p><code>CChainState</code>: Stores and provides an API to update our local knowledge of the current best chain.</p>
<p><code>CChain</code>: An in-memory indexed chain of blocks. It was introduced in <a href="https://github.com/bitcoin/bitcoin/pull/3077" rel="nofollow noreferrer">PR 3077</a>.</p>
<p><code>BlockManager</code>: Maintains a tree of blocks (stored in <code>m_block_index</code>) which is consulted to determine where the most-work tip is.</p>
<blockquote>
<p>Why do <code>CChainState</code> and <code>CChain</code> have a leading 'C', but <code>ChainstateManager</code> and <code>BlockManager</code> don't?</p>
</blockquote>
<p>C stands for class using Hungarian style naming.</p>
<p>The current style in Bitcoin Core is not to use Hungarian notation. Bitcoin Core uses <code>m_</code> to represent member variables, <code>g_</code> to represent globals, and no prefix to represent local variables/parameters. <code>CChainState</code> and <code>CChain</code> were named prior to these style guidelines being implemented in Bitcoin Core.</p>
<p>These were answered by John Newbery and other participants of the May 12th 2021 <a href="https://bitcoincore.reviews/21767" rel="nofollow noreferrer">Bitcoin Core PR review club</a>.</p>

CC BY-SA 4.0
2021-05-24T10:33:14.320Z
2021-05-26T11:46:45.490Z
2021-05-26T11:46:45.490Z
Michael Folkson
<p>What do the classes <code>ChainstateManager</code>, <code>CChainState</code>, <code>CChain</code> and <code>BlockManager</code> do in Bitcoin Core?</p>
<p>Why do <code>CChainState</code> and <code>CChain</code> have a leading 'C', but <code>ChainstateManager</code> and <code>BlockManager</code> don't?</p>
<p>These questions were asked during the May 12th 2021 <a href="https://bitcoincore.reviews/21767" rel="nofollow noreferrer">Bitcoin Core PR review club</a> hosted by John Newbery on a Carl Dong PR to de-globalize ChainstateManager.</p>

CC BY-SA 4.0
2021-06-19T08:08:24.740Z
Thanks for documenting the questions from the review club here!
stackaccount
<bitcoin-core-development><validation><c++>
What do the classes ChainstateManager, CChainState, CChain and BlockManager do in Bitcoin Core?
Michael Folkson
# What do the classes ChainstateManager, CChainState, CChain and BlockManager do in Bitcoin Core?

(Asked by: username_0 on 2021-05-24)

What do the classes `ChainstateManager`, `CChainState`, `CChain` and `BlockManager` do in Bitcoin Core?

Why do `CChainState` and `CChain` have a leading 'C', but `ChainstateManager` and `BlockManager` don't?

These questions were asked during the May 12th 2021 [Bitcoin Core PR review club](https://bitcoincore.reviews/21767) hosted by John Newbery on a Carl Dong PR to de-globalize ChainstateManager.

**Tags:** bitcoin-core-development, validation, c++

> **Comments:**
> **username_1**: Thanks for documenting the questions from the review club here!  

---

## 1 answers

### Answer by username_0 on 2021-05-24. Score: 1 | Accepted answer

> What do the classes `ChainstateManager`, `CChainState`, `CChain` and `BlockManager` do?

A graphic from [Doxygen](https://doxygen.bitcoincore.org/class_chainstate_manager.html) showing how the classes interact:

[![Doxygen graphic](https://i.sstatic.net/6GWr2.png)](https://i.sstatic.net/6GWr2.png)

`ChainstateManager`: Provides an interface for creating and interacting with one or two chainstates

`CChainState`: Stores and provides an API to update our local knowledge of the current best chain.

`CChain`: An in-memory indexed chain of blocks. It was introduced in [PR 3077](https://github.com/bitcoin/bitcoin/pull/3077).

`BlockManager`: Maintains a tree of blocks (stored in `m_block_index`) which is consulted to determine where the most-work tip is.

> Why do `CChainState` and `CChain` have a leading 'C', but `ChainstateManager` and `BlockManager` don't?

C stands for class using Hungarian style naming.

The current style in Bitcoin Core is not to use Hungarian notation. Bitcoin Core uses `m_` to represent member variables, `g_` to represent globals, and no prefix to represent local variables/parameters. `CChainState` and `CChain` were named prior to these style guidelines being implemented in Bitcoin Core.

These were answered by John Newbery and other participants of the May 12th 2021 [Bitcoin Core PR review club](https://bitcoincore.reviews/21767).


---

