Skip to content

Commit e2eb625

Browse files
committed
partial bitcoin#28894: batch all individual spkms setup db writes in a single db txn
includes: - bb4554c
1 parent f29610b commit e2eb625

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/Makefile.bench.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ endif
8383
if ENABLE_WALLET
8484
bench_bench_dash_SOURCES += bench/coin_selection.cpp
8585
bench_bench_dash_SOURCES += bench/wallet_balance.cpp
86+
bench_bench_dash_SOURCES += bench/wallet_create.cpp
8687
endif
8788

8889
bench_bench_dash_LDADD += $(BACKTRACE_LIB) $(BDB_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(SQLITE_LIBS) $(GMP_LIBS)

src/bench/wallet_create.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 <node/context.h>
7+
#include <random.h>
8+
#include <test/util/setup_common.h>
9+
#include <util/translation.h>
10+
#include <wallet/context.h>
11+
#include <wallet/wallet.h>
12+
13+
namespace wallet {
14+
static void WalletCreate(benchmark::Bench& bench, bool encrypted)
15+
{
16+
auto test_setup = MakeNoLogFileContext<TestingSetup>();
17+
FastRandomContext random;
18+
19+
WalletContext context;
20+
context.args = &test_setup->m_args;
21+
context.chain = test_setup->m_node.chain.get();
22+
23+
DatabaseOptions options;
24+
options.require_format = DatabaseFormat::SQLITE;
25+
options.require_create = true;
26+
options.create_flags = WALLET_FLAG_DESCRIPTORS;
27+
28+
if (encrypted) {
29+
options.create_passphrase = random.rand256().ToString();
30+
}
31+
32+
DatabaseStatus status;
33+
bilingual_str error_string;
34+
std::vector<bilingual_str> warnings;
35+
36+
fs::path wallet_path = test_setup->m_path_root / strprintf("test_wallet_%d", random.rand32()).c_str();
37+
bench.run([&] {
38+
auto wallet = CreateWallet(context, wallet_path.u8string(), /*load_on_start=*/std::nullopt, options, status, error_string, warnings);
39+
assert(status == DatabaseStatus::SUCCESS);
40+
assert(wallet != nullptr);
41+
42+
// Cleanup
43+
wallet.reset();
44+
fs::remove_all(wallet_path);
45+
});
46+
}
47+
48+
static void WalletCreatePlain(benchmark::Bench& bench) { WalletCreate(bench, /*encrypted=*/false); }
49+
static void WalletCreateEncrypted(benchmark::Bench& bench) { WalletCreate(bench, /*encrypted=*/true); }
50+
51+
#ifdef USE_SQLITE
52+
BENCHMARK(WalletCreatePlain);
53+
BENCHMARK(WalletCreateEncrypted);
54+
#endif
55+
56+
} // namespace wallet

0 commit comments

Comments
 (0)