Skip to content

Commit 4fe609f

Browse files
jtimonrandom-zebra
authored andcommitted
Decouple CBlockUndo from CDiskBlockPos
1 parent 9703b0e commit 4fe609f

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/main.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,6 +1933,9 @@ static bool AbortNode(CValidationState& state, const std::string& strMessage, co
19331933
return state.Error(strMessage);
19341934
}
19351935

1936+
bool UndoWriteToDisk(const CBlockUndo& blockundo, CDiskBlockPos& pos, const uint256& hashBlock);
1937+
bool UndoReadFromDisk(CBlockUndo& blockundo, const CDiskBlockPos& pos, const uint256& hashBlock);
1938+
19361939
bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool* pfClean)
19371940
{
19381941
AssertLockHeld(cs_main);
@@ -1952,7 +1955,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
19521955
CDiskBlockPos pos = pindex->GetUndoPos();
19531956
if (pos.IsNull())
19541957
return error("DisconnectBlock() : no undo data available");
1955-
if (!blockUndo.ReadFromDisk(pos, pindex->pprev->GetBlockHash()))
1958+
if (!UndoReadFromDisk(blockUndo, pos, pindex->pprev->GetBlockHash()))
19561959
return error("DisconnectBlock() : failure reading undo data");
19571960

19581961
if (blockUndo.vtxundo.size() + 1 != block.vtx.size())
@@ -2320,7 +2323,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
23202323
CDiskBlockPos diskPosBlock;
23212324
if (!FindUndoPos(state, pindex->nFile, diskPosBlock, ::GetSerializeSize(blockundo, SER_DISK, CLIENT_VERSION) + 40))
23222325
return error("ConnectBlock() : FindUndoPos failed");
2323-
if (!blockundo.WriteToDisk(diskPosBlock, pindex->pprev->GetBlockHash()))
2326+
if (!UndoWriteToDisk(blockundo, diskPosBlock, pindex->pprev->GetBlockHash()))
23242327
return AbortNode(state, "Failed to write undo data");
23252328

23262329
// update nUndoPos in block index
@@ -4351,7 +4354,7 @@ bool CVerifyDB::VerifyDB(CCoinsView* coinsview, int nCheckLevel, int nCheckDepth
43514354
CBlockUndo undo;
43524355
CDiskBlockPos pos = pindex->GetUndoPos();
43534356
if (!pos.IsNull()) {
4354-
if (!undo.ReadFromDisk(pos, pindex->pprev->GetBlockHash()))
4357+
if (!UndoReadFromDisk(undo, pos, pindex->pprev->GetBlockHash()))
43554358
return error("%s: *** found bad undo data at %d, hash=%s\n", __func__, pindex->nHeight, pindex->GetBlockHash().ToString());
43564359
}
43574360
}
@@ -6218,44 +6221,44 @@ bool SendMessages(CNode* pto)
62186221
}
62196222

62206223

6221-
bool CBlockUndo::WriteToDisk(CDiskBlockPos& pos, const uint256& hashBlock)
6224+
bool UndoWriteToDisk(const CBlockUndo& blockundo, CDiskBlockPos& pos, const uint256& hashBlock)
62226225
{
62236226
// Open history file to append
62246227
CAutoFile fileout(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION);
62256228
if (fileout.IsNull())
6226-
return error("CBlockUndo::WriteToDisk : OpenUndoFile failed");
6229+
return error("%s : OpenUndoFile failed", __func__);
62276230

62286231
// Write index header
6229-
unsigned int nSize = GetSerializeSize(fileout, *this);
6232+
unsigned int nSize = GetSerializeSize(fileout, blockundo);
62306233
fileout << FLATDATA(Params().MessageStart()) << nSize;
62316234

62326235
// Write undo data
62336236
long fileOutPos = ftell(fileout.Get());
62346237
if (fileOutPos < 0)
6235-
return error("CBlockUndo::WriteToDisk : ftell failed");
6238+
return error("%s : ftell failed", __func__);
62366239
pos.nPos = (unsigned int)fileOutPos;
6237-
fileout << *this;
6240+
fileout << blockundo;
62386241

62396242
// calculate & write checksum
62406243
CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION);
62416244
hasher << hashBlock;
6242-
hasher << *this;
6245+
hasher << blockundo;
62436246
fileout << hasher.GetHash();
62446247

62456248
return true;
62466249
}
62476250

6248-
bool CBlockUndo::ReadFromDisk(const CDiskBlockPos& pos, const uint256& hashBlock)
6251+
bool UndoReadFromDisk(CBlockUndo& blockundo, const CDiskBlockPos& pos, const uint256& hashBlock)
62496252
{
62506253
// Open history file to read
62516254
CAutoFile filein(OpenUndoFile(pos, true), SER_DISK, CLIENT_VERSION);
62526255
if (filein.IsNull())
6253-
return error("CBlockUndo::ReadFromDisk : OpenBlockFile failed");
6256+
return error("%s : OpenBlockFile failed", __func__);
62546257

62556258
// Read block
62566259
uint256 hashChecksum;
62576260
try {
6258-
filein >> *this;
6261+
filein >> blockundo;
62596262
filein >> hashChecksum;
62606263
} catch (const std::exception& e) {
62616264
return error("%s : Deserialize or I/O error - %s", __func__, e.what());
@@ -6264,9 +6267,9 @@ bool CBlockUndo::ReadFromDisk(const CDiskBlockPos& pos, const uint256& hashBlock
62646267
// Verify checksum
62656268
CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION);
62666269
hasher << hashBlock;
6267-
hasher << *this;
6270+
hasher << blockundo;
62686271
if (hashChecksum != hasher.GetHash())
6269-
return error("CBlockUndo::ReadFromDisk : Checksum mismatch");
6272+
return error("%s : Checksum mismatch", __func__);
62706273

62716274
return true;
62726275
}

src/undo.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ class CBlockUndo
8282
{
8383
READWRITE(vtxundo);
8484
}
85-
86-
bool WriteToDisk(CDiskBlockPos& pos, const uint256& hashBlock);
87-
bool ReadFromDisk(const CDiskBlockPos& pos, const uint256& hashBlock);
8885
};
8986

9087
#endif // BITCOIN_UNDO_H

0 commit comments

Comments
 (0)