Bitcoin Core
32.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 <
interfaces/handler.h
>
8
#include <
kernel/chainparams.h
>
9
#include <
primitives/block.h
>
10
#include <
primitives/transaction.h
>
11
#include <
sync.h
>
12
#include <
test/util/mining.h
>
13
#include <
test/util/setup_common.h
>
14
#include <
test/util/time.h
>
15
#include <
uint256.h
>
16
#include <
util/check.h
>
17
#include <validation.h>
18
#include <
wallet/receive.h
>
19
#include <
wallet/sqlite.h
>
20
#include <
wallet/test/util.h
>
21
#include <
wallet/wallet.h
>
22
#include <
wallet/walletutil.h
>
23
24
#include <memory>
25
#include <optional>
26
#include <string>
27
28
namespace
wallet
{
29
static
void
WalletBalance
(
benchmark::Bench
& bench,
const
bool
set_dirty,
const
bool
add_mine)
30
{
31
const
auto
test_setup =
MakeNoLogFileContext<const TestingSetup>
();
32
33
const
auto
& ADDRESS_WATCHONLY =
ADDRESS_BCRT1_UNSPENDABLE
;
34
35
// Set clock to genesis block, so the descriptors/keys creation time don't interfere with the blocks scanning process.
36
// The reason is 'generatetoaddress', which creates a chain with deterministic timestamps in the past.
37
FakeNodeClock
clock{test_setup->m_node.chainman->GetParams().GenesisBlock().Time()};
38
CWallet
wallet
{test_setup->m_node.chain.get(),
""
,
MakeInMemoryWalletDatabase
()};
39
{
40
LOCK
(
wallet
.cs_wallet);
41
wallet
.SetWalletFlag(
WALLET_FLAG_DESCRIPTORS
);
42
wallet
.SetupDescriptorScriptPubKeyMans();
43
}
44
auto
handler = test_setup->m_node.chain->handleNotifications({&
wallet
, [](
CWallet
*) {}});
45
46
const
std::optional<std::string> address_mine{add_mine ? std::optional<std::string>{
getnewaddress
(
wallet
)} : std::nullopt};
47
48
for
(
int
i = 0; i < 100; ++i) {
49
generatetoaddress
(test_setup->m_node, address_mine.value_or(ADDRESS_WATCHONLY));
50
generatetoaddress
(test_setup->m_node, ADDRESS_WATCHONLY);
51
}
52
// Calls SyncWithValidationInterfaceQueue
53
wallet
.chain().waitForNotificationsIfTipChanged(
uint256::ZERO
);
54
55
auto
bal =
GetBalance
(
wallet
);
// Cache
56
57
bench.
setup
([&] {
58
if
(set_dirty)
wallet
.MarkDirty();
59
})
60
.run([&] {
61
bal =
GetBalance
(
wallet
);
62
ankerl::nanobench::doNotOptimizeAway
(bal);
63
assert
(add_mine == (bal.m_mine_trusted > 0));
64
});
65
}
66
67
static
void
WalletBalanceDirty
(
benchmark::Bench
& bench) {
WalletBalance
(bench,
/*set_dirty=*/
true
,
/*add_mine=*/
true
); }
68
static
void
WalletBalanceClean
(
benchmark::Bench
& bench) {
WalletBalance
(bench,
/*set_dirty=*/
false
,
/*add_mine=*/
true
); }
69
static
void
WalletBalanceWatch
(
benchmark::Bench
& bench) {
WalletBalance
(bench,
/*set_dirty=*/
false
,
/*add_mine=*/
false
); }
70
71
BENCHMARK
(
WalletBalanceDirty
);
72
BENCHMARK
(
WalletBalanceClean
);
73
BENCHMARK
(
WalletBalanceWatch
);
74
}
// namespace wallet
bench.h
block.h
check.h
FakeNodeClock
Helper to initialize the global NodeClock, let a duration elapse, and reset it after use in a test.
Definition
time.h:54
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
uint256::ZERO
static const uint256 ZERO
Definition
uint256.h:204
wallet::CWallet
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition
wallet.h:310
handler.h
chain.h
chainparams.h
ankerl::nanobench::doNotOptimizeAway
void doNotOptimizeAway(Arg &&arg)
Makes sure none of the given arguments are optimized away by the compiler.
Definition
nanobench.h:1353
wallet
Definition
coin_selection.cpp:31
wallet::MakeInMemoryWalletDatabase
std::unique_ptr< WalletDatabase > MakeInMemoryWalletDatabase()
Definition
sqlite.cpp:729
wallet::ADDRESS_BCRT1_UNSPENDABLE
const std::string ADDRESS_BCRT1_UNSPENDABLE
Definition
util.h:32
wallet::WalletBalanceDirty
static void WalletBalanceDirty(benchmark::Bench &bench)
Definition
wallet_balance.cpp:67
wallet::WalletBalance
static void WalletBalance(benchmark::Bench &bench, const bool set_dirty, const bool add_mine)
Definition
wallet_balance.cpp:29
wallet::WalletBalanceWatch
static void WalletBalanceWatch(benchmark::Bench &bench)
Definition
wallet_balance.cpp:69
wallet::BENCHMARK
BENCHMARK(CoinSelection)
wallet::GetBalance
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse, bool include_nonmempool)
Definition
receive.cpp:245
wallet::WALLET_FLAG_DESCRIPTORS
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition
walletutil.h:53
wallet::getnewaddress
RPCMethod getnewaddress()
Definition
addresses.cpp:21
wallet::WalletBalanceClean
static void WalletBalanceClean(benchmark::Bench &bench)
Definition
wallet_balance.cpp:68
transaction.h
receive.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
sqlite.h
sync.h
LOCK
#define LOCK(cs)
Definition
sync.h:268
generatetoaddress
COutPoint generatetoaddress(const NodeContext &node, const std::string &address)
RPC-like helper function, returns the generated coin.
Definition
mining.cpp:34
mining.h
time.h
uint256.h
assert
assert(!tx.IsCoinBase())
util.h
wallet.h
walletutil.h
Generated on
for Bitcoin Core by
1.18.0