1

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 hosted by John Newbery on a Carl Dong PR to de-globalize ChainstateManager.

1
  • 1
    Thanks for documenting the questions from the review club here! Jun 19 at 8:08
1

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

A graphic from Doxygen showing how the classes interact:

Doxygen graphic

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.

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.

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.