|
13 | 13 | #include <pow.h>
|
14 | 14 | #include <test/util/blockfilter.h>
|
15 | 15 | #include <test/util/setup_common.h>
|
| 16 | +#include <util/threadpool.h> |
16 | 17 | #include <validation.h>
|
17 | 18 |
|
18 | 19 | #include <boost/test/unit_test.hpp>
|
@@ -268,6 +269,50 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
|
268 | 269 | filter_index.Stop();
|
269 | 270 | }
|
270 | 271 |
|
| 272 | +BOOST_FIXTURE_TEST_CASE(blockfilter_index_parallel_initial_sync, BuildChainTestingSetup) |
| 273 | +{ |
| 274 | + int tip_height = 100; // pre-mined blocks |
| 275 | + const uint16_t MINE_BLOCKS = 650; |
| 276 | + for (int round = 0; round < 2; round++) { // two rounds to test sync from genesis and from a higher block |
| 277 | + // Generate blocks |
| 278 | + mineBlocks(MINE_BLOCKS); |
| 279 | + const CBlockIndex* tip = WITH_LOCK(::cs_main, return m_node.chainman->ActiveChain().Tip()); |
| 280 | + BOOST_REQUIRE(tip->nHeight == MINE_BLOCKS + tip_height); |
| 281 | + tip_height = tip->nHeight; |
| 282 | + |
| 283 | + // Init index |
| 284 | + BlockFilterIndex filter_index(interfaces::MakeChain(m_node), BlockFilterType::BASIC, 1 << 20, /*f_memory=*/false); |
| 285 | + BOOST_REQUIRE(filter_index.Init()); |
| 286 | + |
| 287 | + ThreadPool thread_pool; |
| 288 | + thread_pool.Start(2); |
| 289 | + filter_index.SetThreadPool(thread_pool); |
| 290 | + filter_index.SetBlocksPerWorker(200); |
| 291 | + |
| 292 | + // Start sync |
| 293 | + BOOST_CHECK(!filter_index.BlockUntilSyncedToCurrentChain()); |
| 294 | + filter_index.Sync(); |
| 295 | + const auto& summary{filter_index.GetSummary()}; |
| 296 | + BOOST_CHECK(summary.synced); |
| 297 | + BOOST_CHECK_EQUAL(summary.best_block_height, tip_height); |
| 298 | + |
| 299 | + // Check that filter index has all blocks that were in the chain before it started. |
| 300 | + { |
| 301 | + uint256 last_header; |
| 302 | + LOCK(cs_main); |
| 303 | + const CBlockIndex* block_index; |
| 304 | + for (block_index = m_node.chainman->ActiveChain().Genesis(); |
| 305 | + block_index != nullptr; |
| 306 | + block_index = m_node.chainman->ActiveChain().Next(block_index)) { |
| 307 | + CheckFilterLookups(filter_index, block_index, last_header, m_node.chainman->m_blockman); |
| 308 | + } |
| 309 | + } |
| 310 | + |
| 311 | + filter_index.Interrupt(); |
| 312 | + filter_index.Stop(); |
| 313 | + } |
| 314 | +} |
| 315 | + |
271 | 316 | BOOST_FIXTURE_TEST_CASE(blockfilter_index_init_destroy, BasicTestingSetup)
|
272 | 317 | {
|
273 | 318 | BlockFilterIndex* filter_index;
|
|
0 commit comments