Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
bench
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>
7
#include <
test/util/setup_common.h
>
8
#include <
uint256.h
>
9
#include <
util/check.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 <memory>
18
#include <optional>
19
#include <string>
20
#include <utility>
21
#include <vector>
22
23
namespace
wallet
{
24
static
void
WalletCreate
(
benchmark::Bench
& bench,
bool
encrypted)
25
{
26
auto
test_setup =
MakeNoLogFileContext<TestingSetup>
();
27
FastRandomContext
random;
28
29
WalletContext
context;
30
context.
args
= &test_setup->m_args;
31
context.
chain
= test_setup->m_node.chain.get();
32
33
DatabaseOptions
options;
34
options.
require_format
=
DatabaseFormat::SQLITE
;
35
options.
require_create
=
true
;
36
options.
create_flags
=
WALLET_FLAG_DESCRIPTORS
;
37
38
if
(encrypted) {
39
options.
create_passphrase
= random.
rand256
().
ToString
();
40
}
41
42
DatabaseStatus
status;
43
bilingual_str
error_string;
44
std::vector<bilingual_str> warnings;
45
46
const
auto
wallet_path = test_setup->m_path_root /
"test_wallet"
;
47
const
auto
wallet_name = fs::PathToString(wallet_path);
48
49
std::shared_ptr<CWallet>
wallet
;
50
auto
cleanup{[&] {
51
if
(!
wallet
)
return
;
52
// Release wallet
53
RemoveWallet
(context,
wallet
,
/*load_on_start=*/
std::nullopt);
54
WaitForDeleteWallet
(std::move(
wallet
));
55
fs::remove(wallet_path /
"wallet.dat"
);
56
fs::remove(wallet_path);
57
}};
58
bench.
setup
(cleanup).run([&] {
59
wallet
=
CreateWallet
(context, wallet_name,
/*load_on_start=*/
std::nullopt, options, status, error_string, warnings);
60
assert
(status ==
DatabaseStatus::SUCCESS
);
61
assert
(
wallet
!=
nullptr
);
62
});
63
cleanup();
64
}
65
66
static
void
WalletCreatePlain
(
benchmark::Bench
& bench) {
WalletCreate
(bench,
/*encrypted=*/
false
); }
67
static
void
WalletCreateEncrypted
(
benchmark::Bench
& bench) {
WalletCreate
(bench,
/*encrypted=*/
true
); }
68
69
BENCHMARK
(
WalletCreatePlain
);
70
BENCHMARK
(
WalletCreateEncrypted
);
71
72
}
// namespace wallet
bench.h
check.h
FastRandomContext
Fast randomness source.
Definition
random.h:386
RandomMixin::rand256
uint256 rand256() noexcept
generate a random uint256.
Definition
random.h:317
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:649
ankerl::nanobench::Bench::setup
detail::SetupRunner< SetupOp > setup(SetupOp setupOp)
Configure an untimed setup step per epoch (forces single-iteration epochs).
Definition
nanobench.h:1302
base_blob::ToString
std::string ToString() const
Definition
uint256.cpp:21
db.h
fs.h
wallet
Definition
coin_selection.cpp:31
wallet::WalletCreate
static void WalletCreate(benchmark::Bench &bench, bool encrypted)
Definition
wallet_create.cpp:24
wallet::DatabaseFormat::SQLITE
@ SQLITE
Definition
db.h:164
wallet::BENCHMARK
BENCHMARK(CoinSelection)
wallet::CreateWallet
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:387
wallet::WALLET_FLAG_DESCRIPTORS
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition
walletutil.h:53
wallet::WaitForDeleteWallet
void WaitForDeleteWallet(std::shared_ptr< CWallet > &&wallet)
Definition
wallet.cpp:264
wallet::WalletCreatePlain
static void WalletCreatePlain(benchmark::Bench &bench)
Definition
wallet_create.cpp:66
wallet::DatabaseStatus
DatabaseStatus
Definition
db.h:180
wallet::DatabaseStatus::SUCCESS
@ SUCCESS
Definition
db.h:181
wallet::RemoveWallet
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Definition
wallet.cpp:173
wallet::WalletCreateEncrypted
static void WalletCreateEncrypted(benchmark::Bench &bench)
Definition
wallet_create.cpp:67
setup_common.h
MakeNoLogFileContext
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.
Definition
setup_common.h:241
bilingual_str
Bilingual messages:
Definition
translation.h:24
wallet::DatabaseOptions
Definition
db.h:168
wallet::DatabaseOptions::require_create
bool require_create
Definition
db.h:170
wallet::DatabaseOptions::create_passphrase
SecureString create_passphrase
Definition
db.h:173
wallet::DatabaseOptions::require_format
std::optional< DatabaseFormat > require_format
Definition
db.h:171
wallet::DatabaseOptions::create_flags
uint64_t create_flags
Definition
db.h:172
wallet::WalletContext
Definition
context.h:36
wallet::WalletContext::chain
interfaces::Chain * chain
Definition
context.h:37
wallet::WalletContext::args
ArgsManager * args
Definition
context.h:39
translation.h
uint256.h
assert
assert(!tx.IsCoinBase())
context.h
wallet.h
walletutil.h
Generated on
for Bitcoin Core by
1.18.0