Skip to content

Commit be44332

Browse files
committed
Merge bitcoin/bitcoin#28191: refactor: Remove unused MessageStartChars parameters from BlockManager methods
fa69e3a Remove unused MessageStartChars parameters from BlockManager methods (MarcoFalke) Pull request description: Seems odd to expose these for mocking, when it is not needed. Fix this by removing the the unused parameters and use the already existing member field instead. ACKs for top commit: Empact: utACK fa69e3a dergoegge: utACK fa69e3a Tree-SHA512: 7814e9560abba8d9c0926bcffc70f92e502d22f543af43671248f6fcd1433f35238553c0f05123fde6d8e0f80261af0ab0500927548115153bd68d57fe2da746
2 parents b713825 + fa69e3a commit be44332

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2212,7 +2212,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
22122212
// Fast-path: in this case it is possible to serve the block directly from disk,
22132213
// as the network format matches the format on disk
22142214
std::vector<uint8_t> block_data;
2215-
if (!m_chainman.m_blockman.ReadRawBlockFromDisk(block_data, pindex->GetBlockPos(), m_chainparams.MessageStart())) {
2215+
if (!m_chainman.m_blockman.ReadRawBlockFromDisk(block_data, pindex->GetBlockPos())) {
22162216
assert(!"cannot load block from disk");
22172217
}
22182218
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::BLOCK, Span{block_data}));

src/node/blockstorage.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ CBlockFileInfo* BlockManager::GetBlockFileInfo(size_t n)
476476
return &m_blockfile_info.at(n);
477477
}
478478

479-
bool BlockManager::UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const uint256& hashBlock, const CMessageHeader::MessageStartChars& messageStart) const
479+
bool BlockManager::UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const uint256& hashBlock) const
480480
{
481481
// Open history file to append
482482
AutoFile fileout{OpenUndoFile(pos)};
@@ -486,7 +486,7 @@ bool BlockManager::UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos
486486

487487
// Write index header
488488
unsigned int nSize = GetSerializeSize(blockundo, CLIENT_VERSION);
489-
fileout << messageStart << nSize;
489+
fileout << GetParams().MessageStart() << nSize;
490490

491491
// Write undo data
492492
long fileOutPos = ftell(fileout.Get());
@@ -708,7 +708,7 @@ bool BlockManager::FindUndoPos(BlockValidationState& state, int nFile, FlatFileP
708708
return true;
709709
}
710710

711-
bool BlockManager::WriteBlockToDisk(const CBlock& block, FlatFilePos& pos, const CMessageHeader::MessageStartChars& messageStart) const
711+
bool BlockManager::WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const
712712
{
713713
// Open history file to append
714714
CAutoFile fileout(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION);
@@ -718,7 +718,7 @@ bool BlockManager::WriteBlockToDisk(const CBlock& block, FlatFilePos& pos, const
718718

719719
// Write index header
720720
unsigned int nSize = GetSerializeSize(block, fileout.GetVersion());
721-
fileout << messageStart << nSize;
721+
fileout << GetParams().MessageStart() << nSize;
722722

723723
// Write block
724724
long fileOutPos = ftell(fileout.Get());
@@ -740,7 +740,7 @@ bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValid
740740
if (!FindUndoPos(state, block.nFile, _pos, ::GetSerializeSize(blockundo, CLIENT_VERSION) + 40)) {
741741
return error("ConnectBlock(): FindUndoPos failed");
742742
}
743-
if (!UndoWriteToDisk(blockundo, _pos, block.pprev->GetBlockHash(), GetParams().MessageStart())) {
743+
if (!UndoWriteToDisk(blockundo, _pos, block.pprev->GetBlockHash())) {
744744
return FatalError(m_opts.notifications, state, "Failed to write undo data");
745745
}
746746
// rev files are written in block height order, whereas blk files are written as blocks come in (often out of order)
@@ -806,7 +806,7 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const CBlockIndex& index) co
806806
return true;
807807
}
808808

809-
bool BlockManager::ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatFilePos& pos, const CMessageHeader::MessageStartChars& message_start) const
809+
bool BlockManager::ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatFilePos& pos) const
810810
{
811811
FlatFilePos hpos = pos;
812812
hpos.nPos -= 8; // Seek back 8 bytes for meta header
@@ -821,10 +821,10 @@ bool BlockManager::ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatF
821821

822822
filein >> blk_start >> blk_size;
823823

824-
if (memcmp(blk_start, message_start, CMessageHeader::MESSAGE_START_SIZE)) {
824+
if (memcmp(blk_start, GetParams().MessageStart(), CMessageHeader::MESSAGE_START_SIZE)) {
825825
return error("%s: Block magic mismatch for %s: %s versus expected %s", __func__, pos.ToString(),
826826
HexStr(blk_start),
827-
HexStr(message_start));
827+
HexStr(GetParams().MessageStart()));
828828
}
829829

830830
if (blk_size > MAX_SIZE) {
@@ -859,7 +859,7 @@ FlatFilePos BlockManager::SaveBlockToDisk(const CBlock& block, int nHeight, cons
859859
return FlatFilePos();
860860
}
861861
if (!position_known) {
862-
if (!WriteBlockToDisk(block, blockPos, GetParams().MessageStart())) {
862+
if (!WriteBlockToDisk(block, blockPos)) {
863863
m_opts.notifications.fatalError("Failed to write block");
864864
return FlatFilePos();
865865
}

src/node/blockstorage.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ class BlockManager
101101

102102
FILE* OpenUndoFile(const FlatFilePos& pos, bool fReadOnly = false) const;
103103

104-
bool WriteBlockToDisk(const CBlock& block, FlatFilePos& pos, const CMessageHeader::MessageStartChars& messageStart) const;
105-
bool UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const uint256& hashBlock, const CMessageHeader::MessageStartChars& messageStart) const;
104+
bool WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const;
105+
bool UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const uint256& hashBlock) const;
106106

107107
/* Calculate the block/rev files to delete based on height specified by user with RPC command pruneblockchain */
108108
void FindFilesToPruneManual(std::set<int>& setFilesToPrune, int nManualPruneHeight, int chain_tip_height);
@@ -264,7 +264,7 @@ class BlockManager
264264
/** Functions for disk access for blocks */
265265
bool ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos) const;
266266
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex& index) const;
267-
bool ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatFilePos& pos, const CMessageHeader::MessageStartChars& message_start) const;
267+
bool ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatFilePos& pos) const;
268268

269269
bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex& index) const;
270270

0 commit comments

Comments
 (0)