Bitcoin Core 28.99.0
P2P Digital Currency
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 <span.h>
17#include <sync.h>
19#include <uint256.h>
20#include <util/strencodings.h>
21#include <util/time.h>
22#include <validation.h>
23
24#include <cassert>
25#include <memory>
26#include <vector>
27
28using namespace util::hex_literals;
29
30// Very simple block filter index sync benchmark, only using coinbase outputs.
32{
33 const auto test_setup = MakeNoLogFileContext<TestChain100Setup>();
34
35 // Create more blocks
36 int CHAIN_SIZE = 600;
37 CPubKey pubkey{"02ed26169896db86ced4cbb7b3ecef9859b5952825adbeab998fb5b307e54949c9"_hex_u8};
39 std::vector<CMutableTransaction> noTxns;
40 for (int i = 0; i < CHAIN_SIZE - 100; i++) {
41 test_setup->CreateAndProcessBlock(noTxns, script);
42 SetMockTime(GetTime() + 1);
43 }
44 assert(WITH_LOCK(::cs_main, return test_setup->m_node.chainman->ActiveHeight() == CHAIN_SIZE));
45
46 bench.minEpochIterations(5).run([&] {
47 BlockFilterIndex filter_index(interfaces::MakeChain(test_setup->m_node), BlockFilterType::BASIC,
48 /*n_cache_size=*/0, /*f_memory=*/false, /*f_wipe=*/true);
49 assert(filter_index.Init());
50 assert(!filter_index.BlockUntilSyncedToCurrentChain());
51 filter_index.Sync();
52
53 IndexSummary summary = filter_index.GetSummary();
54 assert(summary.synced);
55 assert(summary.best_block_hash == WITH_LOCK(::cs_main, return test_setup->m_node.chainman->ActiveTip()->GetBlockHash()));
56 });
57}
58
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
bool Init()
Initializes the sync state and registers the instance to the validation interface so that it stays in...
Definition: base.cpp:79
IndexSummary GetSummary() const
Get a summary of the index and its state.
Definition: base.cpp:421
void Sync()
Sync the index with the block index starting from the current best block.
Definition: base.cpp:144
BlockFilterIndex is used to store and retrieve block filters, hashes, and headers for a range of bloc...
An encapsulated public key.
Definition: pubkey.h:34
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:415
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:627
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1234
ANKERL_NANOBENCH(NODISCARD) std Bench & minEpochIterations(uint64_t numIters) noexcept
Sets the minimum number of iterations each epoch should take.
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)
BENCHMARK(BlockFilterIndexSync, benchmark::PriorityLevel::HIGH)
@ HIGH
Definition: bench.h:48
std::unique_ptr< Chain > MakeChain(node::NodeContext &node)
Return implementation of Chain interface.
Definition: interfaces.cpp:999
""_hex is a compile-time user-defined literal returning a std::array<std::byte>, equivalent to ParseH...
Definition: strencodings.h:427
bool synced
Definition: base.h:27
uint256 best_block_hash
Definition: base.h:29
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:301
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
Definition: time.cpp:47
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition: time.cpp:35
assert(!tx.IsCoinBase())