Skip to content

Commit dbe45c3

Browse files
committed
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.
1 parent 4d0c00d commit dbe45c3

File tree

7 files changed

+45
-6
lines changed

7 files changed

+45
-6
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ BITCOIN_CORE_H = \
171171
interfaces/ipc.h \
172172
interfaces/node.h \
173173
interfaces/wallet.h \
174+
kernel/chainstatemanager_opts.h \
174175
key.h \
175176
key_io.h \
176177
logging.h \

src/bitcoin-chainstate.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ int main(int argc, char* argv[])
7070

7171

7272
// SETUP: Chainstate
73-
ChainstateManager chainman{chainparams};
73+
const ChainstateManager::Options chainman_opts{
74+
chainparams,
75+
};
76+
ChainstateManager chainman{chainman_opts};
7477

7578
auto rv = node::LoadChainstate(false,
7679
std::ref(chainman),

src/init.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,10 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14211421
for (bool fLoaded = false; !fLoaded && !ShutdownRequested();) {
14221422
node.mempool = std::make_unique<CTxMemPool>(node.fee_estimator.get(), mempool_check_ratio);
14231423

1424-
node.chainman = std::make_unique<ChainstateManager>(chainparams);
1424+
const ChainstateManager::Options chainman_opts{
1425+
chainparams,
1426+
};
1427+
node.chainman = std::make_unique<ChainstateManager>(chainman_opts);
14251428
ChainstateManager& chainman = *node.chainman;
14261429

14271430
const bool fReset = fReindex;

src/kernel/chainstatemanager_opts.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) 2022 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_KERNEL_CHAINSTATEMANAGER_OPTS_H
6+
#define BITCOIN_KERNEL_CHAINSTATEMANAGER_OPTS_H
7+
8+
#include <cstdint>
9+
#include <functional>
10+
11+
class CChainParams;
12+
13+
/**
14+
* An options struct for `ChainstateManager`, more ergonomically referred to as
15+
* `ChainstateManager::Options` due to the using-declaration in
16+
* `ChainstateManager`.
17+
*/
18+
struct ChainstateManagerOpts {
19+
const CChainParams& chainparams;
20+
};
21+
22+
#endif // BITCOIN_KERNEL_CHAINSTATEMANAGER_OPTS_H

src/test/util/setup_common.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve
164164

165165
m_cache_sizes = CalculateCacheSizes(m_args);
166166

167-
m_node.chainman = std::make_unique<ChainstateManager>(chainparams);
167+
const ChainstateManager::Options chainman_opts{
168+
chainparams,
169+
};
170+
m_node.chainman = std::make_unique<ChainstateManager>(chainman_opts);
168171
m_node.chainman->m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(m_cache_sizes.block_tree_db, true);
169172

170173
// Start script-checking threads. Set g_parallel_script_checks to true so they are used.

src/test/validation_chainstate_tests.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ BOOST_FIXTURE_TEST_SUITE(validation_chainstate_tests, TestingSetup)
2222
//!
2323
BOOST_AUTO_TEST_CASE(validation_chainstate_resize_caches)
2424
{
25-
const CChainParams& chainparams = Params();
26-
ChainstateManager manager(chainparams);
25+
const ChainstateManager::Options chainman_opts{
26+
Params(),
27+
};
28+
ChainstateManager manager{chainman_opts};
29+
2730
WITH_LOCK(::cs_main, manager.m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(1 << 20, true));
2831
CTxMemPool mempool;
2932

src/validation.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <attributes.h>
1515
#include <chain.h>
1616
#include <chainparams.h>
17+
#include <kernel/chainstatemanager_opts.h>
1718
#include <consensus/amount.h>
1819
#include <deploymentstatus.h>
1920
#include <fs.h>
@@ -853,7 +854,10 @@ class ChainstateManager
853854
friend CChainState;
854855

855856
public:
856-
explicit ChainstateManager(const CChainParams& chainparams) : m_chainparams{chainparams} { }
857+
using Options = ChainstateManagerOpts;
858+
859+
explicit ChainstateManager(const Options& opts)
860+
: m_chainparams(opts.chainparams) {};
857861

858862
const CChainParams& GetParams() const { return m_chainparams; }
859863
const Consensus::Params& GetConsensus() const { return m_chainparams.GetConsensus(); }

0 commit comments

Comments
 (0)