Skip to content

Commit 02a0899

Browse files
committed
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.
1 parent a498d69 commit 02a0899

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/kernel/blockmanager_opts.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef BITCOIN_KERNEL_BLOCKMANAGER_OPTS_H
66
#define BITCOIN_KERNEL_BLOCKMANAGER_OPTS_H
77

8+
#include <cstdint>
9+
810
class CChainParams;
911

1012
namespace kernel {
@@ -16,6 +18,7 @@ namespace kernel {
1618
struct BlockManagerOpts {
1719
const CChainParams& chainparams;
1820
uint64_t prune_target{0};
21+
bool fast_prune{false};
1922
};
2023

2124
} // namespace kernel

src/node/blockmanager_args.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& args, BlockM
3131
}
3232
opts.prune_target = nPruneTarget;
3333

34+
if (auto value{args.GetBoolArg("-fastprune")}) opts.fast_prune = *value;
35+
3436
return std::nullopt;
3537
}
3638
} // namespace node

src/node/blockstorage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ void BlockManager::UnlinkPrunedFiles(const std::set<int>& setFilesToPrune) const
581581

582582
FlatFileSeq BlockManager::BlockFileSeq() const
583583
{
584-
return FlatFileSeq(gArgs.GetBlocksDirPath(), "blk", gArgs.GetBoolArg("-fastprune", false) ? 0x4000 /* 16kb */ : BLOCKFILE_CHUNK_SIZE);
584+
return FlatFileSeq(gArgs.GetBlocksDirPath(), "blk", m_opts.fast_prune ? 0x4000 /* 16kb */ : BLOCKFILE_CHUNK_SIZE);
585585
}
586586

587587
FlatFileSeq BlockManager::UndoFileSeq() const
@@ -619,7 +619,7 @@ bool BlockManager::FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigne
619619
unsigned int max_blockfile_size{MAX_BLOCKFILE_SIZE};
620620
// Use smaller blockfiles in test-only -fastprune mode - but avoid
621621
// the possibility of having a block not fit into the block file.
622-
if (gArgs.GetBoolArg("-fastprune", false)) {
622+
if (m_opts.fast_prune) {
623623
max_blockfile_size = 0x10000; // 64kiB
624624
if (nAddSize >= max_blockfile_size) {
625625
// dynamically adjust the blockfile size to be larger than the added size

0 commit comments

Comments
 (0)