aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheCharlatan <seb.kung@gmail.com>2023-02-19 10:20:34 +0100
committerTheCharlatan <seb.kung@gmail.com>2023-05-10 19:07:46 +0200
commit5ff63a09a9edd1204b2cc56cf6f48a44adab7bb3 (patch)
tree6b13bc7b2b3c10e6761b2bd6cc83a687fe020808
parent18e5ba7c8002bcd473ee29ce4b5bfc56df6142a4 (diff)
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.
-rw-r--r--src/init.cpp4
-rw-r--r--src/kernel/blockmanager_opts.h3
-rw-r--r--src/node/blockmanager_args.cpp1
-rw-r--r--src/node/blockstorage.cpp5
-rw-r--r--src/node/blockstorage.h6
5 files changed, 11 insertions, 8 deletions
diff --git a/src/init.cpp b/src/init.cpp
index fc9736db61..52c5780ed4 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -112,6 +112,7 @@
#include <zmq/zmqrpc.h>
#endif
+using kernel::DEFAULT_STOPAFTERBLOCKIMPORT;
using kernel::DumpMempool;
using kernel::ValidationCacheSizes;
@@ -121,7 +122,6 @@ 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;
@@ -1680,7 +1680,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
}
chainman.m_load_block = std::thread(&util::TraceThread, "loadblk", [=, &chainman, &args] {
- ThreadImport(chainman, vImportFiles, args, ShouldPersistMempool(args) ? MempoolPath(args) : fs::path{});
+ ThreadImport(chainman, vImportFiles, ShouldPersistMempool(args) ? MempoolPath(args) : fs::path{});
});
// Wait for genesis block to be processed
diff --git a/src/kernel/blockmanager_opts.h b/src/kernel/blockmanager_opts.h
index 608a852836..8f26422f72 100644
--- a/src/kernel/blockmanager_opts.h
+++ b/src/kernel/blockmanager_opts.h
@@ -13,6 +13,8 @@ class CChainParams;
namespace kernel {
+static constexpr bool DEFAULT_STOPAFTERBLOCKIMPORT{false};
+
/**
* An options struct for `BlockManager`, more ergonomically referred to as
* `BlockManager::Options` due to the using-declaration in `BlockManager`.
@@ -21,6 +23,7 @@ struct BlockManagerOpts {
const CChainParams& chainparams;
uint64_t prune_target{0};
bool fast_prune{false};
+ bool stop_after_block_import{DEFAULT_STOPAFTERBLOCKIMPORT};
const fs::path blocks_dir;
};
diff --git a/src/node/blockmanager_args.cpp b/src/node/blockmanager_args.cpp
index 179c3a4604..23b0bd37ab 100644
--- a/src/node/blockmanager_args.cpp
+++ b/src/node/blockmanager_args.cpp
@@ -32,6 +32,7 @@ std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& args, BlockM
opts.prune_target = nPruneTarget;
if (auto value{args.GetBoolArg("-fastprune")}) opts.fast_prune = *value;
+ if (auto value{args.GetBoolArg("-stopafterblockimport")}) opts.stop_after_block_import = *value;
return std::nullopt;
}
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
index 06aa8d6a19..65dac459c5 100644
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -6,7 +6,6 @@
#include <chain.h>
#include <clientversion.h>
-#include <common/args.h>
#include <consensus/validation.h>
#include <flatfile.h>
#include <hash.h>
@@ -867,7 +866,7 @@ public:
}
};
-void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args, const fs::path& mempool_path)
+void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const fs::path& mempool_path)
{
SetSyscallSandboxPolicy(SyscallSandboxPolicy::INITIALIZATION_LOAD_BLOCKS);
ScheduleBatchPriority();
@@ -934,7 +933,7 @@ void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFile
}
}
- if (args.GetBoolArg("-stopafterblockimport", DEFAULT_STOPAFTERBLOCKIMPORT)) {
+ if (chainman.m_blockman.StopAfterBlockImport()) {
LogPrintf("Stopping after block import\n");
StartShutdown();
return;
diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h
index 6be276e1ca..bce071c7df 100644
--- a/src/node/blockstorage.h
+++ b/src/node/blockstorage.h
@@ -20,7 +20,6 @@
#include <unordered_map>
#include <vector>
-class ArgsManager;
class BlockValidationState;
class CBlock;
class CBlockFileInfo;
@@ -36,7 +35,6 @@ struct Params;
}
namespace node {
-static constexpr bool DEFAULT_STOPAFTERBLOCKIMPORT{false};
/** The pre-allocation chunk size for blk?????.dat files (since 0.8) */
static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB
@@ -210,6 +208,8 @@ public:
[[nodiscard]] bool LoadingBlocks() const { return m_importing || fReindex; }
+ [[nodiscard]] bool StopAfterBlockImport() const { return m_opts.stop_after_block_import; }
+
/** Calculate the amount of disk space the block & undo files currently use */
uint64_t CalculateCurrentUsage();
@@ -249,7 +249,7 @@ public:
void CleanupBlockRevFiles() const;
};
-void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args, const fs::path& mempool_path);
+void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const fs::path& mempool_path);
} // namespace node
#endif // BITCOIN_NODE_BLOCKSTORAGE_H