mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
Don't load caches when blocks/chainstate was deleted and also delete old caches (#3280)
* Don't load caches when blocks/chainstate was not present * Delete old cache files when we decided to not load them * Make sure cache files are of the exact format we expected them to be, flush empty objects into them instead of deleting files naively * Streamline logic a bit, rename fIgnoreCacheFiles to fLoadCacheFiles Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
This commit is contained in:
parent
ebf529e8aa
commit
ce924278df
52
src/init.cpp
52
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<CMasternodeMetaMan> flatdb1(strDBName, "magicMasternodeCache");
|
||||
strDBName = "mncache.dat";
|
||||
uiInterface.InitMessage(_("Loading masternode cache..."));
|
||||
CFlatDB<CMasternodeMetaMan> 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<CGovernanceManager> flatdb3(strDBName, "magicGovernanceCache");
|
||||
strDBName = "governance.dat";
|
||||
uiInterface.InitMessage(_("Loading governance cache..."));
|
||||
CFlatDB<CGovernanceManager> 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<CNetFulfilledRequestManager> flatdb4(strDBName, "magicFulfilledCache");
|
||||
strDBName = "netfulfilled.dat";
|
||||
uiInterface.InitMessage(_("Loading fulfilled requests cache..."));
|
||||
CFlatDB<CNetFulfilledRequestManager> 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
|
||||
|
Loading…
Reference in New Issue
Block a user