Skip to content

Commit fa5d7c3

Browse files
author
MarcoFalke
committed
Remove unused chainparams from BlockManager methods
Also, replace pointer with reference while touching the signature.
1 parent fa3f74a commit fa5d7c3

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

src/node/blockstorage.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ CBlockIndex* BlockManager::InsertBlockIndex(const uint256& hash)
253253
return pindex;
254254
}
255255

256-
bool BlockManager::LoadBlockIndex(const Consensus::Params& consensus_params)
256+
bool BlockManager::LoadBlockIndex()
257257
{
258258
if (!m_block_tree_db->LoadBlockIndexGuts(GetConsensus(), [this](const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return this->InsertBlockIndex(hash); })) {
259259
return false;
@@ -318,9 +318,9 @@ bool BlockManager::WriteBlockIndexDB()
318318
return true;
319319
}
320320

321-
bool BlockManager::LoadBlockIndexDB(const Consensus::Params& consensus_params)
321+
bool BlockManager::LoadBlockIndexDB()
322322
{
323-
if (!LoadBlockIndex(consensus_params)) {
323+
if (!LoadBlockIndex()) {
324324
return false;
325325
}
326326

@@ -720,9 +720,8 @@ static bool WriteBlockToDisk(const CBlock& block, FlatFilePos& pos, const CMessa
720720
return true;
721721
}
722722

723-
bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex* pindex, const CChainParams& chainparams)
723+
bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex& block)
724724
{
725-
auto& block{*pindex};
726725
AssertLockHeld(::cs_main);
727726
// Write undo information to disk
728727
if (block.GetUndoPos().IsNull()) {
@@ -830,7 +829,7 @@ bool ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatFilePos& pos, c
830829
return true;
831830
}
832831

833-
FlatFilePos BlockManager::SaveBlockToDisk(const CBlock& block, int nHeight, CChain& active_chain, const CChainParams& chainparams, const FlatFilePos* dbp)
832+
FlatFilePos BlockManager::SaveBlockToDisk(const CBlock& block, int nHeight, CChain& active_chain, const FlatFilePos* dbp)
834833
{
835834
unsigned int nBlockSize = ::GetSerializeSize(block, CLIENT_VERSION);
836835
FlatFilePos blockPos;

src/node/blockstorage.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class BlockManager
8989
* per index entry (nStatus, nChainWork, nTimeMax, etc.) as well as peripheral
9090
* collections like m_dirty_blockindex.
9191
*/
92-
bool LoadBlockIndex(const Consensus::Params& consensus_params)
92+
bool LoadBlockIndex()
9393
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
9494
void FlushBlockFile(bool fFinalize = false, bool finalize_undo = false);
9595
void FlushUndoFile(int block_file, bool finalize = false);
@@ -165,7 +165,7 @@ class BlockManager
165165
std::unique_ptr<CBlockTreeDB> m_block_tree_db GUARDED_BY(::cs_main);
166166

167167
bool WriteBlockIndexDB() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
168-
bool LoadBlockIndexDB(const Consensus::Params& consensus_params) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
168+
bool LoadBlockIndexDB() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
169169

170170
/**
171171
* Remove any pruned block & undo files that are still on disk.
@@ -187,11 +187,11 @@ class BlockManager
187187
/** Get block file info entry for one block file */
188188
CBlockFileInfo* GetBlockFileInfo(size_t n);
189189

190-
bool WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex* pindex, const CChainParams& chainparams)
190+
bool WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex& block)
191191
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
192192

193193
/** Store block on disk. If dbp is not nullptr, then it provides the known position of the block within a block file on disk. */
194-
FlatFilePos SaveBlockToDisk(const CBlock& block, int nHeight, CChain& active_chain, const CChainParams& chainparams, const FlatFilePos* dbp);
194+
FlatFilePos SaveBlockToDisk(const CBlock& block, int nHeight, CChain& active_chain, const FlatFilePos* dbp);
195195

196196
/** Whether running in -prune mode. */
197197
[[nodiscard]] bool IsPruneMode() const { return m_prune_mode; }

src/test/blockmanager_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ BOOST_AUTO_TEST_CASE(blockmanager_find_block_pos)
2727
BlockManager blockman{blockman_opts};
2828
CChain chain {};
2929
// simulate adding a genesis block normally
30-
BOOST_CHECK_EQUAL(blockman.SaveBlockToDisk(params->GenesisBlock(), 0, chain, *params, nullptr).nPos, BLOCK_SERIALIZATION_HEADER_SIZE);
30+
BOOST_CHECK_EQUAL(blockman.SaveBlockToDisk(params->GenesisBlock(), 0, chain, nullptr).nPos, BLOCK_SERIALIZATION_HEADER_SIZE);
3131
// simulate what happens during reindex
3232
// simulate a well-formed genesis block being found at offset 8 in the blk00000.dat file
3333
// the block is found at offset 8 because there is an 8 byte serialization header
3434
// consisting of 4 magic bytes + 4 length bytes before each block in a well-formed blk file.
3535
FlatFilePos pos{0, BLOCK_SERIALIZATION_HEADER_SIZE};
36-
BOOST_CHECK_EQUAL(blockman.SaveBlockToDisk(params->GenesisBlock(), 0, chain, *params, &pos).nPos, BLOCK_SERIALIZATION_HEADER_SIZE);
36+
BOOST_CHECK_EQUAL(blockman.SaveBlockToDisk(params->GenesisBlock(), 0, chain, &pos).nPos, BLOCK_SERIALIZATION_HEADER_SIZE);
3737
// now simulate what happens after reindex for the first new block processed
3838
// the actual block contents don't matter, just that it's a block.
3939
// verify that the write position is at offset 0x12d.
4040
// this is a check to make sure that https://github.com/bitcoin/bitcoin/issues/21379 does not recur
4141
// 8 bytes (for serialization header) + 285 (for serialized genesis block) = 293
4242
// add another 8 bytes for the second block's serialization header and we get 293 + 8 = 301
43-
FlatFilePos actual{blockman.SaveBlockToDisk(params->GenesisBlock(), 1, chain, *params, nullptr)};
43+
FlatFilePos actual{blockman.SaveBlockToDisk(params->GenesisBlock(), 1, chain, nullptr)};
4444
BOOST_CHECK_EQUAL(actual.nPos, BLOCK_SERIALIZATION_HEADER_SIZE + ::GetSerializeSize(params->GenesisBlock(), CLIENT_VERSION) + BLOCK_SERIALIZATION_HEADER_SIZE);
4545
}
4646

