|
8 | 8 | #include <interfaces/chain.h>
|
9 | 9 | #include <test/util/index.h>
|
10 | 10 | #include <test/util/setup_common.h>
|
| 11 | +#include <util/threadpool.h> |
11 | 12 | #include <validation.h>
|
12 | 13 |
|
13 | 14 | #include <boost/test/unit_test.hpp>
|
@@ -77,4 +78,45 @@ BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup)
|
77 | 78 | txindex.Stop();
|
78 | 79 | }
|
79 | 80 |
|
| 81 | +BOOST_FIXTURE_TEST_CASE(txindex_parallel_initial_sync, TestChain100Setup) |
| 82 | +{ |
| 83 | + int tip_height = 100; // pre-mined blocks |
| 84 | + const uint16_t MINE_BLOCKS = 650; |
| 85 | + for (int round = 0; round < 2; round++) { // two rounds to test sync from genesis and from a higher block |
| 86 | + // Generate blocks |
| 87 | + mineBlocks(MINE_BLOCKS); |
| 88 | + const CBlockIndex* tip = WITH_LOCK(::cs_main, return m_node.chainman->ActiveChain().Tip()); |
| 89 | + BOOST_REQUIRE(tip->nHeight == MINE_BLOCKS + tip_height); |
| 90 | + tip_height = tip->nHeight; |
| 91 | + |
| 92 | + // Init and start index |
| 93 | + TxIndex txindex(interfaces::MakeChain(m_node), 1 << 20, /*f_memory=*/false); |
| 94 | + BOOST_REQUIRE(txindex.Init()); |
| 95 | + std::shared_ptr<ThreadPool> thread_pool = std::make_shared<ThreadPool>(); |
| 96 | + thread_pool->Start(2); |
| 97 | + txindex.SetThreadPool(thread_pool); |
| 98 | + txindex.SetTasksPerWorker(200); |
| 99 | + |
| 100 | + BOOST_CHECK(!txindex.BlockUntilSyncedToCurrentChain()); |
| 101 | + BOOST_REQUIRE(txindex.StartBackgroundSync()); |
| 102 | + |
| 103 | + // Allow tx index to catch up with the block index. |
| 104 | + IndexWaitSynced(txindex, *Assert(m_node.shutdown_signal)); |
| 105 | + |
| 106 | + // Check that txindex has all txs that were in the chain before it started. |
| 107 | + CTransactionRef tx_disk; |
| 108 | + uint256 block_hash; |
| 109 | + for (const auto& txn : m_coinbase_txns) { |
| 110 | + if (!txindex.FindTx(txn->GetHash(), block_hash, tx_disk)) { |
| 111 | + BOOST_ERROR("FindTx failed"); |
| 112 | + } else if (tx_disk->GetHash() != txn->GetHash()) { |
| 113 | + BOOST_ERROR("Read incorrect tx"); |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + txindex.Interrupt(); |
| 118 | + txindex.Stop(); |
| 119 | + } |
| 120 | +} |
| 121 | + |
80 | 122 | BOOST_AUTO_TEST_SUITE_END()
|
0 commit comments