From 02a0899527ba3d31329e56c791c9dbf36075bb84 Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Sat, 18 Feb 2023 12:57:39 +0100 Subject: refactor, BlockManager: Replace fastprune from arg with options Remove access to the global gArgs for the fastprune argument and replace it by adding a field to the existing BlockManager Options struct. When running `clang-tidy-diff` on this commit, there is a diagnostic error: `unknown type name 'uint64_t' [clang-diagnostic-error] uint64_t prune_target{0};`, which is fixed by including cstdint. This should eventually allow users of the BlockManager to not rely on the global gArgs and instead pass in their own options. --- src/node/blockmanager_args.cpp | 2 ++ src/node/blockstorage.cpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src/node') diff --git a/src/node/blockmanager_args.cpp b/src/node/blockmanager_args.cpp index 9c320243e1..179c3a4604 100644 --- a/src/node/blockmanager_args.cpp +++ b/src/node/blockmanager_args.cpp @@ -31,6 +31,8 @@ std::optional ApplyArgsManOptions(const ArgsManager& args, BlockM } opts.prune_target = nPruneTarget; + if (auto value{args.GetBoolArg("-fastprune")}) opts.fast_prune = *value; + return std::nullopt; } } // namespace node diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index 7fc61444e5..a6758b8fc9 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -581,7 +581,7 @@ void BlockManager::UnlinkPrunedFiles(const std::set& setFilesToPrune) const FlatFileSeq BlockManager::BlockFileSeq() const { - return FlatFileSeq(gArgs.GetBlocksDirPath(), "blk", gArgs.GetBoolArg("-fastprune", false) ? 0x4000 /* 16kb */ : BLOCKFILE_CHUNK_SIZE); + return FlatFileSeq(gArgs.GetBlocksDirPath(), "blk", m_opts.fast_prune ? 0x4000 /* 16kb */ : BLOCKFILE_CHUNK_SIZE); } FlatFileSeq BlockManager::UndoFileSeq() const @@ -619,7 +619,7 @@ bool BlockManager::FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigne unsigned int max_blockfile_size{MAX_BLOCKFILE_SIZE}; // Use smaller blockfiles in test-only -fastprune mode - but avoid // the possibility of having a block not fit into the block file. - if (gArgs.GetBoolArg("-fastprune", false)) { + if (m_opts.fast_prune) { max_blockfile_size = 0x10000; // 64kiB if (nAddSize >= max_blockfile_size) { // dynamically adjust the blockfile size to be larger than the added size -- cgit v1.2.3