mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-13 11:25:02 -05:00
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:
parent
0352258148
commit
aadd7c5b9b
8 changed files with 23 additions and 9 deletions
|
@ -82,6 +82,7 @@ int main(int argc, char* argv[])
|
||||||
// SETUP: Chainstate
|
// SETUP: Chainstate
|
||||||
const ChainstateManager::Options chainman_opts{
|
const ChainstateManager::Options chainman_opts{
|
||||||
.chainparams = chainparams,
|
.chainparams = chainparams,
|
||||||
|
.datadir = gArgs.GetDataDirNet(),
|
||||||
.adjusted_time_callback = NodeClock::now,
|
.adjusted_time_callback = NodeClock::now,
|
||||||
};
|
};
|
||||||
ChainstateManager chainman{chainman_opts};
|
ChainstateManager chainman{chainman_opts};
|
||||||
|
|
|
@ -1046,6 +1046,7 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb
|
||||||
{
|
{
|
||||||
ChainstateManager::Options chainman_opts_dummy{
|
ChainstateManager::Options chainman_opts_dummy{
|
||||||
.chainparams = chainparams,
|
.chainparams = chainparams,
|
||||||
|
.datadir = args.GetDataDirNet(),
|
||||||
};
|
};
|
||||||
if (const auto error{ApplyArgsManOptions(args, chainman_opts_dummy)}) {
|
if (const auto error{ApplyArgsManOptions(args, chainman_opts_dummy)}) {
|
||||||
return InitError(*error);
|
return InitError(*error);
|
||||||
|
@ -1444,6 +1445,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||||
bool fReindexChainState = args.GetBoolArg("-reindex-chainstate", false);
|
bool fReindexChainState = args.GetBoolArg("-reindex-chainstate", false);
|
||||||
ChainstateManager::Options chainman_opts{
|
ChainstateManager::Options chainman_opts{
|
||||||
.chainparams = chainparams,
|
.chainparams = chainparams,
|
||||||
|
.datadir = args.GetDataDirNet(),
|
||||||
.adjusted_time_callback = GetAdjustedTime,
|
.adjusted_time_callback = GetAdjustedTime,
|
||||||
};
|
};
|
||||||
Assert(!ApplyArgsManOptions(args, chainman_opts)); // no error can happen, already checked in AppInitParameterInteraction
|
Assert(!ApplyArgsManOptions(args, chainman_opts)); // no error can happen, already checked in AppInitParameterInteraction
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#define BITCOIN_KERNEL_CHAINSTATEMANAGER_OPTS_H
|
#define BITCOIN_KERNEL_CHAINSTATEMANAGER_OPTS_H
|
||||||
|
|
||||||
#include <arith_uint256.h>
|
#include <arith_uint256.h>
|
||||||
|
#include <dbwrapper.h>
|
||||||
|
#include <txdb.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
#include <util/time.h>
|
#include <util/time.h>
|
||||||
|
|
||||||
|
@ -27,6 +29,7 @@ namespace kernel {
|
||||||
*/
|
*/
|
||||||
struct ChainstateManagerOpts {
|
struct ChainstateManagerOpts {
|
||||||
const CChainParams& chainparams;
|
const CChainParams& chainparams;
|
||||||
|
fs::path datadir;
|
||||||
const std::function<NodeClock::time_point()> adjusted_time_callback{nullptr};
|
const std::function<NodeClock::time_point()> adjusted_time_callback{nullptr};
|
||||||
std::optional<bool> check_block_index{};
|
std::optional<bool> check_block_index{};
|
||||||
bool checkpoints_enabled{DEFAULT_CHECKPOINTS_ENABLED};
|
bool checkpoints_enabled{DEFAULT_CHECKPOINTS_ENABLED};
|
||||||
|
@ -36,6 +39,9 @@ struct ChainstateManagerOpts {
|
||||||
std::optional<uint256> assumed_valid_block{};
|
std::optional<uint256> assumed_valid_block{};
|
||||||
//! If the tip is older than this, the node is considered to be in initial block download.
|
//! 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};
|
std::chrono::seconds max_tip_age{DEFAULT_MAX_TIP_AGE};
|
||||||
|
DBOptions block_tree_db{};
|
||||||
|
DBOptions coins_db{};
|
||||||
|
CoinsViewOptions coins_view{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace kernel
|
} // namespace kernel
|
||||||
|
|
|
@ -10,14 +10,12 @@
|
||||||
#include <consensus/params.h>
|
#include <consensus/params.h>
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
#include <node/blockstorage.h>
|
#include <node/blockstorage.h>
|
||||||
#include <node/database_args.h>
|
|
||||||
#include <node/caches.h>
|
#include <node/caches.h>
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <threadsafety.h>
|
#include <threadsafety.h>
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
#include <txdb.h>
|
#include <txdb.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
#include <util/system.h>
|
|
||||||
#include <util/time.h>
|
#include <util/time.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <validation.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:
|
// fails if it's still open from the previous loop. Close it first:
|
||||||
pblocktree.reset();
|
pblocktree.reset();
|
||||||
pblocktree = std::make_unique<CBlockTreeDB>(DBParams{
|
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),
|
.cache_bytes = static_cast<size_t>(cache_sizes.block_tree_db),
|
||||||
.memory_only = options.block_tree_db_in_memory,
|
.memory_only = options.block_tree_db_in_memory,
|
||||||
.wipe_data = options.reindex,
|
.wipe_data = options.reindex,
|
||||||
.options = [] { DBOptions options; node::ReadDatabaseArgs(gArgs, options); return options; }()});
|
.options = chainman.m_options.block_tree_db});
|
||||||
|
|
||||||
if (options.reindex) {
|
if (options.reindex) {
|
||||||
pblocktree->WriteReindexing(true);
|
pblocktree->WriteReindexing(true);
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
#include <node/chainstatemanager_args.h>
|
#include <node/chainstatemanager_args.h>
|
||||||
|
|
||||||
#include <arith_uint256.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 <tinyformat.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
#include <util/strencodings.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};
|
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;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
} // namespace node
|
} // namespace node
|
||||||
|
|
|
@ -180,6 +180,7 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve
|
||||||
|
|
||||||
const ChainstateManager::Options chainman_opts{
|
const ChainstateManager::Options chainman_opts{
|
||||||
.chainparams = chainparams,
|
.chainparams = chainparams,
|
||||||
|
.datadir = m_args.GetDataDirNet(),
|
||||||
.adjusted_time_callback = GetAdjustedTime,
|
.adjusted_time_callback = GetAdjustedTime,
|
||||||
.check_block_index = true,
|
.check_block_index = true,
|
||||||
};
|
};
|
||||||
|
|
|
@ -374,6 +374,7 @@ struct SnapshotTestSetup : TestChain100Setup {
|
||||||
BOOST_CHECK_EQUAL(chainman.GetAll().size(), 0);
|
BOOST_CHECK_EQUAL(chainman.GetAll().size(), 0);
|
||||||
const ChainstateManager::Options chainman_opts{
|
const ChainstateManager::Options chainman_opts{
|
||||||
.chainparams = ::Params(),
|
.chainparams = ::Params(),
|
||||||
|
.datadir = m_args.GetDataDirNet(),
|
||||||
.adjusted_time_callback = GetAdjustedTime,
|
.adjusted_time_callback = GetAdjustedTime,
|
||||||
};
|
};
|
||||||
// For robustness, ensure the old manager is destroyed before creating a
|
// For robustness, ensure the old manager is destroyed before creating a
|
||||||
|
|
|
@ -28,8 +28,6 @@
|
||||||
#include <node/blockstorage.h>
|
#include <node/blockstorage.h>
|
||||||
#include <node/interface_ui.h>
|
#include <node/interface_ui.h>
|
||||||
#include <node/utxo_snapshot.h>
|
#include <node/utxo_snapshot.h>
|
||||||
#include <node/coins_view_args.h>
|
|
||||||
#include <node/database_args.h>
|
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
#include <policy/rbf.h>
|
#include <policy/rbf.h>
|
||||||
#include <policy/settings.h>
|
#include <policy/settings.h>
|
||||||
|
@ -1545,13 +1543,13 @@ void Chainstate::InitCoinsDB(
|
||||||
|
|
||||||
m_coins_views = std::make_unique<CoinsViews>(
|
m_coins_views = std::make_unique<CoinsViews>(
|
||||||
DBParams{
|
DBParams{
|
||||||
.path = gArgs.GetDataDirNet() / leveldb_name,
|
.path = m_chainman.m_options.datadir / leveldb_name,
|
||||||
.cache_bytes = cache_size_bytes,
|
.cache_bytes = cache_size_bytes,
|
||||||
.memory_only = in_memory,
|
.memory_only = in_memory,
|
||||||
.wipe_data = should_wipe,
|
.wipe_data = should_wipe,
|
||||||
.obfuscate = true,
|
.obfuscate = true,
|
||||||
.options = [] { DBOptions options; node::ReadDatabaseArgs(gArgs, options); return options; }()},
|
.options = m_chainman.m_options.coins_db},
|
||||||
[] { CoinsViewOptions options; node::ReadCoinsViewArgs(gArgs, options); return options; }());
|
m_chainman.m_options.coins_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Chainstate::InitCoinsCache(size_t cache_size_bytes)
|
void Chainstate::InitCoinsCache(size_t cache_size_bytes)
|
||||||
|
|
Loading…
Add table
Reference in a new issue