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