diff --git a/src/init.cpp b/src/init.cpp index fafc4a88b7..be7983b511 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2074,32 +2074,58 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) // LOAD SERIALIZED DAT FILES INTO DATA CACHES FOR INTERNAL USE - bool fIgnoreCacheFiles = fLiteMode || fReindex || fReindexChainState; - if (!fIgnoreCacheFiles) { - fs::path pathDB = GetDataDir(); - std::string strDBName; + bool fLoadCacheFiles = !(fLiteMode || fReindex || fReindexChainState); + { + LOCK(cs_main); + // was blocks/chainstate deleted? + if (chainActive.Tip() == nullptr) { + fLoadCacheFiles = false; + } + } + fs::path pathDB = GetDataDir(); + std::string strDBName; - strDBName = "mncache.dat"; - uiInterface.InitMessage(_("Loading masternode cache...")); - CFlatDB flatdb1(strDBName, "magicMasternodeCache"); + strDBName = "mncache.dat"; + uiInterface.InitMessage(_("Loading masternode cache...")); + CFlatDB flatdb1(strDBName, "magicMasternodeCache"); + if (fLoadCacheFiles) { if(!flatdb1.Load(mmetaman)) { return InitError(_("Failed to load masternode cache from") + "\n" + (pathDB / strDBName).string()); } + } else { + CMasternodeMetaMan mmetamanTmp; + if(!flatdb1.Dump(mmetamanTmp)) { + return InitError(_("Failed to clear masternode cache at") + "\n" + (pathDB / strDBName).string()); + } + } - strDBName = "governance.dat"; - uiInterface.InitMessage(_("Loading governance cache...")); - CFlatDB flatdb3(strDBName, "magicGovernanceCache"); + strDBName = "governance.dat"; + uiInterface.InitMessage(_("Loading governance cache...")); + CFlatDB flatdb3(strDBName, "magicGovernanceCache"); + if (fLoadCacheFiles) { if(!flatdb3.Load(governance)) { return InitError(_("Failed to load governance cache from") + "\n" + (pathDB / strDBName).string()); } governance.InitOnLoad(); + } else { + CGovernanceManager governanceTmp; + if(!flatdb3.Dump(governanceTmp)) { + return InitError(_("Failed to clear governance cache at") + "\n" + (pathDB / strDBName).string()); + } + } - strDBName = "netfulfilled.dat"; - uiInterface.InitMessage(_("Loading fulfilled requests cache...")); - CFlatDB flatdb4(strDBName, "magicFulfilledCache"); + strDBName = "netfulfilled.dat"; + uiInterface.InitMessage(_("Loading fulfilled requests cache...")); + CFlatDB flatdb4(strDBName, "magicFulfilledCache"); + if (fLoadCacheFiles) { if(!flatdb4.Load(netfulfilledman)) { return InitError(_("Failed to load fulfilled requests cache from") + "\n" + (pathDB / strDBName).string()); } + } else { + CNetFulfilledRequestManager netfulfilledmanTmp; + if(!flatdb4.Dump(netfulfilledmanTmp)) { + return InitError(_("Failed to clear fulfilled requests cache at") + "\n" + (pathDB / strDBName).string()); + } } // ********************************************************* Step 10c: schedule Dash-specific tasks