Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
bench
wallet_balance.cpp
Go to the documentation of this file.
1
// Copyright (c) 2012-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 <
bench/bench.h
>
6
#include <
interfaces/chain.h
>
7
#include <
kernel/chainparams.h
>
8
#include <
primitives/block.h
>
9
#include <
primitives/transaction.h
>
10
#include <
sync.h
>
11
#include <
test/util/mining.h
>
12
#include <
test/util/setup_common.h
>
13
#include <
uint256.h
>
14
#include <util/time.h>
15
#include <validation.h>
16
#include <
wallet/receive.h
>
17
#include <
wallet/test/util.h
>
18
#include <
wallet/wallet.h
>
19
#include <
wallet/walletutil.h
>
20
21
#include <cassert>
22
#include <memory>
23
#include <optional>
24
#include <string>
25
26
namespace
wallet
{
27
static
void
WalletBalance
(
benchmark::Bench
& bench,
const
bool
set_dirty,
const
bool
add_mine)
28
{
29
const
auto
test_setup =
MakeNoLogFileContext<const TestingSetup>
();
30
31
const
auto
& ADDRESS_WATCHONLY =
ADDRESS_BCRT1_UNSPENDABLE
;
32
33
// Set clock to genesis block, so the descriptors/keys creation time don't interfere with the blocks scanning process.
34
// The reason is 'generatetoaddress', which creates a chain with deterministic timestamps in the past.
35
SetMockTime
(test_setup->m_node.chainman->GetParams().GenesisBlock().nTime);
36
CWallet
wallet
{test_setup->m_node.chain.get(),
""
,
CreateMockableWalletDatabase
()};
37
{
38
LOCK
(
wallet
.cs_wallet);
39
wallet
.SetWalletFlag(
WALLET_FLAG_DESCRIPTORS
);
40
wallet
.SetupDescriptorScriptPubKeyMans();
41
}
42
auto
handler
= test_setup->m_node.chain->handleNotifications({&
wallet
, [](
CWallet
*) {}});
43
44
const
std::optional<std::string> address_mine{add_mine ? std::optional<std::string>{
getnewaddress
(
wallet
)} : std::nullopt};
45
46
for
(
int
i = 0; i < 100; ++i) {
47
generatetoaddress
(test_setup->m_node, address_mine.value_or(ADDRESS_WATCHONLY));
48
generatetoaddress
(test_setup->m_node, ADDRESS_WATCHONLY);
49
}
50
// Calls SyncWithValidationInterfaceQueue
51
wallet
.chain().waitForNotificationsIfTipChanged(
uint256::ZERO
);
52
53
auto
bal =
GetBalance
(
wallet
);
// Cache
54
55
bench.
run
([&] {
56
if
(set_dirty)
wallet
.MarkDirty();
57
bal =
GetBalance
(
wallet
);
58
if
(add_mine)
assert
(bal.m_mine_trusted > 0);
59
});
60
}
61
62
static
void
WalletBalanceDirty
(
benchmark::Bench
& bench) {
WalletBalance
(bench,
/*set_dirty=*/
true
,
/*add_mine=*/
true
); }
63
static
void
WalletBalanceClean
(
benchmark::Bench
& bench) {
WalletBalance
(bench,
/*set_dirty=*/
false
,
/*add_mine=*/
true
); }
64
static
void
WalletBalanceMine
(
benchmark::Bench
& bench) {
WalletBalance
(bench,
/*set_dirty=*/
false
,
/*add_mine=*/
true
); }
65
static
void
WalletBalanceWatch
(
benchmark::Bench
& bench) {
WalletBalance
(bench,
/*set_dirty=*/
false
,
/*add_mine=*/
false
); }
66
67
BENCHMARK
(
WalletBalanceDirty
);
68
BENCHMARK
(
WalletBalanceClean
);
69
BENCHMARK
(
WalletBalanceMine
);
70
BENCHMARK
(
WalletBalanceWatch
);
71
}
// namespace wallet
bench.h
BENCHMARK
#define BENCHMARK(n)
Definition
bench.h:68
block.h
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
uint256::ZERO
static const uint256 ZERO
Definition
uint256.h:203
wallet::CWallet
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition
wallet.h:310
chain.h
chainparams.h
wallet
Definition
wallet_balance.cpp:26
wallet::GetBalance
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
Definition
receive.cpp:245
wallet::ADDRESS_BCRT1_UNSPENDABLE
const std::string ADDRESS_BCRT1_UNSPENDABLE
Definition
util.h:31
wallet::WalletBalanceDirty
static void WalletBalanceDirty(benchmark::Bench &bench)
Definition
wallet_balance.cpp:62
wallet::CreateMockableWalletDatabase
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase(MockableData records)
Definition
util.cpp:211
wallet::WalletBalance
static void WalletBalance(benchmark::Bench &bench, const bool set_dirty, const bool add_mine)
Definition
wallet_balance.cpp:27
wallet::WalletBalanceWatch
static void WalletBalanceWatch(benchmark::Bench &bench)
Definition
wallet_balance.cpp:65
wallet::WALLET_FLAG_DESCRIPTORS
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition
walletutil.h:53
wallet::getnewaddress
RPCHelpMan getnewaddress()
Definition
addresses.cpp:21
wallet::WalletBalanceMine
static void WalletBalanceMine(benchmark::Bench &bench)
Definition
wallet_balance.cpp:64
wallet::WalletBalanceClean
static void WalletBalanceClean(benchmark::Bench &bench)
Definition
wallet_balance.cpp:63
transaction.h
receive.h
handler
bool(* handler)(const std::any &context, HTTPRequest *req, const std::string &strReq)
Definition
rest.cpp:1142
generatetoaddress
static RPCHelpMan generatetoaddress()
Definition
mining.cpp:264
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
sync.h
LOCK
#define LOCK(cs)
Definition
sync.h:258
mining.h
uint256.h
SetMockTime
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition
time.cpp:44
assert
assert(!tx.IsCoinBase())
util.h
wallet.h
walletutil.h
Generated on
for Bitcoin Core by
1.17.0