MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ChainTestingSetup

Method ChainTestingSetup

src/test/util/setup_common.cpp:272–331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

270}
271
272ChainTestingSetup::ChainTestingSetup(const ChainType chainType, TestOpts opts)
273 : BasicTestingSetup(chainType, opts)
274{
275 const CChainParams& chainparams = Params();
276
277 // A task runner is required to prevent ActivateBestChain
278 // from blocking due to queue overrun.
279 if (opts.setup_validation_interface) {
280 m_node.scheduler = std::make_unique<CScheduler>();
281 m_node.scheduler->m_service_thread = std::thread(util::TraceThread, "scheduler", [&] { m_node.scheduler->serviceQueue(); });
282 m_node.validation_signals =
283 // Use synchronous task runner while fuzzing to avoid non-determinism
284 EnableFuzzDeterminism() ?
285 std::make_unique<ValidationSignals>(std::make_unique<util::ImmediateTaskRunner>()) :
286 std::make_unique<ValidationSignals>(std::make_unique<SerialTaskRunner>(*m_node.scheduler));
287 {
288 // Ensure deterministic coverage by waiting for m_service_thread to be running
289 std::promise<void> promise;
290 m_node.scheduler->scheduleFromNow([&promise] { promise.set_value(); }, 0ms);
291 promise.get_future().wait();
292 }
293 }
294
295 bilingual_str error{};
296 m_node.mempool = std::make_unique<CTxMemPool>(MemPoolOptionsForTest(m_node), error);
297 Assert(error.empty());
298 m_node.warnings = std::make_unique<node::Warnings>();
299
300 m_node.notifications = std::make_unique<KernelNotifications>(Assert(m_node.shutdown_request), m_node.exit_status, *Assert(m_node.warnings));
301
302 m_make_chainman = [this, &chainparams, opts] {
303 Assert(!m_node.chainman);
304 ChainstateManager::Options chainman_opts{
305 .chainparams = chainparams,
306 .datadir = m_args.GetDataDirNet(),
307 .check_block_index = 1,
308 .notifications = *m_node.notifications,
309 .signals = m_node.validation_signals.get(),
310 // Use no worker threads while fuzzing to avoid non-determinism
311 .worker_threads_num = EnableFuzzDeterminism() ? 0 : 2,
312 };
313 if (opts.min_validation_cache) {
314 chainman_opts.script_execution_cache_bytes = 0;
315 chainman_opts.signature_cache_bytes = 0;
316 }
317 const BlockManager::Options blockman_opts{
318 .chainparams = chainman_opts.chainparams,
319 .blocks_dir = m_args.GetBlocksDirPath(),
320 .notifications = chainman_opts.notifications,
321 .block_tree_db_params = DBParams{
322 .path = m_args.GetDataDirNet() / "blocks" / "index",
323 .cache_bytes = m_kernel_cache_sizes.block_tree_db,
324 .memory_only = opts.block_tree_db_in_memory,
325 .wipe_data = m_args.GetBoolArg("-reindex", false),
326 },
327 };
328 m_node.chainman = std::make_unique<ChainstateManager>(*Assert(m_node.shutdown_signal), chainman_opts, blockman_opts);
329 };

Callers

nothing calls this directly

Calls 10

EnableFuzzDeterminismFunction · 0.85
MemPoolOptionsForTestFunction · 0.85
serviceQueueMethod · 0.80
GetDataDirNetMethod · 0.80
GetBlocksDirPathMethod · 0.80
GetBoolArgMethod · 0.80
ParamsClass · 0.50
waitMethod · 0.45
emptyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected