Bitcoin Core  31.0.0
P2P Digital Currency
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 <bench/bench.h>
6 #include <random.h>
9 #include <uint256.h>
10 #include <util/fs.h>
11 #include <util/translation.h>
12 #include <wallet/context.h>
13 #include <wallet/db.h>
14 #include <wallet/wallet.h>
15 #include <wallet/walletutil.h>
16 
17 #include <cassert>
18 #include <memory>
19 #include <optional>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
24 namespace wallet {
25 static void WalletCreate(benchmark::Bench& bench, bool encrypted)
26 {
27  auto test_setup = MakeNoLogFileContext<TestingSetup>();
28  FastRandomContext random;
29 
30  WalletContext context;
31  context.args = &test_setup->m_args;
32  context.chain = test_setup->m_node.chain.get();
33 
34  DatabaseOptions options;
36  options.require_create = true;
38 
39  if (encrypted) {
40  options.create_passphrase = random.rand256().ToString();
41  }
42 
43  DatabaseStatus status;
44  bilingual_str error_string;
45  std::vector<bilingual_str> warnings;
46 
47  auto wallet_path = fs::PathToString(test_setup->m_path_root / "test_wallet");
48  bench.run([&] {
49  auto wallet = CreateWallet(context, wallet_path, /*load_on_start=*/std::nullopt, options, status, error_string, warnings);
51  assert(wallet != nullptr);
52 
53  // Release wallet
54  RemoveWallet(context, wallet, /*load_on_start=*/ std::nullopt);
55  WaitForDeleteWallet(std::move(wallet));
56  fs::remove_all(wallet_path);
57  });
58 }
59 
60 static void WalletCreatePlain(benchmark::Bench& bench) { WalletCreate(bench, /*encrypted=*/false); }
61 static void WalletCreateEncrypted(benchmark::Bench& bench) { WalletCreate(bench, /*encrypted=*/true); }
62 
65 
66 } // namespace wallet
std::optional< DatabaseFormat > require_format
Definition: db.h:175
assert(!tx.IsCoinBase())
Bilingual messages:
Definition: translation.h:24
void WaitForDeleteWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly delete the wallet.
Definition: wallet.cpp:254
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1234
SecureString create_passphrase
Definition: db.h:177
uint64_t create_flags
Definition: db.h:176
Fast randomness source.
Definition: random.h:385
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition: walletutil.h:53
BENCHMARK(WalletBalanceDirty)
static void WalletCreate(benchmark::Bench &bench, bool encrypted)
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:163
DatabaseStatus
Definition: db.h:186
static std::string PathToString(const path &path)
Convert path object to a byte string.
Definition: fs.h:157
WalletContext struct containing references to state shared between CWallet instances, like the reference to the chain interface, and the list of opened wallets.
Definition: context.h:36
interfaces::Chain * chain
Definition: context.h:37
Main entry point to nanobench&#39;s benchmarking facility.
Definition: nanobench.h:627
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:377
static void WalletCreateEncrypted(benchmark::Bench &bench)
ArgsManager * args
Definition: context.h:39
static void WalletCreatePlain(benchmark::Bench &bench)