Bitcoin Core
31.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 <
span.h
>
17
#include <
sync.h
>
18
#include <
test/util/setup_common.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
28
using namespace
util::hex_literals
;
29
30
// Very simple block filter index sync benchmark, only using coinbase outputs.
31
static
void
BlockFilterIndexSync
(
benchmark::Bench
& bench)
32
{
33
const
auto
test_setup =
MakeNoLogFileContext<TestChain100Setup>
();
34
35
// Create more blocks
36
int
CHAIN_SIZE = 600;
37
CPubKey
pubkey{
"02ed26169896db86ced4cbb7b3ecef9859b5952825adbeab998fb5b307e54949c9"
_hex_u8};
38
CScript
script
=
GetScriptForDestination
(
WitnessV0KeyHash
(pubkey));
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
// Shutdown sequence (c.f. Shutdown() in init.cpp)
58
filter_index.
Stop
();
59
});
60
}
61
62
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:68
block.h
BlockFilterType::BASIC
@ BASIC
Definition
blockfilter.h:95
blockfilterindex.h
BaseIndex::Stop
void Stop()
Stops the instance from staying in sync with blockchain updates.
Definition
base.cpp:461
BaseIndex::Init
bool Init()
Initializes the sync state and registers the instance to the validation interface so that it stays in...
Definition
base.cpp:104
BaseIndex::GetSummary
IndexSummary GetSummary() const
Get a summary of the index and its state.
Definition
base.cpp:472
BaseIndex::Sync
void Sync()
Sync the index with the block index starting from the current best block.
Definition
base.cpp:201
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:34
CScript
Serialized script, used inside transaction inputs and outputs.
Definition
script.h:405
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:627
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition
nanobench.h:1234
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:31
chain.h
chain.h
interfaces::MakeChain
std::unique_ptr< Chain > MakeChain(node::NodeContext &node)
Return implementation of Chain interface.
Definition
interfaces.cpp:1023
script
Definition
parsing.cpp:13
util::hex_literals
""_hex is a compile-time user-defined literal returning a std::array<std::byte>, equivalent to ParseH...
Definition
strencodings.h:400
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:250
span.h
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
Definition
addresstype.h:80
sync.h
WITH_LOCK
#define WITH_LOCK(cs, code)
Definition
sync.h:289
uint256.h
GetTime
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
Definition
time.cpp:81
SetMockTime
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition
time.cpp:44
assert
assert(!tx.IsCoinBase())
Generated on
for Bitcoin Core by
1.17.0