Skip to content

Commit 9ff40ff

Browse files
committed
tests: init g_txindex earlier, move back to TestingSetup
`g_txindex` was moved to `TestChainSetup` in dash#4855 to aid in removing some crash mitigations. Since then, we have better sync logic to such crashes and we can finally move it back to `TestingSetup`, as `TestingSetup` is meant to be complete environment.
1 parent 20f2636 commit 9ff40ff

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

src/test/util/setup_common.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,27 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
302302
if (!m_node.chainman->ActiveChainstate().ActivateBestChain(state)) {
303303
throw std::runtime_error(strprintf("ActivateBestChain failed. (%s)", state.ToString()));
304304
}
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);
305313
}
306314

307315
TestingSetup::~TestingSetup()
308316
{
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+
}
309326
DashTestSetupClose(m_node);
310327
m_node.connman->Stop();
311328
m_node.peerman.reset();
@@ -349,14 +366,6 @@ TestChainSetup::TestChainSetup(int num_blocks, const std::vector<const char*>& e
349366
hash != checkpoints.mapCheckpoints.end() &&
350367
m_node.chainman->ActiveChain().Tip()->GetBlockHash() == hash->second);
351368
}
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);
360369
}
361370

362371
void TestChainSetup::mineBlocks(int num_blocks)
@@ -498,17 +507,6 @@ CMutableTransaction TestChainSetup::CreateValidMempoolTransaction(CTransactionRe
498507
return mempool_txn;
499508
}
500509

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-
512510
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction& tx) const
513511
{
514512
return FromTx(MakeTransactionRef(tx));

src/test/util/setup_common.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ class CScript;
122122
struct TestChainSetup : public RegTestingSetup
123123
{
124124
TestChainSetup(int num_blocks, const std::vector<const char*>& extra_args = {});
125-
~TestChainSetup();
126125

127126
/**
128127
* Create a new block with just given transactions, coinbase paying to

0 commit comments

Comments
 (0)