aboutsummaryrefslogtreecommitdiff
path: root/src/index
diff options
context:
space:
mode:
authorTheCharlatan <seb.kung@gmail.com>2023-02-18 15:49:41 +0100
committerTheCharlatan <seb.kung@gmail.com>2023-05-10 19:06:53 +0200
commitf0bb1021f0d60f5f19176e67a66fcf7c325f88d1 (patch)
tree042a49839ae28506b5de80a32895ddf6812264bb /src/index
parentcfbb2124939822e95265a39242ffca3d86bac6e8 (diff)
downloadbitcoin-f0bb1021f0d60f5f19176e67a66fcf7c325f88d1.tar.xz
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.
Diffstat (limited to 'src/index')
-rw-r--r--src/index/base.cpp6
-rw-r--r--src/index/blockfilterindex.cpp4
-rw-r--r--src/index/coinstatsindex.cpp10
-rw-r--r--src/index/txindex.cpp4
4 files changed, 6 insertions, 18 deletions
diff --git a/src/index/base.cpp b/src/index/base.cpp
index 237c8e8be0..3e05c9b965 100644
--- a/src/index/base.cpp
+++ b/src/index/base.cpp
@@ -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;
diff --git a/src/index/blockfilterindex.cpp b/src/index/blockfilterindex.cpp
index e6300ce3dd..a860b3a94d 100644
--- a/src/index/blockfilterindex.cpp
+++ b/src/index/blockfilterindex.cpp
@@ -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;
}
diff --git a/src/index/coinstatsindex.cpp b/src/index/coinstatsindex.cpp
index 5bc6ad3d31..d80885f842 100644
--- a/src/index/coinstatsindex.cpp
+++ b/src/index/coinstatsindex.cpp
@@ -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;
}
diff --git a/src/index/txindex.cpp b/src/index/txindex.cpp
index 49bddf2d4d..2e07a35d0d 100644
--- a/src/index/txindex.cpp
+++ b/src/index/txindex.cpp
@@ -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__);
}