aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2015-01-26 09:47:59 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2015-02-05 14:21:25 +0100
commitf5791c6ae3b59ef4c8d04e6873310a022e1211b6 (patch)
treeb4c259437b6104c1efd4db667fd5c13dfac08976
parent1c4e3f99f05273e4d0fae7246d3afe5a33c52ee0 (diff)
downloadbitcoin-f5791c6ae3b59ef4c8d04e6873310a022e1211b6.tar.xz
Add more information to errors in ReadBlockFromDisk
A lot of times, disk corruption problems appear here. To facilitate debugging and troubleshooting, add position information to the error messages.
-rw-r--r--src/chain.h6
-rw-r--r--src/main.cpp9
2 files changed, 11 insertions, 4 deletions
diff --git a/src/chain.h b/src/chain.h
index 004e87ab52..02f53cd2f2 100644
--- a/src/chain.h
+++ b/src/chain.h
@@ -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 {
diff --git a/src/main.cpp b/src/main.cpp
index 27c427f7cd..32baf5508a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -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;
}
@@ -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;
}