mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
Remove unused chainparams from BlockManager methods
Also, replace pointer with reference while touching the signature.
This commit is contained in:
parent
fa3f74a40e
commit
fa5d7c39eb
4 changed files with 16 additions and 17 deletions
|
@ -253,7 +253,7 @@ CBlockIndex* BlockManager::InsertBlockIndex(const uint256& hash)
|
||||||
return pindex;
|
return pindex;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BlockManager::LoadBlockIndex(const Consensus::Params& consensus_params)
|
bool BlockManager::LoadBlockIndex()
|
||||||
{
|
{
|
||||||
if (!m_block_tree_db->LoadBlockIndexGuts(GetConsensus(), [this](const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return this->InsertBlockIndex(hash); })) {
|
if (!m_block_tree_db->LoadBlockIndexGuts(GetConsensus(), [this](const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return this->InsertBlockIndex(hash); })) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -318,9 +318,9 @@ bool BlockManager::WriteBlockIndexDB()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BlockManager::LoadBlockIndexDB(const Consensus::Params& consensus_params)
|
bool BlockManager::LoadBlockIndexDB()
|
||||||
{
|
{
|
||||||
if (!LoadBlockIndex(consensus_params)) {
|
if (!LoadBlockIndex()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -720,9 +720,8 @@ static bool WriteBlockToDisk(const CBlock& block, FlatFilePos& pos, const CMessa
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex* pindex, const CChainParams& chainparams)
|
bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex& block)
|
||||||
{
|
{
|
||||||
auto& block{*pindex};
|
|
||||||
AssertLockHeld(::cs_main);
|
AssertLockHeld(::cs_main);
|
||||||
// Write undo information to disk
|
// Write undo information to disk
|
||||||
if (block.GetUndoPos().IsNull()) {
|
if (block.GetUndoPos().IsNull()) {
|
||||||
|
@ -830,7 +829,7 @@ bool ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatFilePos& pos, c
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
FlatFilePos BlockManager::SaveBlockToDisk(const CBlock& block, int nHeight, CChain& active_chain, const CChainParams& chainparams, const FlatFilePos* dbp)
|
FlatFilePos BlockManager::SaveBlockToDisk(const CBlock& block, int nHeight, CChain& active_chain, const FlatFilePos* dbp)
|
||||||
{
|
{
|
||||||
unsigned int nBlockSize = ::GetSerializeSize(block, CLIENT_VERSION);
|
unsigned int nBlockSize = ::GetSerializeSize(block, CLIENT_VERSION);
|
||||||
FlatFilePos blockPos;
|
FlatFilePos blockPos;
|
||||||
|
|
|
@ -89,7 +89,7 @@ private:
|
||||||
* per index entry (nStatus, nChainWork, nTimeMax, etc.) as well as peripheral
|
* per index entry (nStatus, nChainWork, nTimeMax, etc.) as well as peripheral
|
||||||
* collections like m_dirty_blockindex.
|
* collections like m_dirty_blockindex.
|
||||||
*/
|
*/
|
||||||
bool LoadBlockIndex(const Consensus::Params& consensus_params)
|
bool LoadBlockIndex()
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
void FlushBlockFile(bool fFinalize = false, bool finalize_undo = false);
|
void FlushBlockFile(bool fFinalize = false, bool finalize_undo = false);
|
||||||
void FlushUndoFile(int block_file, bool finalize = false);
|
void FlushUndoFile(int block_file, bool finalize = false);
|
||||||
|
@ -165,7 +165,7 @@ public:
|
||||||
std::unique_ptr<CBlockTreeDB> m_block_tree_db GUARDED_BY(::cs_main);
|
std::unique_ptr<CBlockTreeDB> m_block_tree_db GUARDED_BY(::cs_main);
|
||||||
|
|
||||||
bool WriteBlockIndexDB() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
bool WriteBlockIndexDB() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||||
bool LoadBlockIndexDB(const Consensus::Params& consensus_params) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
bool LoadBlockIndexDB() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove any pruned block & undo files that are still on disk.
|
* Remove any pruned block & undo files that are still on disk.
|
||||||
|
@ -187,11 +187,11 @@ public:
|
||||||
/** Get block file info entry for one block file */
|
/** Get block file info entry for one block file */
|
||||||
CBlockFileInfo* GetBlockFileInfo(size_t n);
|
CBlockFileInfo* GetBlockFileInfo(size_t n);
|
||||||
|
|
||||||
bool WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex* pindex, const CChainParams& chainparams)
|
bool WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex& block)
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||||
|
|
||||||
/** Store block on disk. If dbp is not nullptr, then it provides the known position of the block within a block file on disk. */
|
/** Store block on disk. If dbp is not nullptr, then it provides the known position of the block within a block file on disk. */
|
||||||
FlatFilePos SaveBlockToDisk(const CBlock& block, int nHeight, CChain& active_chain, const CChainParams& chainparams, const FlatFilePos* dbp);
|
FlatFilePos SaveBlockToDisk(const CBlock& block, int nHeight, CChain& active_chain, const FlatFilePos* dbp);
|
||||||
|
|
||||||
/** Whether running in -prune mode. */
|
/** Whether running in -prune mode. */
|
||||||
[[nodiscard]] bool IsPruneMode() const { return m_prune_mode; }
|
[[nodiscard]] bool IsPruneMode() const { return m_prune_mode; }
|
||||||
|
|
|
@ -27,20 +27,20 @@ BOOST_AUTO_TEST_CASE(blockmanager_find_block_pos)
|
||||||
BlockManager blockman{blockman_opts};
|
BlockManager blockman{blockman_opts};
|
||||||
CChain chain {};
|
CChain chain {};
|
||||||
// simulate adding a genesis block normally
|
// simulate adding a genesis block normally
|
||||||
BOOST_CHECK_EQUAL(blockman.SaveBlockToDisk(params->GenesisBlock(), 0, chain, *params, nullptr).nPos, BLOCK_SERIALIZATION_HEADER_SIZE);
|
BOOST_CHECK_EQUAL(blockman.SaveBlockToDisk(params->GenesisBlock(), 0, chain, nullptr).nPos, BLOCK_SERIALIZATION_HEADER_SIZE);
|
||||||
// simulate what happens during reindex
|
// simulate what happens during reindex
|
||||||
// simulate a well-formed genesis block being found at offset 8 in the blk00000.dat file
|
// simulate a well-formed genesis block being found at offset 8 in the blk00000.dat file
|
||||||
// the block is found at offset 8 because there is an 8 byte serialization header
|
// the block is found at offset 8 because there is an 8 byte serialization header
|
||||||
// consisting of 4 magic bytes + 4 length bytes before each block in a well-formed blk file.
|
// consisting of 4 magic bytes + 4 length bytes before each block in a well-formed blk file.
|
||||||
FlatFilePos pos{0, BLOCK_SERIALIZATION_HEADER_SIZE};
|
FlatFilePos pos{0, BLOCK_SERIALIZATION_HEADER_SIZE};
|
||||||
BOOST_CHECK_EQUAL(blockman.SaveBlockToDisk(params->GenesisBlock(), 0, chain, *params, &pos).nPos, BLOCK_SERIALIZATION_HEADER_SIZE);
|
BOOST_CHECK_EQUAL(blockman.SaveBlockToDisk(params->GenesisBlock(), 0, chain, &pos).nPos, BLOCK_SERIALIZATION_HEADER_SIZE);
|
||||||
// now simulate what happens after reindex for the first new block processed
|
// now simulate what happens after reindex for the first new block processed
|
||||||
// the actual block contents don't matter, just that it's a block.
|
// the actual block contents don't matter, just that it's a block.
|
||||||
// verify that the write position is at offset 0x12d.
|
// verify that the write position is at offset 0x12d.
|
||||||
// this is a check to make sure that https://github.com/bitcoin/bitcoin/issues/21379 does not recur
|
// this is a check to make sure that https://github.com/bitcoin/bitcoin/issues/21379 does not recur
|
||||||
// 8 bytes (for serialization header) + 285 (for serialized genesis block) = 293
|
// 8 bytes (for serialization header) + 285 (for serialized genesis block) = 293
|
||||||
// add another 8 bytes for the second block's serialization header and we get 293 + 8 = 301
|
// add another 8 bytes for the second block's serialization header and we get 293 + 8 = 301
|
||||||
FlatFilePos actual{blockman.SaveBlockToDisk(params->GenesisBlock(), 1, chain, *params, nullptr)};
|
FlatFilePos actual{blockman.SaveBlockToDisk(params->GenesisBlock(), 1, chain, nullptr)};
|
||||||
BOOST_CHECK_EQUAL(actual.nPos, BLOCK_SERIALIZATION_HEADER_SIZE + ::GetSerializeSize(params->GenesisBlock(), CLIENT_VERSION) + BLOCK_SERIALIZATION_HEADER_SIZE);
|
BOOST_CHECK_EQUAL(actual.nPos, BLOCK_SERIALIZATION_HEADER_SIZE + ::GetSerializeSize(params->GenesisBlock(), CLIENT_VERSION) + BLOCK_SERIALIZATION_HEADER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2374,7 +2374,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
||||||
if (fJustCheck)
|
if (fJustCheck)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!m_blockman.WriteUndoDataForBlock(blockundo, state, pindex, params)) {
|
if (!m_blockman.WriteUndoDataForBlock(blockundo, state, *pindex)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4000,7 +4000,7 @@ bool Chainstate::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, BlockV
|
||||||
// Write block to history file
|
// Write block to history file
|
||||||
if (fNewBlock) *fNewBlock = true;
|
if (fNewBlock) *fNewBlock = true;
|
||||||
try {
|
try {
|
||||||
FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, pindex->nHeight, m_chain, params, dbp)};
|
FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, pindex->nHeight, m_chain, dbp)};
|
||||||
if (blockPos.IsNull()) {
|
if (blockPos.IsNull()) {
|
||||||
state.Error(strprintf("%s: Failed to find position to write new block to disk", __func__));
|
state.Error(strprintf("%s: Failed to find position to write new block to disk", __func__));
|
||||||
return false;
|
return false;
|
||||||
|
@ -4418,7 +4418,7 @@ bool ChainstateManager::LoadBlockIndex()
|
||||||
// Load block index from databases
|
// Load block index from databases
|
||||||
bool needs_init = fReindex;
|
bool needs_init = fReindex;
|
||||||
if (!fReindex) {
|
if (!fReindex) {
|
||||||
bool ret = m_blockman.LoadBlockIndexDB(GetConsensus());
|
bool ret{m_blockman.LoadBlockIndexDB()};
|
||||||
if (!ret) return false;
|
if (!ret) return false;
|
||||||
|
|
||||||
m_blockman.ScanAndUnlinkAlreadyPrunedFiles();
|
m_blockman.ScanAndUnlinkAlreadyPrunedFiles();
|
||||||
|
@ -4522,7 +4522,7 @@ bool Chainstate::LoadGenesisBlock()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const CBlock& block = params.GenesisBlock();
|
const CBlock& block = params.GenesisBlock();
|
||||||
FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, 0, m_chain, params, nullptr)};
|
FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, 0, m_chain, nullptr)};
|
||||||
if (blockPos.IsNull()) {
|
if (blockPos.IsNull()) {
|
||||||
return error("%s: writing genesis block to disk failed", __func__);
|
return error("%s: writing genesis block to disk failed", __func__);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue