Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
bench
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
>
10
#include <
index/blockfilterindex.h
>
11
#include <
interfaces/chain.h
>
12
#include <
primitives/block.h
>
13
#include <
primitives/transaction.h
>
14
#include <
pubkey.h
>
15
#include <
script/script.h
>
16
#include <
sync.h
>
17
#include <
test/util/setup_common.h
>
18
#include <
test/util/time.h
>
19
#include <
uint256.h
>
20
#include <
util/check.h
>
21
#include <
util/strencodings.h
>
22
#include <util/time.h>
23
#include <validation.h>
24
25
#include <array>
26
#include <memory>
27
#include <span>
28
#include <vector>
29
30
using namespace
util::hex_literals
;
31
32
// Very simple block filter index sync benchmark, only using coinbase outputs.
33
static
void
BlockFilterIndexSync
(
benchmark::Bench
& bench)
34
{
35
const
auto
test_setup =
MakeNoLogFileContext<TestChain100Setup>
();
36
37
// Create more blocks
38
int
CHAIN_SIZE = 600;
39
CPubKey
pubkey{
"02ed26169896db86ced4cbb7b3ecef9859b5952825adbeab998fb5b307e54949c9"
_hex_u8};
40
CScript
script
=
GetScriptForDestination
(
WitnessV0KeyHash
(pubkey));
41
std::vector<CMutableTransaction> noTxns;
42
for
(
int
i = 0; i < CHAIN_SIZE - 100; i++) {
43
test_setup->CreateAndProcessBlock(noTxns,
script
);
44
test_setup->m_clock += 1s;
45
}
46
assert
(
WITH_LOCK
(
::cs_main
,
return
test_setup->m_node.chainman->ActiveHeight() == CHAIN_SIZE));
47
48
bench.
minEpochIterations
(5).
run
([&] {
49
BlockFilterIndex
filter_index(
interfaces::MakeChain
(test_setup->m_node),
BlockFilterType::BASIC
,
50
/*n_cache_size=*/
0,
/*f_memory=*/
false
,
/*f_wipe=*/
true
);
51
assert
(filter_index.
Init
());
52
assert
(!filter_index.BlockUntilSyncedToCurrentChain());
53
filter_index.
Sync
();
54
55
IndexSummary
summary = filter_index.
GetSummary
();
56
assert
(summary.
synced
);
57
assert
(summary.
best_block_hash
==
WITH_LOCK
(
::cs_main
,
return
test_setup->m_node.chainman->ActiveTip()->GetBlockHash()));
58
59
// Shutdown sequence (c.f. Shutdown() in init.cpp)
60
filter_index.
Stop
();
61
});
62
}
63
64
BENCHMARK
(
BlockFilterIndexSync
);
GetScriptForDestination
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition
addresstype.cpp:166
addresstype.h
base.h
bench.h
BENCHMARK
#define BENCHMARK(n)
Definition
bench.h:69
block.h
BlockFilterType::BASIC
@ BASIC
Definition
blockfilter.h:95
blockfilterindex.h
check.h
BaseIndex::Stop
void Stop()
Stops the instance from staying in sync with blockchain updates.
Definition
base.cpp:477
BaseIndex::Init
bool Init()
Initializes the sync state and registers the instance to the validation interface so that it stays in...
Definition
base.cpp:105
BaseIndex::GetSummary
IndexSummary GetSummary() const
Get a summary of the index and its state.
Definition
base.cpp:488
BaseIndex::Sync
void Sync()
Sync the index with the block index starting from the current best block.
Definition
base.cpp:208
BlockFilterIndex
BlockFilterIndex is used to store and retrieve block filters, hashes, and headers for a range of bloc...
Definition
blockfilterindex.h:41
CPubKey
An encapsulated public key.
Definition
pubkey.h:40
CScript
Serialized script, used inside transaction inputs and outputs.
Definition
script.h:406
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:649
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition
nanobench.h:1308
ankerl::nanobench::Bench::minEpochIterations
ANKERL_NANOBENCH(NODISCARD) std Bench & minEpochIterations(uint64_t numIters) noexcept
Sets the minimum number of iterations each epoch should take.
cs_main
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition
cs_main.cpp:8
BlockFilterIndexSync
static void BlockFilterIndexSync(benchmark::Bench &bench)
Definition
index_blockfilter.cpp:33
chain.h
chain.h
interfaces::MakeChain
std::unique_ptr< Chain > MakeChain(node::NodeContext &node)
Return implementation of Chain interface.
Definition
interfaces.cpp:1088
script
Definition
parsing.cpp:11
util::hex_literals
""_hex is a compile-time user-defined literal returning a std::array<std::byte>, equivalent to ParseH...
Definition
strencodings.h:386
transaction.h
pubkey.h
script.h
setup_common.h
MakeNoLogFileContext
std::unique_ptr< T > MakeNoLogFileContext(const ChainType chain_type=ChainType::REGTEST, TestOpts opts={})
Make a test setup that has disk access to the debug.log file disabled.
Definition
setup_common.h:241
strencodings.h
IndexSummary
Definition
base.h:30
IndexSummary::synced
bool synced
Definition
base.h:32
IndexSummary::best_block_hash
uint256 best_block_hash
Definition
base.h:34
WitnessV0KeyHash::WitnessV0KeyHash
WitnessV0KeyHash()
Definition
addresstype.h:81
sync.h
WITH_LOCK
#define WITH_LOCK(cs, code)
Definition
sync.h:299
time.h
uint256.h
assert
assert(!tx.IsCoinBase())
Generated on
for Bitcoin Core by
1.18.0