Bitcoin Core  27.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 <bench/bench.h>
6 
7 #include <addresstype.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.
16 {
17  const auto test_setup = MakeNoLogFileContext<TestChain100Setup>();
18 
19  // Create more blocks
20  int CHAIN_SIZE = 600;
21  CPubKey pubkey{ParseHex("02ed26169896db86ced4cbb7b3ecef9859b5952825adbeab998fb5b307e54949c9")};
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 
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:414
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:47
std::unique_ptr< Chain > MakeChain(node::NodeContext &node)
Return implementation of Chain interface.
Definition: interfaces.cpp:835
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
Definition: strencodings.h:65
bool synced
Definition: base.h:25
uint256 best_block_hash
Definition: base.h:27
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:301
int64_t GetTime()
Definition: time.cpp:44
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition: time.cpp:32
assert(!tx.IsCoinBase())