LoadChainTip requires cs_main to be locked. Under some conditions, it may call ActivateBestChain. However, ActivateBestChain requires cs_main NOT to be taken when called.
UnlinkPrunedFiles(setFilesToPrune);
            nLastWrite = nNow;
        }
        
        if (fDoFullFlush && !pcoinsTip->GetBestBlock().IsNull()) {
            
            
            
            
            
            if (!CheckDiskSpace(GetDataDir(), 48 * 2 * 2 * pcoinsTip->GetCacheSize())) {
                return AbortNode(state, "Disk space is low!", _("Error: Disk space is low!"));
            }
            
            if (!pcoinsTip->Flush())
                return AbortNode(state, "Failed to write to coin database");
            nLastFlush = nNow;
            full_flush_completed = true;
        }
    }
    if (full_flush_completed) {
        
        GetMainSignals().ChainStateFlushed(::ChainActive().GetLocator());
    }
    } catch (const std::runtime_error& e) {
        return AbortNode(state, std::string("System error while flushing: ") + e.what());
    }
    return true;
}
void FlushStateToDisk() {