Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: nkjack on November 30, 2018, 03:49:44 PM



Title: Bitcoin-core - globals in validation.cpp
Post by: nkjack on November 30, 2018, 03:49:44 PM
Hey,

I have tried to understand the validation.cpp in the bitcoin core more deeply and there is something that I don't understand.

In the validation.cpp there is a instance of CChainState g_chainstate storing CChain chainActive and BlockMap mapBlockIndex.

In addition there are global variables instantiated outside the CChainState class, two of them are:

BlockMap& mapBlockIndex = g_chainstate.mapBlockIndex;
CChain& chainActive = g_chainstate.chainActive;

Why is it coded that why? why not making the mapBlockIndex and chainActive just static variables in the CChainState class?

It seems to me that these variables are not necessarily have to be global variables, but I might miss something.

Thank you very much.