@@ -323,6 +323,14 @@ TestChainSetup::TestChainSetup(int num_blocks, const std::vector<const char*>& e
323
323
// Generate a num_blocks length chain:
324
324
this ->mineBlocks (num_blocks);
325
325
326
+ // Initialize transaction index *after* chain has been constructed
327
+ g_txindex = std::make_unique<TxIndex>(1 << 20 , true );
328
+ assert (!g_txindex->BlockUntilSyncedToCurrentChain ());
329
+ if (!g_txindex->Start (m_node.chainman ->ActiveChainstate ())) {
330
+ throw std::runtime_error (" TxIndex::Start() failed." );
331
+ }
332
+ IndexWaitSynced (*g_txindex);
333
+
326
334
CCheckpointData checkpoints{
327
335
{
328
336
/* TestChainDATSetup */
@@ -361,11 +369,10 @@ void TestChainSetup::mineBlocks(int num_blocks)
361
369
m_coinbase_txns.push_back (b.vtx [0 ]);
362
370
}
363
371
364
- g_txindex = std::make_unique<TxIndex>(1 << 20 , true );
365
- assert (g_txindex->Start (m_node.chainman ->ActiveChainstate ()));
366
-
367
372
// Allow tx index to catch up with the block index.
368
- IndexWaitSynced (*g_txindex);
373
+ if (g_txindex) {
374
+ IndexWaitSynced (*g_txindex);
375
+ }
369
376
}
370
377
371
378
CBlock TestChainSetup::CreateAndProcessBlock (const std::vector<CMutableTransaction>& txns, const CScript& scriptPubKey)
@@ -500,6 +507,7 @@ TestChainSetup::~TestChainSetup()
500
507
// we might be destroying it while scheduler still has some work for it
501
508
// e.g. via BlockConnected signal
502
509
IndexWaitSynced (*g_txindex);
510
+ g_txindex->Interrupt ();
503
511
g_txindex->Stop ();
504
512
SyncWithValidationInterfaceQueue ();
505
513
g_txindex.reset ();
0 commit comments