|
17 | 17 | #include <net_processing.h>
|
18 | 18 | #include <node/miner.h>
|
19 | 19 | #include <noui.h>
|
| 20 | +#include <node/blockstorage.h> // for fReindex, fPruneMode |
| 21 | +#include <node/chainstate.h> // for LoadChainstate |
20 | 22 | #include <policy/fees.h>
|
21 | 23 | #include <pow.h>
|
22 | 24 | #include <rpc/blockchain.h>
|
23 | 25 | #include <rpc/register.h>
|
24 | 26 | #include <rpc/server.h>
|
25 | 27 | #include <scheduler.h>
|
26 | 28 | #include <script/sigcache.h>
|
| 29 | +#include <shutdown.h> // for ShutdownRequested |
27 | 30 | #include <streams.h>
|
28 | 31 | #include <txdb.h>
|
29 | 32 | #include <util/strencodings.h>
|
@@ -143,8 +146,10 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve
|
143 | 146 | m_node.fee_estimator = std::make_unique<CBlockPolicyEstimator>();
|
144 | 147 | m_node.mempool = std::make_unique<CTxMemPool>(m_node.fee_estimator.get(), 1);
|
145 | 148 |
|
| 149 | + m_cache_sizes = CalculateCacheSizes(m_args); |
| 150 | + |
146 | 151 | m_node.chainman = std::make_unique<ChainstateManager>();
|
147 |
| - m_node.chainman->m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(1 << 20, true); |
| 152 | + m_node.chainman->m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(m_cache_sizes.block_tree_db, true); |
148 | 153 |
|
149 | 154 | // Start script-checking threads. Set g_parallel_script_checks to true so they are used.
|
150 | 155 | constexpr int script_check_threads = 2;
|
@@ -177,15 +182,18 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
|
177 | 182 | // instead of unit tests, but for now we need these here.
|
178 | 183 | RegisterAllCoreRPCCommands(tableRPC);
|
179 | 184 |
|
180 |
| - m_node.chainman->InitializeChainstate(m_node.mempool.get()); |
181 |
| - m_node.chainman->ActiveChainstate().InitCoinsDB( |
182 |
| - /*cache_size_bytes=*/1 << 23, /*in_memory=*/true, /*should_wipe=*/false); |
183 |
| - assert(!m_node.chainman->ActiveChainstate().CanFlushToDisk()); |
184 |
| - m_node.chainman->ActiveChainstate().InitCoinsCache(1 << 23); |
185 |
| - assert(m_node.chainman->ActiveChainstate().CanFlushToDisk()); |
186 |
| - if (!m_node.chainman->ActiveChainstate().LoadGenesisBlock()) { |
187 |
| - throw std::runtime_error("LoadGenesisBlock failed."); |
188 |
| - } |
| 185 | + auto rv = LoadChainstate(fReindex.load(), |
| 186 | + *Assert(m_node.chainman.get()), |
| 187 | + Assert(m_node.mempool.get()), |
| 188 | + fPruneMode, |
| 189 | + chainparams.GetConsensus(), |
| 190 | + m_args.GetBoolArg("-reindex-chainstate", false), |
| 191 | + m_cache_sizes.block_tree_db, |
| 192 | + m_cache_sizes.coins_db, |
| 193 | + m_cache_sizes.coins, |
| 194 | + true, |
| 195 | + true); |
| 196 | + assert(!rv.has_value()); |
189 | 197 |
|
190 | 198 | BlockValidationState state;
|
191 | 199 | if (!m_node.chainman->ActiveChainstate().ActivateBestChain(state)) {
|
|
0 commit comments