refactor, validation: Add ChainstateManagerOpts db options

Use ChainstateManagerOpts struct to remove ArgsManager uses from validation.cpp.

This commit does not change behavior.
This commit is contained in:
Ryan Ofsky 2022-08-16 23:32:55 -04:00
parent 0352258148
commit aadd7c5b9b
8 changed files with 23 additions and 9 deletions

View file

@ -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};

View file

@ -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

View file

@ -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

View file

@ -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);

View file

@ -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

View file

@ -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,
};

View file

@ -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

View file

@ -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)