This removes several globals (pindexBest, pindexGenesisBlock, hashBestChain, nBestHeight, nBestChainWork, vBlockIndexByHeight), and replaces them by chainBlocks, an instance of a new CChain class. CChain actually only wraps what was previously stored in vBlockIndexByHeight - all other variables are redundant and can be computed from that one.
This is a preparation for a second iteration of headersfirst which I’m implementing, which will add a second instance of CChain (chainHeaders) in addition to chainActive. This pull request shouldn’t change any functionality.
Since pindexGenesisBlock, hashBestBlock and nBestChainWork are now computed when needed rather than stored, there are potential edge cases in which no genesis block exists yet, and chainActive.Tip() returns NULL. I have tested synchronizing from network and reindexing.