diff options
author | Ryan Ofsky <ryan@ofsky.org> | 2022-08-16 23:32:55 -0400 |
---|---|---|
committer | Ryan Ofsky <ryan@ofsky.org> | 2023-02-10 04:39:11 -0400 |
commit | aadd7c5b9b43a38beaa954b4cb8c2fff55f2200f (patch) | |
tree | ce5985441ccca16a902830c7e1472ad58d86a197 | |
parent | 0352258148c51572426666d337c7b28d0033376c (diff) | |
download | bitcoin-aadd7c5b9b43a38beaa954b4cb8c2fff55f2200f.tar.xz |
refactor, validation: Add ChainstateManagerOpts db options
Use ChainstateManagerOpts struct to remove ArgsManager uses from validation.cpp.
This commit does not change behavior.
-rw-r--r-- | src/bitcoin-chainstate.cpp | 1 | ||||
-rw-r--r-- | src/init.cpp | 2 | ||||
-rw-r--r-- | src/kernel/chainstatemanager_opts.h | 6 | ||||
-rw-r--r-- | src/node/chainstate.cpp | 6 | ||||
-rw-r--r-- | src/node/chainstatemanager_args.cpp | 7 | ||||
-rw-r--r-- | src/test/util/setup_common.cpp | 1 | ||||
-rw-r--r-- | src/test/validation_chainstatemanager_tests.cpp | 1 | ||||
-rw-r--r-- | src/validation.cpp | 8 |
8 files changed, 23 insertions, 9 deletions
diff --git a/src/bitcoin-chainstate.cpp b/src/bitcoin-chainstate.cpp index d972b71a65..423fa79c6f 100644 --- a/src/bitcoin-chainstate.cpp +++ b/src/bitcoin-chainstate.cpp @@ -82,6 +82,7 @@ int main(int argc, char* argv[]) // SETUP: Chainstate const ChainstateManager::Options chainman_opts{ .chainparams = chainparams, + .datadir = gArgs.GetDataDirNet(), .adjusted_time_callback = NodeClock::now, }; ChainstateManager chainman{chainman_opts}; diff --git a/src/init.cpp b/src/init.cpp index 73ae36e4f7..49040c6f63 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1046,6 +1046,7 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb { ChainstateManager::Options chainman_opts_dummy{ .chainparams = chainparams, + .datadir = args.GetDataDirNet(), }; if (const auto error{ApplyArgsManOptions(args, chainman_opts_dummy)}) { return InitError(*error); @@ -1444,6 +1445,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) bool fReindexChainState = args.GetBoolArg("-reindex-chainstate", false); ChainstateManager::Options chainman_opts{ .chainparams = chainparams, + .datadir = args.GetDataDirNet(), .adjusted_time_callback = GetAdjustedTime, }; Assert(!ApplyArgsManOptions(args, chainman_opts)); // no error can happen, already checked in AppInitParameterInteraction diff --git a/src/kernel/chainstatemanager_opts.h b/src/kernel/chainstatemanager_opts.h index 226bb6031e..2395f60164 100644 --- a/src/kernel/chainstatemanager_opts.h +++ b/src/kernel/chainstatemanager_opts.h @@ -6,6 +6,8 @@ #define BITCOIN_KERNEL_CHAINSTATEMANAGER_OPTS_H #include <arith_uint256.h> +#include <dbwrapper.h> +#include <txdb.h> #include <uint256.h> #include <util/time.h> @@ -27,6 +29,7 @@ namespace kernel { */ struct ChainstateManagerOpts { const CChainParams& chainparams; + fs::path datadir; const std::function<NodeClock::time_point()> adjusted_time_callback{nullptr}; std::optional<bool> check_block_index{}; bool checkpoints_enabled{DEFAULT_CHECKPOINTS_ENABLED}; @@ -36,6 +39,9 @@ struct ChainstateManagerOpts { std::optional<uint256> assumed_valid_block{}; //! If the tip is older than this, the node is considered to be in initial block download. std::chrono::seconds max_tip_age{DEFAULT_MAX_TIP_AGE}; + DBOptions block_tree_db{}; + DBOptions coins_db{}; + CoinsViewOptions coins_view{}; }; } // namespace kernel diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp index fa521a9e03..4741c4c421 100644 --- a/src/node/chainstate.cpp +++ b/src/node/chainstate.cpp @@ -10,14 +10,12 @@ #include <consensus/params.h> #include <logging.h> #include <node/blockstorage.h> -#include <node/database_args.h> #include <node/caches.h> #include <sync.h> #include <threadsafety.h> #include <tinyformat.h> #include <txdb.h> #include <uint256.h> -#include <util/system.h> #include <util/time.h> #include <util/translation.h> #include <validation.h> @@ -67,11 +65,11 @@ ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSize // fails if it's still open from the previous loop. Close it first: pblocktree.reset(); pblocktree = std::make_unique<CBlockTreeDB>(DBParams{ - .path = gArgs.GetDataDirNet() / "blocks" / "index", + .path = chainman.m_options.datadir / "blocks" / "index", .cache_bytes = static_cast<size_t>(cache_sizes.block_tree_db), .memory_only = options.block_tree_db_in_memory, .wipe_data = options.reindex, - .options = [] { DBOptions options; node::ReadDatabaseArgs(gArgs, options); return options; }()}); + .options = chainman.m_options.block_tree_db}); if (options.reindex) { pblocktree->WriteReindexing(true); diff --git a/src/node/chainstatemanager_args.cpp b/src/node/chainstatemanager_args.cpp index b0d929626b..9801e6e959 100644 --- a/src/node/chainstatemanager_args.cpp +++ b/src/node/chainstatemanager_args.cpp @@ -5,6 +5,9 @@ #include <node/chainstatemanager_args.h> #include <arith_uint256.h> +#include <kernel/chainstatemanager_opts.h> +#include <node/coins_view_args.h> +#include <node/database_args.h> #include <tinyformat.h> #include <uint256.h> #include <util/strencodings.h> @@ -34,6 +37,10 @@ std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& args, Chains if (auto value{args.GetIntArg("-maxtipage")}) opts.max_tip_age = std::chrono::seconds{*value}; + ReadDatabaseArgs(args, opts.block_tree_db); + ReadDatabaseArgs(args, opts.coins_db); + ReadCoinsViewArgs(args, opts.coins_view); + return std::nullopt; } } // namespace node diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index 2318380c6e..1fc8a02975 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -180,6 +180,7 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve const ChainstateManager::Options chainman_opts{ .chainparams = chainparams, + .datadir = m_args.GetDataDirNet(), .adjusted_time_callback = GetAdjustedTime, .check_block_index = true, }; diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp index 56867a584b..63523d3e2e 100644 --- a/src/test/validation_chainstatemanager_tests.cpp +++ b/src/test/validation_chainstatemanager_tests.cpp @@ -374,6 +374,7 @@ struct SnapshotTestSetup : TestChain100Setup { BOOST_CHECK_EQUAL(chainman.GetAll().size(), 0); const ChainstateManager::Options chainman_opts{ .chainparams = ::Params(), + .datadir = m_args.GetDataDirNet(), .adjusted_time_callback = GetAdjustedTime, }; // For robustness, ensure the old manager is destroyed before creating a diff --git a/src/validation.cpp b/src/validation.cpp index 971eb346a4..c839647b29 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -28,8 +28,6 @@ #include <node/blockstorage.h> #include <node/interface_ui.h> #include <node/utxo_snapshot.h> -#include <node/coins_view_args.h> -#include <node/database_args.h> #include <policy/policy.h> #include <policy/rbf.h> #include <policy/settings.h> @@ -1545,13 +1543,13 @@ void Chainstate::InitCoinsDB( m_coins_views = std::make_unique<CoinsViews>( DBParams{ - .path = gArgs.GetDataDirNet() / leveldb_name, + .path = m_chainman.m_options.datadir / leveldb_name, .cache_bytes = cache_size_bytes, .memory_only = in_memory, .wipe_data = should_wipe, .obfuscate = true, - .options = [] { DBOptions options; node::ReadDatabaseArgs(gArgs, options); return options; }()}, - [] { CoinsViewOptions options; node::ReadCoinsViewArgs(gArgs, options); return options; }()); + .options = m_chainman.m_options.coins_db}, + m_chainman.m_options.coins_view); } void Chainstate::InitCoinsCache(size_t cache_size_bytes) |