Skip to content

Commit 78de5a4

Browse files
committed
bench: basic block filter index initial sync
1 parent 0f1cf9b commit 78de5a4

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/Makefile.bench.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ bench_bench_bitcoin_SOURCES = \
3434
bench/examples.cpp \
3535
bench/gcs_filter.cpp \
3636
bench/hashpadding.cpp \
37+
bench/index_blockfilter.cpp \
3738
bench/load_external.cpp \
3839
bench/lockedpool.cpp \
3940
bench/logging.cpp \

src/bench/index_blockfilter.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
#include <addresstype.h>
7+
#include <index/blockfilterindex.h>
8+
#include <node/chainstate.h>
9+
#include <node/context.h>
10+
#include <test/util/index.h>
11+
#include <test/util/mining.h>
12+
#include <test/util/setup_common.h>
13+
#include <util/strencodings.h>
14+
15+
// Very simple block filter index sync benchmark, only using coinbase outputs.
16+
static void BlockFilterIndexSync(benchmark::Bench& bench)
17+
{
18+
const auto test_setup = MakeNoLogFileContext<TestChain100Setup>();
19+
20+
// Create more blocks
21+
int CHAIN_SIZE = 600;
22+
CPubKey pubkey{ParseHex("02ed26169896db86ced4cbb7b3ecef9859b5952825adbeab998fb5b307e54949c9")};
23+
CScript script = GetScriptForDestination(WitnessV0KeyHash(pubkey));
24+
std::vector<CMutableTransaction> noTxns;
25+
for (int i = 0; i < CHAIN_SIZE - 100; i++) {
26+
test_setup->CreateAndProcessBlock(noTxns, script);
27+
SetMockTime(GetTime() + 1);
28+
}
29+
assert(WITH_LOCK(::cs_main, return test_setup->m_node.chainman->ActiveHeight() == CHAIN_SIZE));
30+
31+
bench.minEpochIterations(5).run([&] {
32+
BlockFilterIndex filter_index(interfaces::MakeChain(test_setup->m_node), BlockFilterType::BASIC,
33+
/*n_cache_size=*/0, /*f_memory=*/false, /*f_wipe=*/true);
34+
assert(filter_index.Init());
35+
assert(!filter_index.BlockUntilSyncedToCurrentChain());
36+
filter_index.Sync();
37+
38+
IndexSummary summary = filter_index.GetSummary();
39+
assert(summary.synced);
40+
assert(summary.best_block_hash == WITH_LOCK(::cs_main, return test_setup->m_node.chainman->ActiveTip()->GetBlockHash()));
41+
});
42+
}
43+
44+
BENCHMARK(BlockFilterIndexSync, benchmark::PriorityLevel::HIGH);

0 commit comments

Comments
 (0)