| 1531 | } |
| 1532 | |
| 1533 | static 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 */ |
| 1565 | static bool AbortNode(const std::string& strMessage, const std::string& userMessage="") |
no test coverage detected