Skip to content

Commit 8c93bf4

Browse files
committed
LoadBlockIndexDB(): Require block db reindex if any blk*.dat files are missing.
1 parent 7a0e84d commit 8c93bf4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/main.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,6 +2941,24 @@ bool static LoadBlockIndexDB()
29412941
if (pblocktree->ReadBlockFileInfo(nLastBlockFile, infoLastBlockFile))
29422942
LogPrintf("LoadBlockIndexDB(): last block file info: %s\n", infoLastBlockFile.ToString());
29432943

2944+
// Check presence of blk files
2945+
LogPrintf("Checking all blk files are present...\n");
2946+
set<int> setBlkDataFiles;
2947+
BOOST_FOREACH(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex)
2948+
{
2949+
CBlockIndex* pindex = item.second;
2950+
if (pindex->nStatus & BLOCK_HAVE_DATA) {
2951+
setBlkDataFiles.insert(pindex->nFile);
2952+
}
2953+
}
2954+
for (std::set<int>::iterator it = setBlkDataFiles.begin(); it != setBlkDataFiles.end(); it++)
2955+
{
2956+
CDiskBlockPos pos(*it, 0);
2957+
if (!CAutoFile(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION)) {
2958+
return false;
2959+
}
2960+
}
2961+
29442962
// Check whether we need to continue reindexing
29452963
bool fReindexing = false;
29462964
pblocktree->ReadReindexing(fReindexing);

0 commit comments

Comments
 (0)