Skip to content

Commit

Permalink
Add more information to errors in ReadBlockFromDisk
Browse files Browse the repository at this point in the history
A lot of times, disk corruption problems appear here.
To facilitate debugging and troubleshooting, add position information
to the error messages.
  • Loading branch information
laanwj committed Feb 5, 2015
1 parent 1c4e3f9 commit f5791c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ struct CDiskBlockPos

void SetNull() { nFile = -1; nPos = 0; }
bool IsNull() const { return (nFile == -1); }

std::string ToString() const
{
return strprintf("CBlockDiskPos(nFile=%i, nPos=%i)", nFile, nPos);
}

};

enum BlockStatus {
Expand Down
9 changes: 5 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,19 +1199,19 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos)
// Open history file to read
CAutoFile filein(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION);
if (filein.IsNull())
return error("ReadBlockFromDisk: OpenBlockFile failed");
return error("ReadBlockFromDisk: OpenBlockFile failed for %s", pos.ToString());

// Read block
try {
filein >> block;
}
catch (const std::exception& e) {
return error("%s: Deserialize or I/O error - %s", __func__, e.what());
return error("%s: Deserialize or I/O error - %s at %s", __func__, e.what(), pos.ToString());
}

// Check the header
if (!CheckProofOfWork(block.GetHash(), block.nBits))
return error("ReadBlockFromDisk: Errors in block header");
return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString());

return true;
}
Expand All @@ -1221,7 +1221,8 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex)
if (!ReadBlockFromDisk(block, pindex->GetBlockPos()))
return false;
if (block.GetHash() != pindex->GetBlockHash())
return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index");
return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s",
pindex->ToString(), pindex->GetBlockPos().ToString());
return true;
}

Expand Down

0 comments on commit f5791c6

Please sign in to comment.