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

Function UndoReadFromDisk

src/main.cpp:1985–2010  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1983}
1984
1985bool UndoReadFromDisk(CBlockUndo& blockundo, const CDiskBlockPos& pos, const uint256& hashBlock)
1986{
1987 // Open history file to read
1988 CAutoFile filein(OpenUndoFile(pos, true), SER_DISK, CLIENT_VERSION);
1989 if (filein.IsNull())
1990 return error("%s: OpenBlockFile failed", __func__);
1991
1992 // Read block
1993 uint256 hashChecksum;
1994 try {
1995 filein >> blockundo;
1996 filein >> hashChecksum;
1997 }
1998 catch (const std::exception& e) {
1999 return error("%s: Deserialize or I/O error - %s", __func__, e.what());
2000 }
2001
2002 // Verify checksum
2003 CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION);
2004 hasher << hashBlock;
2005 hasher << blockundo;
2006 if (hashChecksum != hasher.GetHash())
2007 return error("%s: Checksum mismatch", __func__);
2008
2009 return true;
2010}
2011
2012/** Abort with a message */
2013bool AbortNode(const std::string& strMessage, const std::string& userMessage="")

Callers 2

DisconnectBlockFunction · 0.85
VerifyDBMethod · 0.85

Calls 4

OpenUndoFileFunction · 0.85
errorFunction · 0.85
IsNullMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected