Skip to content

Commit ce56f56

Browse files
committed
Merge pull request #6173
e697343 Chainparams: Explicit CMessageHeader::MessageStartChars to functions in main: (Jorge Timón)
2 parents c7c9af3 + e697343 commit ce56f56

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/main.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock
11461146
// CBlock and CBlockIndex
11471147
//
11481148

1149-
bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos)
1149+
bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos, const CMessageHeader::MessageStartChars& messageStart)
11501150
{
11511151
// Open history file to append
11521152
CAutoFile fileout(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION);
@@ -1155,7 +1155,7 @@ bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos)
11551155

11561156
// Write index header
11571157
unsigned int nSize = fileout.GetSerializeSize(block);
1158-
fileout << FLATDATA(Params().MessageStart()) << nSize;
1158+
fileout << FLATDATA(messageStart) << nSize;
11591159

11601160
// Write block
11611161
long fileOutPos = ftell(fileout.Get());
@@ -1509,7 +1509,7 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
15091509

15101510
namespace {
15111511

1512-
bool UndoWriteToDisk(const CBlockUndo& blockundo, CDiskBlockPos& pos, const uint256& hashBlock)
1512+
bool UndoWriteToDisk(const CBlockUndo& blockundo, CDiskBlockPos& pos, const uint256& hashBlock, const CMessageHeader::MessageStartChars& messageStart)
15131513
{
15141514
// Open history file to append
15151515
CAutoFile fileout(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION);
@@ -1518,7 +1518,7 @@ bool UndoWriteToDisk(const CBlockUndo& blockundo, CDiskBlockPos& pos, const uint
15181518

15191519
// Write index header
15201520
unsigned int nSize = fileout.GetSerializeSize(blockundo);
1521-
fileout << FLATDATA(Params().MessageStart()) << nSize;
1521+
fileout << FLATDATA(messageStart) << nSize;
15221522

15231523
// Write undo data
15241524
long fileOutPos = ftell(fileout.Get());
@@ -1918,7 +1918,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
19181918
CDiskBlockPos pos;
19191919
if (!FindUndoPos(state, pindex->nFile, pos, ::GetSerializeSize(blockundo, SER_DISK, CLIENT_VERSION) + 40))
19201920
return error("ConnectBlock(): FindUndoPos failed");
1921-
if (!UndoWriteToDisk(blockundo, pos, pindex->pprev->GetBlockHash()))
1921+
if (!UndoWriteToDisk(blockundo, pos, pindex->pprev->GetBlockHash(), chainparams.MessageStart()))
19221922
return AbortNode(state, "Failed to write undo data");
19231923

19241924
// update nUndoPos in block index
@@ -2841,6 +2841,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc
28412841

28422842
bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, CDiskBlockPos* dbp)
28432843
{
2844+
const CChainParams& chainparams = Params();
28442845
AssertLockHeld(cs_main);
28452846

28462847
CBlockIndex *&pindex = *ppindex;
@@ -2876,7 +2877,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
28762877
if (!FindBlockPos(state, blockPos, nBlockSize+8, nHeight, block.GetBlockTime(), dbp != NULL))
28772878
return error("AcceptBlock(): FindBlockPos failed");
28782879
if (dbp == NULL)
2879-
if (!WriteBlockToDisk(block, blockPos))
2880+
if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart()))
28802881
AbortNode(state, "Failed to write block");
28812882
if (!ReceivedBlockTransactions(block, state, pindex, blockPos))
28822883
return error("AcceptBlock(): ReceivedBlockTransactions failed");
@@ -3366,6 +3367,7 @@ bool LoadBlockIndex()
33663367

33673368

33683369
bool InitBlockIndex() {
3370+
const CChainParams& chainparams = Params();
33693371
LOCK(cs_main);
33703372
// Check whether we're already initialized
33713373
if (chainActive.Genesis() != NULL)
@@ -3386,7 +3388,7 @@ bool InitBlockIndex() {
33863388
CValidationState state;
33873389
if (!FindBlockPos(state, blockPos, nBlockSize+8, 0, block.GetBlockTime()))
33883390
return error("LoadBlockIndex(): FindBlockPos failed");
3389-
if (!WriteBlockToDisk(block, blockPos))
3391+
if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart()))
33903392
return error("LoadBlockIndex(): writing genesis block to disk failed");
33913393
CBlockIndex *pindex = AddToBlockIndex(block);
33923394
if (!ReceivedBlockTransactions(block, state, pindex, blockPos))

src/main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ class CScriptCheck
362362

363363

364364
/** Functions for disk access for blocks */
365-
bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos);
365+
bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos, const CMessageHeader::MessageStartChars& messageStart);
366366
bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos);
367367
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex);
368368

0 commit comments

Comments
 (0)