From 7a0e84dd63ac98a92fd7aafd2d432f1da71eb8da Mon Sep 17 00:00:00 2001 From: Ashley Holman Date: Sun, 11 May 2014 00:30:18 -0500 Subject: [PATCH 1/2] ProcessGetData(): abort if a block file is missing from disk --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 379ca3ef7..f90f03801 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3373,7 +3373,7 @@ void static ProcessGetData(CNode* pfrom) { // Send block from disk CBlock block; - ReadBlockFromDisk(block, (*mi).second); + assert(ReadBlockFromDisk(block, (*mi).second)); if (inv.type == MSG_BLOCK) pfrom->PushMessage("block", block); else // MSG_FILTERED_BLOCK) From 8c93bf4c2857cdc01f0e5efca2becef08d2c5f1e Mon Sep 17 00:00:00 2001 From: Ashley Holman Date: Sun, 11 May 2014 07:05:04 -0500 Subject: [PATCH 2/2] LoadBlockIndexDB(): Require block db reindex if any blk*.dat files are missing. --- src/main.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index f90f03801..4b0e3af64 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2941,6 +2941,24 @@ bool static LoadBlockIndexDB() if (pblocktree->ReadBlockFileInfo(nLastBlockFile, infoLastBlockFile)) LogPrintf("LoadBlockIndexDB(): last block file info: %s\n", infoLastBlockFile.ToString()); + // Check presence of blk files + LogPrintf("Checking all blk files are present...\n"); + set 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::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 bool fReindexing = false; pblocktree->ReadReindexing(fReindexing);