Bitcoin Core
31.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 <
test/util/setup_common.h
>
11
#include <
util/check.h
>
12
#include <
wallet/context.h
>
13
#include <
wallet/db.h
>
14
#include <
wallet/test/util.h
>
15
#include <
wallet/transaction.h
>
16
#include <
wallet/wallet.h
>
17
#include <
wallet/walletutil.h
>
18
19
#include <cstdint>
20
#include <memory>
21
#include <utility>
22
#include <vector>
23
24
namespace
wallet
{
25
static
void
AddTx
(
CWallet
&
wallet
)
26
{
27
CMutableTransaction
mtx;
28
mtx.
vout
.emplace_back(
COIN
,
GetScriptForDestination
(*
Assert
(
wallet
.GetNewDestination(
OutputType::BECH32
,
""
))));
29
mtx.
vin
.emplace_back();
30
31
wallet
.AddToWallet(
MakeTransactionRef
(mtx),
TxStateInactive
{});
32
}
33
34
static
void
WalletLoadingDescriptors
(
benchmark::Bench
& bench)
35
{
36
const
auto
test_setup =
MakeNoLogFileContext<TestingSetup>
();
37
38
WalletContext
context;
39
context.
args
= &test_setup->m_args;
40
context.
chain
= test_setup->m_node.chain.get();
41
42
// Setup the wallet
43
// Loading the wallet will also create it
44
uint64_t create_flags =
WALLET_FLAG_DESCRIPTORS
;
45
auto
database =
CreateMockableWalletDatabase
();
46
auto
wallet
=
TestCreateWallet
(std::move(database), context, create_flags);
47
48
// Generate a bunch of transactions and addresses to put into the wallet
49
for
(
int
i = 0; i < 1000; ++i) {
50
AddTx
(*
wallet
);
51
}
52
53
database =
DuplicateMockDatabase
(
wallet
->GetDatabase());
54
55
// reload the wallet for the actual benchmark
56
TestUnloadWallet
(std::move(
wallet
));
57
58
bench.
epochs
(5).
run
([&] {
59
wallet
=
TestLoadWallet
(std::move(database), context);
60
61
// Cleanup
62
database =
DuplicateMockDatabase
(
wallet
->GetDatabase());
63
TestUnloadWallet
(std::move(
wallet
));
64
});
65
}
66
67
BENCHMARK
(
WalletLoadingDescriptors
);
68
}
// 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
static constexpr CAmount COIN
The amount of satoshis in one BTC.
Definition
amount.h:15
bench.h
BENCHMARK
#define BENCHMARK(n)
Definition
bench.h:68
check.h
Assert
#define Assert(val)
Identity function.
Definition
check.h:113
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:627
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition
nanobench.h:1234
ankerl::nanobench::Bench::epochs
Bench & epochs(size_t numEpochs) noexcept
Controls number of epochs, the number of measurements to perform.
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
wallet_balance.cpp:26
wallet::TestUnloadWallet
void TestUnloadWallet(std::shared_ptr< CWallet > &&wallet)
Definition
util.cpp:98
wallet::AddTx
static void AddTx(CWallet &wallet)
Definition
wallet_loading.cpp:25
wallet::CreateMockableWalletDatabase
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase(MockableData records)
Definition
util.cpp:211
wallet::DuplicateMockDatabase
std::unique_ptr< WalletDatabase > DuplicateMockDatabase(WalletDatabase &database)
Definition
util.cpp:106
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:50
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:34
outputtype.h
OutputType::BECH32
@ BECH32
Definition
outputtype.h:21
transaction.h
MakeTransactionRef
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition
transaction.h:404
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:250
CMutableTransaction
A mutable version of CTransaction.
Definition
transaction.h:358
CMutableTransaction::vout
std::vector< CTxOut > vout
Definition
transaction.h:360
CMutableTransaction::vin
std::vector< CTxIn > vin
Definition
transaction.h:359
wallet::TxStateInactive
Definition
transaction.h:59
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
context.h
util.h
transaction.h
wallet.h
walletutil.h
Generated on
for Bitcoin Core by
1.17.0