Skip to content

Commit 5ff63a0

Browse files
committed
refactor, blockstorage: Replace stopafterblockimport arg
Add a stop_after_block_import field to the BlockManager options. Use this field instead of the global gArgs. This should allow users of the BlockManager to not rely on the global Args.
1 parent 18e5ba7 commit 5ff63a0

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

src/init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
#include <zmq/zmqrpc.h>
113113
#endif
114114

115+
using kernel::DEFAULT_STOPAFTERBLOCKIMPORT;
115116
using kernel::DumpMempool;
116117
using kernel::ValidationCacheSizes;
117118

@@ -121,7 +122,6 @@ using node::CacheSizes;
121122
using node::CalculateCacheSizes;
122123
using node::DEFAULT_PERSIST_MEMPOOL;
123124
using node::DEFAULT_PRINTPRIORITY;
124-
using node::DEFAULT_STOPAFTERBLOCKIMPORT;
125125
using node::fReindex;
126126
using node::LoadChainstate;
127127
using node::MempoolPath;
@@ -1680,7 +1680,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
16801680
}
16811681

16821682
chainman.m_load_block = std::thread(&util::TraceThread, "loadblk", [=, &chainman, &args] {
1683-
ThreadImport(chainman, vImportFiles, args, ShouldPersistMempool(args) ? MempoolPath(args) : fs::path{});
1683+
ThreadImport(chainman, vImportFiles, ShouldPersistMempool(args) ? MempoolPath(args) : fs::path{});
16841684
});
16851685

16861686
// Wait for genesis block to be processed

src/kernel/blockmanager_opts.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class CChainParams;
1313

1414
namespace kernel {
1515

16+
static constexpr bool DEFAULT_STOPAFTERBLOCKIMPORT{false};
17+
1618
/**
1719
* An options struct for `BlockManager`, more ergonomically referred to as
1820
* `BlockManager::Options` due to the using-declaration in `BlockManager`.
@@ -21,6 +23,7 @@ struct BlockManagerOpts {
2123
const CChainParams& chainparams;
2224
uint64_t prune_target{0};
2325
bool fast_prune{false};
26+
bool stop_after_block_import{DEFAULT_STOPAFTERBLOCKIMPORT};
2427
const fs::path blocks_dir;
2528
};
2629

src/node/blockmanager_args.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& args, BlockM
3232
opts.prune_target = nPruneTarget;
3333

3434
if (auto value{args.GetBoolArg("-fastprune")}) opts.fast_prune = *value;
35+
if (auto value{args.GetBoolArg("-stopafterblockimport")}) opts.stop_after_block_import = *value;
3536

3637
return std::nullopt;
3738
}

src/node/blockstorage.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include <chain.h>
88
#include <clientversion.h>
9-
#include <common/args.h>
109
#include <consensus/validation.h>
1110
#include <flatfile.h>
1211
#include <hash.h>
@@ -867,7 +866,7 @@ class ImportingNow
867866
}
868867
};
869868

870-
void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args, const fs::path& mempool_path)
869+
void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const fs::path& mempool_path)
871870
{
872871
SetSyscallSandboxPolicy(SyscallSandboxPolicy::INITIALIZATION_LOAD_BLOCKS);
873872
ScheduleBatchPriority();
@@ -934,7 +933,7 @@ void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFile
934933
}
935934
}
936935

937-
if (args.GetBoolArg("-stopafterblockimport", DEFAULT_STOPAFTERBLOCKIMPORT)) {
936+
if (chainman.m_blockman.StopAfterBlockImport()) {
938937
LogPrintf("Stopping after block import\n");
939938
StartShutdown();
940939
return;

src/node/blockstorage.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <unordered_map>
2121
#include <vector>
2222

23-
class ArgsManager;
2423
class BlockValidationState;
2524
class CBlock;
2625
class CBlockFileInfo;
@@ -36,7 +35,6 @@ struct Params;
3635
}
3736

3837
namespace node {
39-
static constexpr bool DEFAULT_STOPAFTERBLOCKIMPORT{false};
4038

4139
/** The pre-allocation chunk size for blk?????.dat files (since 0.8) */
4240
static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB
@@ -210,6 +208,8 @@ class BlockManager
210208

211209
[[nodiscard]] bool LoadingBlocks() const { return m_importing || fReindex; }
212210

211+
[[nodiscard]] bool StopAfterBlockImport() const { return m_opts.stop_after_block_import; }
212+
213213
/** Calculate the amount of disk space the block & undo files currently use */
214214
uint64_t CalculateCurrentUsage();
215215

@@ -249,7 +249,7 @@ class BlockManager
249249
void CleanupBlockRevFiles() const;
250250
};
251251

252-
void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args, const fs::path& mempool_path);
252+
void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const fs::path& mempool_path);
253253
} // namespace node
254254

255255
#endif // BITCOIN_NODE_BLOCKSTORAGE_H

0 commit comments

Comments
 (0)