mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
Add ChainstateManagerOpts, using as ::Options
[META] Although it seems like we don't need it for just one option, we're going to introduce another member to this struct *in the next commit*. In future patchsets for libbitcoinkernel decoupling it from ArgsManager, even more members will be added here.
This commit is contained in:
parent
4d0c00dffd
commit
dbe45c34f8
7 changed files with 45 additions and 6 deletions
|
@ -171,6 +171,7 @@ BITCOIN_CORE_H = \
|
|||
interfaces/ipc.h \
|
||||
interfaces/node.h \
|
||||
interfaces/wallet.h \
|
||||
kernel/chainstatemanager_opts.h \
|
||||
key.h \
|
||||
key_io.h \
|
||||
logging.h \
|
||||
|
|
|
@ -70,7 +70,10 @@ int main(int argc, char* argv[])
|
|||
|
||||
|
||||
// SETUP: Chainstate
|
||||
ChainstateManager chainman{chainparams};
|
||||
const ChainstateManager::Options chainman_opts{
|
||||
chainparams,
|
||||
};
|
||||
ChainstateManager chainman{chainman_opts};
|
||||
|
||||
auto rv = node::LoadChainstate(false,
|
||||
std::ref(chainman),
|
||||
|
|
|
@ -1421,7 +1421,10 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
|||
for (bool fLoaded = false; !fLoaded && !ShutdownRequested();) {
|
||||
node.mempool = std::make_unique<CTxMemPool>(node.fee_estimator.get(), mempool_check_ratio);
|
||||
|
||||
node.chainman = std::make_unique<ChainstateManager>(chainparams);
|
||||
const ChainstateManager::Options chainman_opts{
|
||||
chainparams,
|
||||
};
|
||||
node.chainman = std::make_unique<ChainstateManager>(chainman_opts);
|
||||
ChainstateManager& chainman = *node.chainman;
|
||||
|
||||
const bool fReset = fReindex;
|
||||
|
|
22
src/kernel/chainstatemanager_opts.h
Normal file
22
src/kernel/chainstatemanager_opts.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
// Copyright (c) 2022 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_KERNEL_CHAINSTATEMANAGER_OPTS_H
|
||||
#define BITCOIN_KERNEL_CHAINSTATEMANAGER_OPTS_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
class CChainParams;
|
||||
|
||||
/**
|
||||
* An options struct for `ChainstateManager`, more ergonomically referred to as
|
||||
* `ChainstateManager::Options` due to the using-declaration in
|
||||
* `ChainstateManager`.
|
||||
*/
|
||||
struct ChainstateManagerOpts {
|
||||
const CChainParams& chainparams;
|
||||
};
|
||||
|
||||
#endif // BITCOIN_KERNEL_CHAINSTATEMANAGER_OPTS_H
|
|
@ -164,7 +164,10 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve
|
|||
|
||||
m_cache_sizes = CalculateCacheSizes(m_args);
|
||||
|
||||
m_node.chainman = std::make_unique<ChainstateManager>(chainparams);
|
||||
const ChainstateManager::Options chainman_opts{
|
||||
chainparams,
|
||||
};
|
||||
m_node.chainman = std::make_unique<ChainstateManager>(chainman_opts);
|
||||
m_node.chainman->m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(m_cache_sizes.block_tree_db, true);
|
||||
|
||||
// Start script-checking threads. Set g_parallel_script_checks to true so they are used.
|
||||
|
|
|
@ -22,8 +22,11 @@ BOOST_FIXTURE_TEST_SUITE(validation_chainstate_tests, TestingSetup)
|
|||
//!
|
||||
BOOST_AUTO_TEST_CASE(validation_chainstate_resize_caches)
|
||||
{
|
||||
const CChainParams& chainparams = Params();
|
||||
ChainstateManager manager(chainparams);
|
||||
const ChainstateManager::Options chainman_opts{
|
||||
Params(),
|
||||
};
|
||||
ChainstateManager manager{chainman_opts};
|
||||
|
||||
WITH_LOCK(::cs_main, manager.m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(1 << 20, true));
|
||||
CTxMemPool mempool;
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <attributes.h>
|
||||
#include <chain.h>
|
||||
#include <chainparams.h>
|
||||
#include <kernel/chainstatemanager_opts.h>
|
||||
#include <consensus/amount.h>
|
||||
#include <deploymentstatus.h>
|
||||
#include <fs.h>
|
||||
|
@ -853,7 +854,10 @@ private:
|
|||
friend CChainState;
|
||||
|
||||
public:
|
||||
explicit ChainstateManager(const CChainParams& chainparams) : m_chainparams{chainparams} { }
|
||||
using Options = ChainstateManagerOpts;
|
||||
|
||||
explicit ChainstateManager(const Options& opts)
|
||||
: m_chainparams(opts.chainparams) {};
|
||||
|
||||
const CChainParams& GetParams() const { return m_chainparams; }
|
||||
const Consensus::Params& GetConsensus() const { return m_chainparams.GetConsensus(); }
|
||||
|
|
Loading…
Reference in a new issue