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)
This commit is contained in:
Wladimir J. van der Laan 2014-05-19 16:01:43 +02:00
commit aed38cbcb5
No known key found for this signature in database
GPG key ID: 74810B012346C9A6

View file

@ -2941,6 +2941,24 @@ bool static LoadBlockIndexDB()
if (pblocktree->ReadBlockFileInfo(nLastBlockFile, infoLastBlockFile)) if (pblocktree->ReadBlockFileInfo(nLastBlockFile, infoLastBlockFile))
LogPrintf("LoadBlockIndexDB(): last block file info: %s\n", infoLastBlockFile.ToString()); LogPrintf("LoadBlockIndexDB(): last block file info: %s\n", infoLastBlockFile.ToString());
// Check presence of blk files
LogPrintf("Checking all blk files are present...\n");
set<int> setBlkDataFiles;
BOOST_FOREACH(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex)
{
CBlockIndex* pindex = item.second;
if (pindex->nStatus & BLOCK_HAVE_DATA) {
setBlkDataFiles.insert(pindex->nFile);
}
}
for (std::set<int>::iterator it = setBlkDataFiles.begin(); it != setBlkDataFiles.end(); it++)
{
CDiskBlockPos pos(*it, 0);
if (!CAutoFile(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION)) {
return false;
}
}
// Check whether we need to continue reindexing // Check whether we need to continue reindexing
bool fReindexing = false; bool fReindexing = false;
pblocktree->ReadReindexing(fReindexing); pblocktree->ReadReindexing(fReindexing);
@ -3373,7 +3391,7 @@ void static ProcessGetData(CNode* pfrom)
{ {
// Send block from disk // Send block from disk
CBlock block; CBlock block;
ReadBlockFromDisk(block, (*mi).second); assert(ReadBlockFromDisk(block, (*mi).second));
if (inv.type == MSG_BLOCK) if (inv.type == MSG_BLOCK)
pfrom->PushMessage("block", block); pfrom->PushMessage("block", block);
else // MSG_FILTERED_BLOCK) else // MSG_FILTERED_BLOCK)