Bitcoin Core  27.99.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 #if defined(HAVE_CONFIG_H)
7 #endif
8 
9 #include <bench/bench.h>
10 #include <node/context.h>
11 #include <random.h>
12 #include <test/util/setup_common.h>
13 #include <wallet/context.h>
14 #include <wallet/wallet.h>
15 
16 namespace wallet {
17 static void WalletCreate(benchmark::Bench& bench, bool encrypted)
18 {
19  auto test_setup = MakeNoLogFileContext<TestingSetup>();
20  FastRandomContext random;
21 
22  WalletContext context;
23  context.args = &test_setup->m_args;
24  context.chain = test_setup->m_node.chain.get();
25 
26  DatabaseOptions options;
28  options.require_create = true;
30 
31  if (encrypted) {
32  options.create_passphrase = random.rand256().ToString();
33  }
34 
35  DatabaseStatus status;
36  bilingual_str error_string;
37  std::vector<bilingual_str> warnings;
38 
39  fs::path wallet_path = test_setup->m_path_root / strprintf("test_wallet_%d", random.rand32()).c_str();
40  bench.run([&] {
41  auto wallet = CreateWallet(context, wallet_path.utf8string(), /*load_on_start=*/std::nullopt, options, status, error_string, warnings);
43  assert(wallet != nullptr);
44 
45  // Cleanup
46  wallet.reset();
47  fs::remove_all(wallet_path);
48  });
49 }
50 
51 static void WalletCreatePlain(benchmark::Bench& bench) { WalletCreate(bench, /*encrypted=*/false); }
52 static void WalletCreateEncrypted(benchmark::Bench& bench) { WalletCreate(bench, /*encrypted=*/true); }
53 
54 #ifdef USE_SQLITE
57 #endif
58 
59 } // namespace wallet
Fast randomness source.
Definition: random.h:145
uint32_t rand32() noexcept
Generate a random 32-bit integer.
Definition: random.h:222
uint256 rand256() noexcept
generate a random uint256.
Definition: random.cpp:664
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
std::string ToString() const
Definition: uint256.cpp:55
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:33
std::string utf8string() const
Return a UTF-8 representation of the path as a std::string, for compatibility with code using std::st...
Definition: fs.h:63
@ LOW
Definition: bench.h:46
static void WalletCreate(benchmark::Bench &bench, bool encrypted)
BENCHMARK(WalletBalanceDirty, benchmark::PriorityLevel::HIGH)
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:373
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition: walletutil.h:74
static void WalletCreatePlain(benchmark::Bench &bench)
DatabaseStatus
Definition: db.h:196
static void WalletCreateEncrypted(benchmark::Bench &bench)
Bilingual messages:
Definition: translation.h:18
SecureString create_passphrase
Definition: db.h:187
std::optional< DatabaseFormat > require_format
Definition: db.h:185
uint64_t create_flags
Definition: db.h:186
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
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1162
assert(!tx.IsCoinBase())