Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
bench
wallet_ismine.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 <
key.h
>
8
#include <
key_io.h
>
9
#include <
script/descriptor.h
>
10
#include <
script/script.h
>
11
#include <
script/signingprovider.h
>
12
#include <
sync.h
>
13
#include <
test/util/setup_common.h
>
14
#include <
util/check.h
>
15
#include <
wallet/context.h
>
16
#include <
wallet/db.h
>
17
#include <
wallet/sqlite.h
>
18
#include <
wallet/test/util.h
>
19
#include <
wallet/wallet.h
>
20
#include <
wallet/walletutil.h
>
21
22
#include <cstdint>
23
#include <memory>
24
#include <string>
25
#include <utility>
26
#include <vector>
27
28
namespace
wallet
{
29
static
void
WalletIsMine
(
benchmark::Bench
& bench,
int
num_combo = 0)
30
{
31
const
auto
test_setup =
MakeNoLogFileContext<TestingSetup>
();
32
33
WalletContext
context;
34
context.
args
= &test_setup->m_args;
35
context.
chain
= test_setup->m_node.chain.get();
36
37
// Setup the wallet
38
// Loading the wallet will also create it
39
uint64_t create_flags =
WALLET_FLAG_DESCRIPTORS
;
40
auto
database =
MakeInMemoryWalletDatabase
();
41
auto
wallet
=
TestCreateWallet
(std::move(database), context, create_flags);
42
43
// For a descriptor wallet, fill with num_combo combo descriptors with random keys
44
// This benchmarks a non-HD wallet migrated to descriptors
45
if
(num_combo > 0) {
46
LOCK
(
wallet
->cs_wallet);
47
for
(
int
i = 0; i < num_combo; ++i) {
48
CKey
key;
49
key.
MakeNewKey
(
/*fCompressed=*/
true
);
50
FlatSigningProvider
keys
;
51
std::string error;
52
std::vector<std::unique_ptr<Descriptor>> desc =
Parse
(
"combo("
+
EncodeSecret
(key) +
")"
,
keys
, error,
/*require_checksum=*/
false
);
53
WalletDescriptor
w_desc(std::move(desc.at(0)),
/*creation_time=*/
0,
/*range_start=*/
0,
/*range_end=*/
0,
/*next_index=*/
0);
54
Assert
(
wallet
->AddWalletDescriptor(w_desc,
keys
,
/*label=*/
""
,
/*internal=*/
false
));
55
}
56
}
57
58
const
CScript
script
=
GetScriptForDestination
(
DecodeDestination
(
ADDRESS_BCRT1_UNSPENDABLE
));
59
60
bench.
run
([&] {
61
LOCK
(
wallet
->cs_wallet);
62
bool
mine =
wallet
->IsMine(
script
);
63
assert
(!mine);
64
});
65
66
TestUnloadWallet
(std::move(
wallet
));
67
}
68
69
static
void
WalletIsMineDescriptors
(
benchmark::Bench
& bench) {
WalletIsMine
(bench); }
70
static
void
WalletIsMineMigratedDescriptors
(
benchmark::Bench
& bench) {
WalletIsMine
(bench,
/*num_combo=*/
2000); }
71
BENCHMARK
(
WalletIsMineDescriptors
);
72
BENCHMARK
(
WalletIsMineMigratedDescriptors
);
73
}
// namespace wallet
GetScriptForDestination
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition
addresstype.cpp:166
addresstype.h
bench.h
check.h
Assert
#define Assert(val)
Identity function.
Definition
check.h:116
CKey
An encapsulated private key.
Definition
key.h:40
CKey::MakeNewKey
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
Definition
key.cpp:163
CScript
Serialized script, used inside transaction inputs and outputs.
Definition
script.h:406
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:649
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition
nanobench.h:1308
wallet::WalletDescriptor
Descriptor with some wallet metadata.
Definition
walletutil.h:64
db.h
key.h
DecodeDestination
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
Definition
key_io.cpp:300
EncodeSecret
std::string EncodeSecret(const CKey &key)
Definition
key_io.cpp:232
key_io.h
script
Definition
parsing.cpp:11
wallet
Definition
coin_selection.cpp:31
wallet::MakeInMemoryWalletDatabase
std::unique_ptr< WalletDatabase > MakeInMemoryWalletDatabase()
Definition
sqlite.cpp:729
wallet::WalletIsMineDescriptors
static void WalletIsMineDescriptors(benchmark::Bench &bench)
Definition
wallet_ismine.cpp:69
wallet::ADDRESS_BCRT1_UNSPENDABLE
const std::string ADDRESS_BCRT1_UNSPENDABLE
Definition
util.h:32
wallet::WalletIsMine
static void WalletIsMine(benchmark::Bench &bench, int num_combo=0)
Definition
wallet_ismine.cpp:29
wallet::TestUnloadWallet
void TestUnloadWallet(std::shared_ptr< CWallet > &&wallet)
Definition
util.cpp:97
wallet::WalletIsMineMigratedDescriptors
static void WalletIsMineMigratedDescriptors(benchmark::Bench &bench)
Definition
wallet_ismine.cpp:70
wallet::BENCHMARK
BENCHMARK(CoinSelection)
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
Parse
std::vector< std::unique_ptr< Descriptor > > Parse(std::string_view descriptor, FlatSigningProvider &out, std::string &error, bool require_checksum)
Parse a descriptor string.
Definition
descriptor.cpp:2994
descriptor.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
signingprovider.h
sqlite.h
FlatSigningProvider
Definition
signingprovider.h:235
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
sync.h
LOCK
#define LOCK(cs)
Definition
sync.h:268
keys
std::vector< uint16_t > keys
Definition
dbwrapper.cpp:376
assert
assert(!tx.IsCoinBase())
context.h
util.h
wallet.h
walletutil.h
Generated on
for Bitcoin Core by
1.18.0