0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-03 09:56:38 -05:00

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.
This commit is contained in:
TheCharlatan 2023-02-18 12:57:39 +01:00
parent a498d699e3
commit 02a0899527
No known key found for this signature in database
GPG key ID: 9B79B45691DB4173
3 changed files with 7 additions and 2 deletions

View file

@ -5,6 +5,8 @@
#ifndef BITCOIN_KERNEL_BLOCKMANAGER_OPTS_H #ifndef BITCOIN_KERNEL_BLOCKMANAGER_OPTS_H
#define BITCOIN_KERNEL_BLOCKMANAGER_OPTS_H #define BITCOIN_KERNEL_BLOCKMANAGER_OPTS_H
#include <cstdint>
class CChainParams; class CChainParams;
namespace kernel { namespace kernel {
@ -16,6 +18,7 @@ namespace kernel {
struct BlockManagerOpts { struct BlockManagerOpts {
const CChainParams& chainparams; const CChainParams& chainparams;
uint64_t prune_target{0}; uint64_t prune_target{0};
bool fast_prune{false};
}; };
} // namespace kernel } // namespace kernel

View file

@ -31,6 +31,8 @@ std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& args, BlockM
} }
opts.prune_target = nPruneTarget; opts.prune_target = nPruneTarget;
if (auto value{args.GetBoolArg("-fastprune")}) opts.fast_prune = *value;
return std::nullopt; return std::nullopt;
} }
} // namespace node } // namespace node

View file

@ -581,7 +581,7 @@ void BlockManager::UnlinkPrunedFiles(const std::set<int>& setFilesToPrune) const
FlatFileSeq BlockManager::BlockFileSeq() 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 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}; unsigned int max_blockfile_size{MAX_BLOCKFILE_SIZE};
// Use smaller blockfiles in test-only -fastprune mode - but avoid // Use smaller blockfiles in test-only -fastprune mode - but avoid
// the possibility of having a block not fit into the block file. // 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 max_blockfile_size = 0x10000; // 64kiB
if (nAddSize >= max_blockfile_size) { if (nAddSize >= max_blockfile_size) {
// dynamically adjust the blockfile size to be larger than the added size // dynamically adjust the blockfile size to be larger than the added size