Bitcoin Core 32.99.0
P2P Digital Currency
Loading...
Searching...
No Matches
index_blockfilter.cpp
Go to the documentation of this file.
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 <addresstype.h>
6#include <bench/bench.h>
7#include <blockfilter.h>
8#include <chain.h>
9#include <index/base.h>
11#include <interfaces/chain.h>
12#include <primitives/block.h>
14#include <pubkey.h>
15#include <script/script.h>
16#include <sync.h>
18#include <test/util/time.h>
20#include <uint256.h>
21#include <util/check.h>
22#include <util/strencodings.h>
23#include <util/time.h>
24#include <validation.h>
25
26#include <array>
27#include <memory>
28#include <span>
29#include <vector>
30
31using namespace util::hex_literals;
32
33// Very simple block filter index sync benchmark, only using coinbase outputs.
35{
37
38 // Create more blocks
39 int CHAIN_SIZE = 600;
40 CPubKey pubkey{"02ed26169896db86ced4cbb7b3ecef9859b5952825adbeab998fb5b307e54949c9"_hex_u8};
42 std::vector<CMutableTransaction> noTxns;
43 for (int i = 0; i < CHAIN_SIZE - 100; i++) {
44 test_setup->CreateAndProcessBlock(noTxns, script);
45 test_setup->m_clock += 1s;
46 }
47 assert(WITH_LOCK(::cs_main, return test_setup->m_node.chainman->ActiveHeight() == CHAIN_SIZE));
48
49 bench.minEpochIterations(5).run([&] {
51 /*n_cache_size=*/0, /*f_memory=*/false, /*f_wipe=*/true);
52 assert(filter_index.Init());
53 assert(!filter_index.BlockUntilSyncedToCurrentChain());
54 filter_index.Sync();
55
56 IndexSummary summary = filter_index.GetSummary();
57 assert(summary.synced);
58 assert(summary.best_block_hash == WITH_LOCK(::cs_main, return test_setup->m_node.chainman->ActiveTip()->GetBlockHash()));
59
60 StopIndex(filter_index, test_setup->m_node);
61 });
62}
63
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
#define BENCHMARK(n)
Definition bench.h:69
bool Init()
Initializes the sync state and registers the instance to the validation interface so that it stays in...
Definition base.cpp:105
IndexSummary GetSummary() const
Get a summary of the index and its state.
Definition base.cpp:488
void Sync()
Sync the index with the block index starting from the current best block.
Definition base.cpp:208
BlockFilterIndex is used to store and retrieve block filters, hashes, and headers for a range of bloc...
An encapsulated public key.
Definition pubkey.h:43
Serialized script, used inside transaction inputs and outputs.
Definition script.h:406
Main entry point to nanobench's benchmarking facility.
Definition nanobench.h:649
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition cs_main.cpp:8
static void BlockFilterIndexSync(benchmark::Bench &bench)
std::unique_ptr< Chain > MakeChain(node::NodeContext &node)
Return implementation of Chain interface.
""_hex is a compile-time user-defined literal returning a std::array<std::byte>, equivalent to ParseH...
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition sync.h:299
void StopIndex(BaseIndex &index, node::NodeContext &node)
Drain validation callbacks before stopping an index, matching Shutdown() in init.cpp.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:82
assert(!tx.IsCoinBase())