@@ -302,10 +302,27 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
302
302
if (!m_node.chainman ->ActiveChainstate ().ActivateBestChain (state)) {
303
303
throw std::runtime_error (strprintf (" ActivateBestChain failed. (%s)" , state.ToString ()));
304
304
}
305
+
306
+ g_txindex = std::make_unique<TxIndex>(1 << 20 , true );
307
+ if (!g_txindex->Start (m_node.chainman ->ActiveChainstate ())) {
308
+ throw std::runtime_error (" TxIndex::Start() failed." );
309
+ }
310
+
311
+ // Allow tx index to catch up with the block index.
312
+ IndexWaitSynced (*g_txindex);
305
313
}
306
314
307
315
TestingSetup::~TestingSetup ()
308
316
{
317
+ // Allow tx index to catch up with the block index cause otherwise
318
+ // we might be destroying it while scheduler still has some work for it
319
+ // e.g. via BlockConnected signal
320
+ {
321
+ IndexWaitSynced (*g_txindex);
322
+ g_txindex->Stop ();
323
+ SyncWithValidationInterfaceQueue ();
324
+ g_txindex.reset ();
325
+ }
309
326
DashTestSetupClose (m_node);
310
327
m_node.connman ->Stop ();
311
328
m_node.peerman .reset ();
@@ -349,14 +366,6 @@ TestChainSetup::TestChainSetup(int num_blocks, const std::vector<const char*>& e
349
366
hash != checkpoints.mapCheckpoints .end () &&
350
367
m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash () == hash->second );
351
368
}
352
-
353
- g_txindex = std::make_unique<TxIndex>(1 << 20 , true );
354
- if (!g_txindex->Start (m_node.chainman ->ActiveChainstate ())) {
355
- throw std::runtime_error (" TxIndex::Start() failed." );
356
- }
357
-
358
- // Allow tx index to catch up with the block index.
359
- IndexWaitSynced (*g_txindex);
360
369
}
361
370
362
371
void TestChainSetup::mineBlocks (int num_blocks)
@@ -498,17 +507,6 @@ CMutableTransaction TestChainSetup::CreateValidMempoolTransaction(CTransactionRe
498
507
return mempool_txn;
499
508
}
500
509
501
- TestChainSetup::~TestChainSetup ()
502
- {
503
- // Allow tx index to catch up with the block index cause otherwise
504
- // we might be destroying it while scheduler still has some work for it
505
- // e.g. via BlockConnected signal
506
- IndexWaitSynced (*g_txindex);
507
- g_txindex->Stop ();
508
- SyncWithValidationInterfaceQueue ();
509
- g_txindex.reset ();
510
- }
511
-
512
510
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx (const CMutableTransaction& tx) const
513
511
{
514
512
return FromTx (MakeTransactionRef (tx));
0 commit comments