Bitcoin Core 28.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
wallet_create.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 <config/bitcoin-config.h> // IWYU pragma: keep
6
7#include <bench/bench.h>
8#include <node/context.h>
9#include <random.h>
11#include <wallet/context.h>
12#include <wallet/wallet.h>
13
14namespace wallet {
15static void WalletCreate(benchmark::Bench& bench, bool encrypted)
16{
17 auto test_setup = MakeNoLogFileContext<TestingSetup>();
18 FastRandomContext random;
19
20 WalletContext context;
21 context.args = &test_setup->m_args;
22 context.chain = test_setup->m_node.chain.get();
23
24 DatabaseOptions options;
26 options.require_create = true;
28
29 if (encrypted) {
30 options.create_passphrase = random.rand256().ToString();
31 }
32
33 DatabaseStatus status;
34 bilingual_str error_string;
35 std::vector<bilingual_str> warnings;
36
37 auto wallet_path = fs::PathToString(test_setup->m_path_root / "test_wallet");
38 bench.run([&] {
39 auto wallet = CreateWallet(context, wallet_path, /*load_on_start=*/std::nullopt, options, status, error_string, warnings);
41 assert(wallet != nullptr);
42
43 // Release wallet
44 RemoveWallet(context, wallet, /*load_on_start=*/ std::nullopt);
45 WaitForDeleteWallet(std::move(wallet));
46 fs::remove_all(wallet_path);
47 });
48}
49
50static void WalletCreatePlain(benchmark::Bench& bench) { WalletCreate(bench, /*encrypted=*/false); }
51static void WalletCreateEncrypted(benchmark::Bench& bench) { WalletCreate(bench, /*encrypted=*/true); }
52
53#ifdef USE_SQLITE
56#endif
57
58} // namespace wallet
#define BENCHMARK(n, priority_level)
Definition bench.h:79
Fast randomness source.
Definition random.h:377
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
@ LOW
Definition bench.h:46
static std::string PathToString(const path &path)
Convert path object to a byte string.
Definition fs.h:151
static void WalletCreate(benchmark::Bench &bench, bool encrypted)
std::shared_ptr< CWallet > CreateWallet(WalletContext &context, const std::string &name, std::optional< bool > load_on_start, DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
Definition wallet.cpp:383
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition walletutil.h:74
void WaitForDeleteWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly delete the wallet.
Definition wallet.cpp:252
static void WalletCreatePlain(benchmark::Bench &bench)
DatabaseStatus
Definition db.h:204
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Definition wallet.cpp:161
static void WalletCreateEncrypted(benchmark::Bench &bench)
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.
Bilingual messages:
Definition translation.h:18
SecureString create_passphrase
Definition db.h:195
std::optional< DatabaseFormat > require_format
Definition db.h:193
uint64_t create_flags
Definition db.h:194
WalletContext struct containing references to state shared between CWallet instances,...
Definition context.h:36
interfaces::Chain * chain
Definition context.h:37
ArgsManager * args
Definition context.h:39
assert(!tx.IsCoinBase())