Skip to content

Commit aed38cb

Browse files
committed
Merge pull request #4173
8c93bf4 LoadBlockIndexDB(): Require block db reindex if any blk*.dat files are missing. (Ashley Holman) 7a0e84d ProcessGetData(): abort if a block file is missing from disk (Ashley Holman)
2 parents c26acfc + 8c93bf4 commit aed38cb

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/main.cpp

Lines changed: 19 additions & 1 deletion
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);
@@ -3373,7 +3391,7 @@ void static ProcessGetData(CNode* pfrom)
33733391
{
33743392
// Send block from disk
33753393
CBlock block;
3376-
ReadBlockFromDisk(block, (*mi).second);
3394+
assert(ReadBlockFromDisk(block, (*mi).second));
33773395
if (inv.type == MSG_BLOCK)
33783396
pfrom->PushMessage("block", block);
33793397
else // MSG_FILTERED_BLOCK)

0 commit comments

Comments
 (0)