Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
bench
wallet_loading.cpp
Go to the documentation of this file.
1
// Copyright (c) 2022-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#include <
addresstype.h
>
6
#include <
bench/bench.h
>
7
#include <
consensus/amount.h
>
8
#include <
outputtype.h
>
9
#include <
primitives/transaction.h
>
10
#include <
script/script.h
>
11
#include <
test/util/setup_common.h
>
12
#include <
util/check.h
>
13
#include <
util/translation.h
>
14
#include <
wallet/context.h
>
15
#include <
wallet/db.h
>
16
#include <
wallet/test/util.h
>
17
#include <
wallet/transaction.h
>
18
#include <
wallet/wallet.h
>
19
#include <
wallet/walletutil.h
>
20
21
#include <cstdint>
22
#include <memory>
23
#include <optional>
24
#include <string>
25
#include <utility>
26
#include <vector>
27
28
namespace
wallet
{
29
static
void
AddTx
(
CWallet
&
wallet
)
30
{
31
CMutableTransaction
mtx;
32
mtx.
vout
.emplace_back(
COIN
,
GetScriptForDestination
(*
Assert
(
wallet
.GetNewDestination(
OutputType::BECH32
,
""
))));
33
mtx.
vin
.emplace_back();
34
35
wallet
.AddToWallet(MakeTransactionRef(mtx),
TxStateInactive
{});
36
}
37
38
static
void
WalletLoadingDescriptors
(
benchmark::Bench
& bench)
39
{
40
const
auto
test_setup =
MakeNoLogFileContext<TestingSetup>
();
41
42
WalletContext
context;
43
context.
args
= &test_setup->m_args;
44
context.
chain
= test_setup->m_node.chain.get();
45
46
// Setup the wallet
47
// Loading the wallet will also create it
48
uint64_t create_flags =
WALLET_FLAG_DESCRIPTORS
;
49
DatabaseStatus
status;
50
DatabaseOptions
options;
51
options.
require_format
=
DatabaseFormat::SQLITE
;
52
options.
require_create
=
true
;
53
bilingual_str
error;
54
auto
database =
MakeWalletDatabase
(
""
, options, status, error);
55
auto
wallet
=
TestCreateWallet
(std::move(database), context, create_flags);
56
57
// Generate a bunch of transactions and addresses to put into the wallet
58
for
(
int
i = 0; i < 1000; ++i) {
59
AddTx
(*
wallet
);
60
}
61
62
options.
require_create
=
false
;
63
options.
require_existing
=
true
;
64
65
bench.
epochs
(5)
66
.
setup
([&] {
67
TestUnloadWallet
(std::move(
wallet
));
68
database =
MakeWalletDatabase
(
""
, options, status, error);
69
})
70
.run([&] {
71
wallet
=
TestLoadWallet
(std::move(database), context);
72
});
73
74
// Cleanup
75
TestUnloadWallet
(std::move(
wallet
));
76
}
77
78
BENCHMARK
(
WalletLoadingDescriptors
);
79
}
// namespace wallet
GetScriptForDestination
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition
addresstype.cpp:166
addresstype.h
amount.h
COIN
constexpr CAmount COIN
The amount of satoshis in one BTC.
Definition
amount.h:15
bench.h
check.h
Assert
#define Assert(val)
Identity function.
Definition
check.h:116
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:649
ankerl::nanobench::Bench::epochs
Bench & epochs(size_t numEpochs) noexcept
Controls number of epochs, the number of measurements to perform.
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
wallet::CWallet
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition
wallet.h:310
db.h
wallet
Definition
coin_selection.cpp:31
wallet::DatabaseFormat::SQLITE
@ SQLITE
Definition
db.h:164
wallet::TestUnloadWallet
void TestUnloadWallet(std::shared_ptr< CWallet > &&wallet)
Definition
util.cpp:97
wallet::AddTx
static void AddTx(CWallet &wallet)
Definition
wallet_loading.cpp:29
wallet::MakeWalletDatabase
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error_string)
Definition
wallet.cpp:2996
wallet::BENCHMARK
BENCHMARK(CoinSelection)
wallet::TestLoadWallet
std::shared_ptr< CWallet > TestLoadWallet(std::unique_ptr< WalletDatabase > database, WalletContext &context)
Definition
util.cpp:75
wallet::TestCreateWallet
std::shared_ptr< CWallet > TestCreateWallet(std::unique_ptr< WalletDatabase > database, WalletContext &context, uint64_t create_flags)
Definition
util.cpp:51
wallet::WALLET_FLAG_DESCRIPTORS
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition
walletutil.h:53
wallet::WalletLoadingDescriptors
static void WalletLoadingDescriptors(benchmark::Bench &bench)
Definition
wallet_loading.cpp:38
wallet::DatabaseStatus
DatabaseStatus
Definition
db.h:180
outputtype.h
OutputType::BECH32
@ BECH32
Definition
outputtype.h:21
transaction.h
script.h
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
CMutableTransaction
A mutable version of CTransaction.
Definition
transaction.h:372
CMutableTransaction::vout
std::vector< CTxOut > vout
Definition
transaction.h:374
CMutableTransaction::vin
std::vector< CTxIn > vin
Definition
transaction.h:373
bilingual_str
Bilingual messages:
Definition
translation.h:24
wallet::DatabaseOptions
Definition
db.h:168
wallet::DatabaseOptions::require_existing
bool require_existing
Definition
db.h:169
wallet::DatabaseOptions::require_create
bool require_create
Definition
db.h:170
wallet::DatabaseOptions::require_format
std::optional< DatabaseFormat > require_format
Definition
db.h:171
wallet::TxStateInactive
Definition
transaction.h:61
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
context.h
util.h
transaction.h
wallet.h
walletutil.h
Generated on
for Bitcoin Core by
1.18.0