aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-12-30 23:41:41 +0100
committerPieter Wuille <pieter.wuille@gmail.com>2013-01-03 15:29:19 +0100
commit8539361e66eace839060f77f39b770d045e7ce28 (patch)
treec66def3d40aeb33fbb945c1dc28a9eafd11f5005 /src/main.cpp
parent2cbd71da06a14ffe823440973f8a87032bbe0b1e (diff)
downloadbitcoin-8539361e66eace839060f77f39b770d045e7ce28.tar.xz
Add checksums to undo data
This should be compatible with older code that didn't write checksums.
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp22
1 files changed, 7 insertions, 15 deletions
diff --git a/src/main.cpp b/src/main.cpp
index bb39f422f9..2619062a6b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1474,19 +1474,11 @@ bool CBlock::DisconnectBlock(CBlockIndex *pindex, CCoinsViewCache &view, bool *p
bool fClean = true;
CBlockUndo blockUndo;
- {
- CDiskBlockPos pos = pindex->GetUndoPos();
- if (pos.IsNull())
- return error("DisconnectBlock() : no undo data available");
- CAutoFile fileUndo(OpenUndoFile(pos, true), SER_DISK, CLIENT_VERSION);
- if (!fileUndo)
- return error("DisconnectBlock() : cannot open undo file");
- try {
- fileUndo >> blockUndo;
- } catch(std::exception &e) {
- return error("DisconnectBlock() : deserialize or I/O error reading udno data");
- }
- }
+ CDiskBlockPos pos = pindex->GetUndoPos();
+ if (pos.IsNull())
+ return error("DisconnectBlock() : no undo data available");
+ if (!blockUndo.ReadFromDisk(pos, pindex->pprev->GetBlockHash()))
+ return error("DisconnectBlock() : failure reading undo data");
if (blockUndo.vtxundo.size() + 1 != vtx.size())
return error("DisconnectBlock() : block and undo data inconsistent");
@@ -1670,9 +1662,9 @@ bool CBlock::ConnectBlock(CBlockIndex* pindex, CCoinsViewCache &view, bool fJust
{
if (pindex->GetUndoPos().IsNull()) {
CDiskBlockPos pos;
- if (!FindUndoPos(pindex->nFile, pos, ::GetSerializeSize(blockundo, SER_DISK, CLIENT_VERSION) + 8))
+ if (!FindUndoPos(pindex->nFile, pos, ::GetSerializeSize(blockundo, SER_DISK, CLIENT_VERSION) + 40))
return error("ConnectBlock() : FindUndoPos failed");
- if (!blockundo.WriteToDisk(pos))
+ if (!blockundo.WriteToDisk(pos, pindex->pprev->GetBlockHash()))
return error("ConnectBlock() : CBlockUndo::WriteToDisk failed");
// update nUndoPos in block index