mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
Make DisconnectBlock unaware of where undo data resides on disk
This commit is contained in:
parent
00d25e90db
commit
93a34cfeec
@ -1380,8 +1380,13 @@ bool UndoWriteToDisk(const CBlockUndo& blockundo, CDiskBlockPos& pos, const uint
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UndoReadFromDisk(CBlockUndo& blockundo, const CDiskBlockPos& pos, const uint256& hashBlock)
|
||||
static bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex *pindex)
|
||||
{
|
||||
CDiskBlockPos pos = pindex->GetUndoPos();
|
||||
if (pos.IsNull()) {
|
||||
return error("%s: no undo data available", __func__);
|
||||
}
|
||||
|
||||
// Open history file to read
|
||||
CAutoFile filein(OpenUndoFile(pos, true), SER_DISK, CLIENT_VERSION);
|
||||
if (filein.IsNull())
|
||||
@ -1391,7 +1396,7 @@ bool UndoReadFromDisk(CBlockUndo& blockundo, const CDiskBlockPos& pos, const uin
|
||||
uint256 hashChecksum;
|
||||
CHashVerifier<CAutoFile> verifier(&filein); // We need a CHashVerifier as reserializing may lose data
|
||||
try {
|
||||
verifier << hashBlock;
|
||||
verifier << pindex->pprev->GetBlockHash();
|
||||
verifier >> blockundo;
|
||||
filein >> hashChecksum;
|
||||
}
|
||||
@ -1474,12 +1479,7 @@ static DisconnectResult DisconnectBlock(const CBlock& block, const CBlockIndex*
|
||||
bool fClean = true;
|
||||
|
||||
CBlockUndo blockUndo;
|
||||
CDiskBlockPos pos = pindex->GetUndoPos();
|
||||
if (pos.IsNull()) {
|
||||
error("DisconnectBlock(): no undo data available");
|
||||
return DISCONNECT_FAILED;
|
||||
}
|
||||
if (!UndoReadFromDisk(blockUndo, pos, pindex->pprev->GetBlockHash())) {
|
||||
if (!UndoReadFromDisk(blockUndo, pindex)) {
|
||||
error("DisconnectBlock(): failure reading undo data");
|
||||
return DISCONNECT_FAILED;
|
||||
}
|
||||
@ -3723,10 +3723,10 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
|
||||
// check level 2: verify undo validity
|
||||
if (nCheckLevel >= 2 && pindex) {
|
||||
CBlockUndo undo;
|
||||
CDiskBlockPos pos = pindex->GetUndoPos();
|
||||
if (!pos.IsNull()) {
|
||||
if (!UndoReadFromDisk(undo, pos, pindex->pprev->GetBlockHash()))
|
||||
if (!pindex->GetUndoPos().IsNull()) {
|
||||
if (!UndoReadFromDisk(undo, pindex)) {
|
||||
return error("VerifyDB(): *** found bad undo data at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
// check level 3: check for inconsistencies during memory-only disconnect of tip blocks
|
||||
|
Loading…
Reference in New Issue
Block a user