Skip to content

Commit 93a34cf

Browse files
committed
Make DisconnectBlock unaware of where undo data resides on disk
1 parent 00d25e9 commit 93a34cf

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/validation.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,8 +1380,13 @@ bool UndoWriteToDisk(const CBlockUndo& blockundo, CDiskBlockPos& pos, const uint
13801380
return true;
13811381
}
13821382

1383-
bool UndoReadFromDisk(CBlockUndo& blockundo, const CDiskBlockPos& pos, const uint256& hashBlock)
1383+
static bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex *pindex)
13841384
{
1385+
CDiskBlockPos pos = pindex->GetUndoPos();
1386+
if (pos.IsNull()) {
1387+
return error("%s: no undo data available", __func__);
1388+
}
1389+
13851390
// Open history file to read
13861391
CAutoFile filein(OpenUndoFile(pos, true), SER_DISK, CLIENT_VERSION);
13871392
if (filein.IsNull())
@@ -1391,7 +1396,7 @@ bool UndoReadFromDisk(CBlockUndo& blockundo, const CDiskBlockPos& pos, const uin
13911396
uint256 hashChecksum;
13921397
CHashVerifier<CAutoFile> verifier(&filein); // We need a CHashVerifier as reserializing may lose data
13931398
try {
1394-
verifier << hashBlock;
1399+
verifier << pindex->pprev->GetBlockHash();
13951400
verifier >> blockundo;
13961401
filein >> hashChecksum;
13971402
}
@@ -1474,12 +1479,7 @@ static DisconnectResult DisconnectBlock(const CBlock& block, const CBlockIndex*
14741479
bool fClean = true;
14751480

14761481
CBlockUndo blockUndo;
1477-
CDiskBlockPos pos = pindex->GetUndoPos();
1478-
if (pos.IsNull()) {
1479-
error("DisconnectBlock(): no undo data available");
1480-
return DISCONNECT_FAILED;
1481-
}
1482-
if (!UndoReadFromDisk(blockUndo, pos, pindex->pprev->GetBlockHash())) {
1482+
if (!UndoReadFromDisk(blockUndo, pindex)) {
14831483
error("DisconnectBlock(): failure reading undo data");
14841484
return DISCONNECT_FAILED;
14851485
}
@@ -3723,10 +3723,10 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
37233723
// check level 2: verify undo validity
37243724
if (nCheckLevel >= 2 && pindex) {
37253725
CBlockUndo undo;
3726-
CDiskBlockPos pos = pindex->GetUndoPos();
3727-
if (!pos.IsNull()) {
3728-
if (!UndoReadFromDisk(undo, pos, pindex->pprev->GetBlockHash()))
3726+
if (!pindex->GetUndoPos().IsNull()) {
3727+
if (!UndoReadFromDisk(undo, pindex)) {
37293728
return error("VerifyDB(): *** found bad undo data at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
3729+
}
37303730
}
37313731
}
37323732
// check level 3: check for inconsistencies during memory-only disconnect of tip blocks

0 commit comments

Comments
 (0)