@@ -1380,8 +1380,13 @@ bool UndoWriteToDisk(const CBlockUndo& blockundo, CDiskBlockPos& pos, const uint
1380
1380
return true ;
1381
1381
}
1382
1382
1383
- bool UndoReadFromDisk (CBlockUndo& blockundo, const CDiskBlockPos& pos, const uint256& hashBlock )
1383
+ static bool UndoReadFromDisk (CBlockUndo& blockundo, const CBlockIndex *pindex )
1384
1384
{
1385
+ CDiskBlockPos pos = pindex->GetUndoPos ();
1386
+ if (pos.IsNull ()) {
1387
+ return error (" %s: no undo data available" , __func__);
1388
+ }
1389
+
1385
1390
// Open history file to read
1386
1391
CAutoFile filein (OpenUndoFile (pos, true ), SER_DISK, CLIENT_VERSION);
1387
1392
if (filein.IsNull ())
@@ -1391,7 +1396,7 @@ bool UndoReadFromDisk(CBlockUndo& blockundo, const CDiskBlockPos& pos, const uin
1391
1396
uint256 hashChecksum;
1392
1397
CHashVerifier<CAutoFile> verifier (&filein); // We need a CHashVerifier as reserializing may lose data
1393
1398
try {
1394
- verifier << hashBlock ;
1399
+ verifier << pindex-> pprev -> GetBlockHash () ;
1395
1400
verifier >> blockundo;
1396
1401
filein >> hashChecksum;
1397
1402
}
@@ -1474,12 +1479,7 @@ static DisconnectResult DisconnectBlock(const CBlock& block, const CBlockIndex*
1474
1479
bool fClean = true ;
1475
1480
1476
1481
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)) {
1483
1483
error (" DisconnectBlock(): failure reading undo data" );
1484
1484
return DISCONNECT_FAILED;
1485
1485
}
@@ -3723,10 +3723,10 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
3723
3723
// check level 2: verify undo validity
3724
3724
if (nCheckLevel >= 2 && pindex) {
3725
3725
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)) {
3729
3728
return error (" VerifyDB(): *** found bad undo data at %d, hash=%s\n " , pindex->nHeight , pindex->GetBlockHash ().ToString ());
3729
+ }
3730
3730
}
3731
3731
}
3732
3732
// check level 3: check for inconsistencies during memory-only disconnect of tip blocks
0 commit comments