MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / UndoReadFromDisk

Function UndoReadFromDisk

src/validation.cpp:1533–1562  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1531}
1532
1533static bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex *pindex)
1534{
1535 CDiskBlockPos pos = pindex->GetUndoPos();
1536 if (pos.IsNull()) {
1537 return error("%s: no undo data available", __func__);
1538 }
1539
1540 // Open history file to read
1541 CAutoFile filein(OpenUndoFile(pos, true), SER_DISK, CLIENT_VERSION);
1542 if (filein.IsNull())
1543 return error("%s: OpenUndoFile failed", __func__);
1544
1545 // Read block
1546 uint256 hashChecksum;
1547 CHashVerifier<CAutoFile> verifier(&filein); // We need a CHashVerifier as reserializing may lose data
1548 try {
1549 verifier << pindex->pprev->GetBlockHash();
1550 verifier >> blockundo;
1551 filein >> hashChecksum;
1552 }
1553 catch (const std::exception& e) {
1554 return error("%s: Deserialize or I/O error - %s", __func__, e.what());
1555 }
1556
1557 // Verify checksum
1558 if (hashChecksum != verifier.GetHash())
1559 return error("%s: Checksum mismatch", __func__);
1560
1561 return true;
1562}
1563
1564/** Abort with a message */
1565static bool AbortNode(const std::string& strMessage, const std::string& userMessage="")

Callers 2

DisconnectBlockMethod · 0.85
VerifyDBMethod · 0.85

Calls 7

errorFunction · 0.85
OpenUndoFileFunction · 0.85
GetUndoPosMethod · 0.80
whatMethod · 0.80
IsNullMethod · 0.45
GetBlockHashMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected