aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTheCharlatan <seb.kung@gmail.com>2023-02-18 18:17:33 +0100
committerTheCharlatan <seb.kung@gmail.com>2023-05-10 19:07:44 +0200
commit18e5ba7c8002bcd473ee29ce4b5bfc56df6142a4 (patch)
treecf11cb6570d968c9cb921df20786277716d6a22c /src
parent02a0899527ba3d31329e56c791c9dbf36075bb84 (diff)
refactor, blockstorage: Replace blocksdir arg
Add a blocks_dir field to the BlockManager options. Move functions relying on the global gArgs to get the blocks_dir into the BlockManager class. This should eventually allow users of the BlockManager to not rely on the global Args and instead pass in their own options.
Diffstat (limited to 'src')
-rw-r--r--src/bitcoin-chainstate.cpp1
-rw-r--r--src/init.cpp11
-rw-r--r--src/kernel/blockmanager_opts.h3
-rw-r--r--src/node/blockstorage.cpp7
-rw-r--r--src/test/blockmanager_tests.cpp3
-rw-r--r--src/test/util/setup_common.cpp4
-rw-r--r--src/test/validation_chainstatemanager_tests.cpp4
7 files changed, 22 insertions, 11 deletions
diff --git a/src/bitcoin-chainstate.cpp b/src/bitcoin-chainstate.cpp
index 52e697a78d..16c3bfb708 100644
--- a/src/bitcoin-chainstate.cpp
+++ b/src/bitcoin-chainstate.cpp
@@ -89,6 +89,7 @@ int main(int argc, char* argv[])
};
const node::BlockManager::Options blockman_opts{
.chainparams = chainman_opts.chainparams,
+ .blocks_dir = gArgs.GetBlocksDirPath(),
};
ChainstateManager chainman{chainman_opts, blockman_opts};
diff --git a/src/init.cpp b/src/init.cpp
index 948cf0414b..fc9736db61 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -116,18 +116,19 @@ using kernel::DumpMempool;
using kernel::ValidationCacheSizes;
using node::ApplyArgsManOptions;
+using node::BlockManager;
using node::CacheSizes;
using node::CalculateCacheSizes;
using node::DEFAULT_PERSIST_MEMPOOL;
using node::DEFAULT_PRINTPRIORITY;
using node::DEFAULT_STOPAFTERBLOCKIMPORT;
+using node::fReindex;
using node::LoadChainstate;
using node::MempoolPath;
-using node::ShouldPersistMempool;
using node::NodeContext;
+using node::ShouldPersistMempool;
using node::ThreadImport;
using node::VerifyLoadedChainstate;
-using node::fReindex;
static constexpr bool DEFAULT_PROXYRANDOMIZE{true};
static constexpr bool DEFAULT_REST_ENABLE{false};
@@ -1037,8 +1038,9 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb
if (const auto error{ApplyArgsManOptions(args, chainman_opts_dummy)}) {
return InitError(*error);
}
- node::BlockManager::Options blockman_opts_dummy{
+ BlockManager::Options blockman_opts_dummy{
.chainparams = chainman_opts_dummy.chainparams,
+ .blocks_dir = args.GetBlocksDirPath(),
};
if (const auto error{ApplyArgsManOptions(args, blockman_opts_dummy)}) {
return InitError(*error);
@@ -1446,8 +1448,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
};
Assert(!ApplyArgsManOptions(args, chainman_opts)); // no error can happen, already checked in AppInitParameterInteraction
- node::BlockManager::Options blockman_opts{
+ BlockManager::Options blockman_opts{
.chainparams = chainman_opts.chainparams,
+ .blocks_dir = args.GetBlocksDirPath(),
};
Assert(!ApplyArgsManOptions(args, blockman_opts)); // no error can happen, already checked in AppInitParameterInteraction
diff --git a/src/kernel/blockmanager_opts.h b/src/kernel/blockmanager_opts.h
index 6fa9ddd8c9..608a852836 100644
--- a/src/kernel/blockmanager_opts.h
+++ b/src/kernel/blockmanager_opts.h
@@ -5,6 +5,8 @@
#ifndef BITCOIN_KERNEL_BLOCKMANAGER_OPTS_H
#define BITCOIN_KERNEL_BLOCKMANAGER_OPTS_H
+#include <util/fs.h>
+
#include <cstdint>
class CChainParams;
@@ -19,6 +21,7 @@ struct BlockManagerOpts {
const CChainParams& chainparams;
uint64_t prune_target{0};
bool fast_prune{false};
+ const fs::path blocks_dir;
};
} // namespace kernel
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
index a6758b8fc9..06aa8d6a19 100644
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -427,8 +427,7 @@ void BlockManager::CleanupBlockRevFiles() const
// Remove the rev files immediately and insert the blk file paths into an
// ordered map keyed by block file index.
LogPrintf("Removing unusable blk?????.dat and rev?????.dat files for -reindex with -prune\n");
- const fs::path& blocksdir = gArgs.GetBlocksDirPath();
- for (fs::directory_iterator it(blocksdir); it != fs::directory_iterator(); it++) {
+ for (fs::directory_iterator it(m_opts.blocks_dir); it != fs::directory_iterator(); it++) {
const std::string path = fs::PathToString(it->path().filename());
if (fs::is_regular_file(*it) &&
path.length() == 12 &&
@@ -581,12 +580,12 @@ void BlockManager::UnlinkPrunedFiles(const std::set<int>& setFilesToPrune) const
FlatFileSeq BlockManager::BlockFileSeq() const
{
- return FlatFileSeq(gArgs.GetBlocksDirPath(), "blk", m_opts.fast_prune ? 0x4000 /* 16kb */ : BLOCKFILE_CHUNK_SIZE);
+ return FlatFileSeq(m_opts.blocks_dir, "blk", m_opts.fast_prune ? 0x4000 /* 16kb */ : BLOCKFILE_CHUNK_SIZE);
}
FlatFileSeq BlockManager::UndoFileSeq() const
{
- return FlatFileSeq(gArgs.GetBlocksDirPath(), "rev", UNDOFILE_CHUNK_SIZE);
+ return FlatFileSeq(m_opts.blocks_dir, "rev", UNDOFILE_CHUNK_SIZE);
}
FILE* BlockManager::OpenBlockFile(const FlatFilePos& pos, bool fReadOnly) const
diff --git a/src/test/blockmanager_tests.cpp b/src/test/blockmanager_tests.cpp
index aaad37824a..f094766886 100644
--- a/src/test/blockmanager_tests.cpp
+++ b/src/test/blockmanager_tests.cpp
@@ -21,8 +21,9 @@ BOOST_FIXTURE_TEST_SUITE(blockmanager_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(blockmanager_find_block_pos)
{
const auto params {CreateChainParams(ArgsManager{}, ChainType::MAIN)};
- node::BlockManager::Options blockman_opts{
+ const BlockManager::Options blockman_opts{
.chainparams = *params,
+ .blocks_dir = m_args.GetBlocksDirPath(),
};
BlockManager blockman{blockman_opts};
CChain chain {};
diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp
index 642350b033..62d60d6774 100644
--- a/src/test/util/setup_common.cpp
+++ b/src/test/util/setup_common.cpp
@@ -62,6 +62,7 @@
using kernel::ValidationCacheSizes;
using node::ApplyArgsManOptions;
using node::BlockAssembler;
+using node::BlockManager;
using node::CalculateCacheSizes;
using node::LoadChainstate;
using node::RegenerateCommitments;
@@ -186,8 +187,9 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, const std::vecto
.adjusted_time_callback = GetAdjustedTime,
.check_block_index = true,
};
- node::BlockManager::Options blockman_opts{
+ const BlockManager::Options blockman_opts{
.chainparams = chainman_opts.chainparams,
+ .blocks_dir = m_args.GetBlocksDirPath(),
};
m_node.chainman = std::make_unique<ChainstateManager>(chainman_opts, blockman_opts);
m_node.chainman->m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(DBParams{
diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp
index 85fe065a38..05e2787075 100644
--- a/src/test/validation_chainstatemanager_tests.cpp
+++ b/src/test/validation_chainstatemanager_tests.cpp
@@ -22,6 +22,7 @@
#include <boost/test/unit_test.hpp>
+using node::BlockManager;
using node::SnapshotMetadata;
BOOST_FIXTURE_TEST_SUITE(validation_chainstatemanager_tests, ChainTestingSetup)
@@ -381,8 +382,9 @@ struct SnapshotTestSetup : TestChain100Setup {
.datadir = m_args.GetDataDirNet(),
.adjusted_time_callback = GetAdjustedTime,
};
- node::BlockManager::Options blockman_opts{
+ const BlockManager::Options blockman_opts{
.chainparams = chainman_opts.chainparams,
+ .blocks_dir = m_args.GetBlocksDirPath(),
};
// For robustness, ensure the old manager is destroyed before creating a
// new one.