mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
refactor: Move functions to BlockManager methods
This is a commit in preparation for the next few commits. The functions are moved to methods to avoid their re-declaration for the purpose of passing in BlockManager options. The functions that were now moved into the BlockManager should no longer use the params as an argument, but instead use the member variable. In the moved ReadBlockFromDisk and UndoReadFromDisk, change the function signature to accept a reference to a CBlockIndex instead of a raw pointer. The pointer is expected to be non-null, so reflect that in the type. To allow for the move of functions to BlockManager methods all call sites require an instantiated BlockManager, or a callback to one.
This commit is contained in:
@@ -23,8 +23,6 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
using node::ReadBlockFromDisk;
|
||||
|
||||
constexpr uint8_t DB_BEST_BLOCK{'B'};
|
||||
|
||||
constexpr auto SYNC_LOG_INTERVAL{30s};
|
||||
@@ -159,8 +157,6 @@ void BaseIndex::ThreadSync()
|
||||
SetSyscallSandboxPolicy(SyscallSandboxPolicy::TX_INDEX);
|
||||
const CBlockIndex* pindex = m_best_block_index.load();
|
||||
if (!m_synced) {
|
||||
auto& consensus_params = Params().GetConsensus();
|
||||
|
||||
std::chrono::steady_clock::time_point last_log_time{0s};
|
||||
std::chrono::steady_clock::time_point last_locator_write_time{0s};
|
||||
while (true) {
|
||||
@@ -207,7 +203,7 @@ void BaseIndex::ThreadSync()
|
||||
|
||||
CBlock block;
|
||||
interfaces::BlockInfo block_info = kernel::MakeBlockInfo(pindex);
|
||||
if (!ReadBlockFromDisk(block, pindex, consensus_params)) {
|
||||
if (!m_chainstate->m_blockman.ReadBlockFromDisk(block, *pindex)) {
|
||||
FatalError("%s: Failed to read block %s from disk",
|
||||
__func__, pindex->GetBlockHash().ToString());
|
||||
return;
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
#include <util/fs_helpers.h>
|
||||
#include <validation.h>
|
||||
|
||||
using node::UndoReadFromDisk;
|
||||
|
||||
/* The index database stores three items for each block: the disk location of the encoded filter,
|
||||
* its dSHA256 hash, and the header. Those belonging to blocks on the active chain are indexed by
|
||||
* height, and those belonging to blocks that have been reorganized out of the active chain are
|
||||
@@ -223,7 +221,7 @@ bool BlockFilterIndex::CustomAppend(const interfaces::BlockInfo& block)
|
||||
// pindex variable gives indexing code access to node internals. It
|
||||
// will be removed in upcoming commit
|
||||
const CBlockIndex* pindex = WITH_LOCK(cs_main, return m_chainstate->m_blockman.LookupBlockIndex(block.hash));
|
||||
if (!UndoReadFromDisk(block_undo, pindex)) {
|
||||
if (!m_chainstate->m_blockman.UndoReadFromDisk(block_undo, *pindex)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,6 @@ using kernel::CCoinsStats;
|
||||
using kernel::GetBogoSize;
|
||||
using kernel::TxOutSer;
|
||||
|
||||
using node::ReadBlockFromDisk;
|
||||
using node::UndoReadFromDisk;
|
||||
|
||||
static constexpr uint8_t DB_BLOCK_HASH{'s'};
|
||||
static constexpr uint8_t DB_BLOCK_HEIGHT{'t'};
|
||||
static constexpr uint8_t DB_MUHASH{'M'};
|
||||
@@ -125,7 +122,7 @@ bool CoinStatsIndex::CustomAppend(const interfaces::BlockInfo& block)
|
||||
// pindex variable gives indexing code access to node internals. It
|
||||
// will be removed in upcoming commit
|
||||
const CBlockIndex* pindex = WITH_LOCK(cs_main, return m_chainstate->m_blockman.LookupBlockIndex(block.hash));
|
||||
if (!UndoReadFromDisk(block_undo, pindex)) {
|
||||
if (!m_chainstate->m_blockman.UndoReadFromDisk(block_undo, *pindex)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -282,12 +279,11 @@ bool CoinStatsIndex::CustomRewind(const interfaces::BlockKey& current_tip, const
|
||||
LOCK(cs_main);
|
||||
const CBlockIndex* iter_tip{m_chainstate->m_blockman.LookupBlockIndex(current_tip.hash)};
|
||||
const CBlockIndex* new_tip_index{m_chainstate->m_blockman.LookupBlockIndex(new_tip.hash)};
|
||||
const auto& consensus_params{Params().GetConsensus()};
|
||||
|
||||
do {
|
||||
CBlock block;
|
||||
|
||||
if (!ReadBlockFromDisk(block, iter_tip, consensus_params)) {
|
||||
if (!m_chainstate->m_blockman.ReadBlockFromDisk(block, *iter_tip)) {
|
||||
return error("%s: Failed to read block %s from disk",
|
||||
__func__, iter_tip->GetBlockHash().ToString());
|
||||
}
|
||||
@@ -409,7 +405,7 @@ bool CoinStatsIndex::ReverseBlock(const CBlock& block, const CBlockIndex* pindex
|
||||
|
||||
// Ignore genesis block
|
||||
if (pindex->nHeight > 0) {
|
||||
if (!UndoReadFromDisk(block_undo, pindex)) {
|
||||
if (!m_chainstate->m_blockman.UndoReadFromDisk(block_undo, *pindex)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
#include <node/blockstorage.h>
|
||||
#include <validation.h>
|
||||
|
||||
using node::OpenBlockFile;
|
||||
|
||||
constexpr uint8_t DB_TXINDEX{'t'};
|
||||
|
||||
std::unique_ptr<TxIndex> g_txindex;
|
||||
@@ -80,7 +78,7 @@ bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRe
|
||||
return false;
|
||||
}
|
||||
|
||||
CAutoFile file(OpenBlockFile(postx, true), SER_DISK, CLIENT_VERSION);
|
||||
CAutoFile file(m_chainstate->m_blockman.OpenBlockFile(postx, true), SER_DISK, CLIENT_VERSION);
|
||||
if (file.IsNull()) {
|
||||
return error("%s: OpenBlockFile failed", __func__);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user