index_blockfilter.cpp
1 // Copyright (c) 2023-present The Bitcoin Core developers 2 // Distributed under the MIT software license, see the accompanying 3 // file COPYING or https://www.opensource.org/licenses/mit-license.php. 4 5 #include <bench/bench.h> 6 7 #include <addresstype.h> 8 #include <index/blockfilterindex.h> 9 #include <node/chainstate.h> 10 #include <node/context.h> 11 #include <test/util/setup_common.h> 12 #include <util/strencodings.h> 13 14 // Very simple block filter index sync benchmark, only using coinbase outputs. 15 static void BlockFilterIndexSync(benchmark::Bench& bench) 16 { 17 const auto test_setup = MakeNoLogFileContext<TestChain100Setup>(); 18 19 // Create more blocks 20 int CHAIN_SIZE = 600; 21 CPubKey pubkey{ParseHex("02ed26169896db86ced4cbb7b3ecef9859b5952825adbeab998fb5b307e54949c9")}; 22 CScript script = GetScriptForDestination(WitnessV0KeyHash(pubkey)); 23 std::vector<CMutableTransaction> noTxns; 24 for (int i = 0; i < CHAIN_SIZE - 100; i++) { 25 test_setup->CreateAndProcessBlock(noTxns, script); 26 SetMockTime(GetTime() + 1); 27 } 28 assert(WITH_LOCK(::cs_main, return test_setup->m_node.chainman->ActiveHeight() == CHAIN_SIZE)); 29 30 bench.minEpochIterations(5).run([&] { 31 BlockFilterIndex filter_index(interfaces::MakeChain(test_setup->m_node), BlockFilterType::BASIC, 32 /*n_cache_size=*/0, /*f_memory=*/false, /*f_wipe=*/true); 33 assert(filter_index.Init()); 34 assert(!filter_index.BlockUntilSyncedToCurrentChain()); 35 filter_index.Sync(); 36 37 IndexSummary summary = filter_index.GetSummary(); 38 assert(summary.synced); 39 assert(summary.best_block_hash == WITH_LOCK(::cs_main, return test_setup->m_node.chainman->ActiveTip()->GetBlockHash())); 40 }); 41 } 42 43 BENCHMARK(BlockFilterIndexSync, benchmark::PriorityLevel::HIGH);