The const_cast
CBlock &block = const_cast<CBlock&>(chainparams.GenesisBlock());
is not necessary as all the functions invoked form this block receive a const CBlock& anyway. Simply add the const to block:
const CBlock& block = chainparams.GenesisBlock();
Casting away const, especially from something as precious as the genesis block, feels really weird to me as a reader of bitcoin-core source code.