src/validation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,7 +2374,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
23742374
if (fJustCheck)
23752375
return true;
23762376

2377-
if (!m_blockman.WriteUndoDataForBlock(blockundo, state, pindex, params)) {
2377+
if (!m_blockman.WriteUndoDataForBlock(blockundo, state, *pindex)) {
23782378
return false;
23792379
}
23802380

@@ -4000,7 +4000,7 @@ bool Chainstate::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, BlockV
40004000
// Write block to history file
40014001
if (fNewBlock) *fNewBlock = true;
40024002
try {
4003-
FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, pindex->nHeight, m_chain, params, dbp)};
4003+
FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, pindex->nHeight, m_chain, dbp)};
40044004
if (blockPos.IsNull()) {
40054005
state.Error(strprintf("%s: Failed to find position to write new block to disk", __func__));
40064006
return false;
@@ -4418,7 +4418,7 @@ bool ChainstateManager::LoadBlockIndex()
44184418
// Load block index from databases
44194419
bool needs_init = fReindex;
44204420
if (!fReindex) {
4421-
bool ret = m_blockman.LoadBlockIndexDB(GetConsensus());
4421+
bool ret{m_blockman.LoadBlockIndexDB()};
44224422
if (!ret) return false;
44234423

44244424
m_blockman.ScanAndUnlinkAlreadyPrunedFiles();
@@ -4522,7 +4522,7 @@ bool Chainstate::LoadGenesisBlock()
45224522

45234523
try {
45244524
const CBlock& block = params.GenesisBlock();
4525-
FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, 0, m_chain, params, nullptr)};
4525+
FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, 0, m_chain, nullptr)};
45264526
if (blockPos.IsNull()) {
45274527
return error("%s: writing genesis block to disk failed", __func__);
45284528
}

0 commit comments

Comments
 (0)