Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move g_txindex initialization out of erroneous location and into constructor #6119

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/test/util/setup_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,14 @@ TestChainSetup::TestChainSetup(int num_blocks, const std::vector<const char*>& e
// Generate a num_blocks length chain:
this->mineBlocks(num_blocks);

// Initialize transaction index *after* chain has been constructed
g_txindex = std::make_unique<TxIndex>(1 << 20, true);
assert(!g_txindex->BlockUntilSyncedToCurrentChain());
if (!g_txindex->Start(m_node.chainman->ActiveChainstate())) {
throw std::runtime_error("TxIndex::Start() failed.");
}
IndexWaitSynced(*g_txindex);

CCheckpointData checkpoints{
{
/* TestChainDATSetup */
Expand Down Expand Up @@ -361,11 +369,10 @@ void TestChainSetup::mineBlocks(int num_blocks)
m_coinbase_txns.push_back(b.vtx[0]);
}

g_txindex = std::make_unique<TxIndex>(1 << 20, true);
assert(g_txindex->Start(m_node.chainman->ActiveChainstate()));

// Allow tx index to catch up with the block index.
IndexWaitSynced(*g_txindex);
if (g_txindex) {
IndexWaitSynced(*g_txindex);
}
}

CBlock TestChainSetup::CreateAndProcessBlock(const std::vector<CMutableTransaction>& txns, const CScript& scriptPubKey)
Expand Down Expand Up @@ -500,6 +507,7 @@ TestChainSetup::~TestChainSetup()
// we might be destroying it while scheduler still has some work for it
// e.g. via BlockConnected signal
IndexWaitSynced(*g_txindex);
g_txindex->Interrupt();
g_txindex->Stop();
SyncWithValidationInterfaceQueue();
g_txindex.reset();
Expand Down
Loading