This is to track the regression introduced in master, which needs fixing for 0.14. See #9240, #9371, etc.
do {
        CBlockIndex *pindexNew = NULL;
        
        {
            std::set<CBlockIndex*, CBlockIndexWorkComparator>::reverse_iterator it = setBlockIndexCandidates.rbegin();
            if (it == setBlockIndexCandidates.rend())
                return NULL;
            pindexNew = *it;
        }
        
        
        CBlockIndex *pindexTest = pindexNew;
        bool fInvalidAncestor = false;
        while (pindexTest && !chainActive.Contains(pindexTest)) {
            assert(pindexTest->nChainTx || pindexTest->nHeight == 0);
            
            
            
            
            bool fFailedChain = pindexTest->nStatus & BLOCK_FAILED_MASK;