Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2022-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.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>22#include <cstdint>23#include <memory>24#include <string>25#include <utility>26#include <vector>28namespace wallet {29static void WalletIsMine(benchmark::Bench& bench, int num_combo = 0)30{31const auto test_setup = MakeNoLogFileContext<TestingSetup>();33WalletContext context;34context.args = &test_setup->m_args;35context.chain = test_setup->m_node.chain.get();37// Setup the wallet38// Loading the wallet will also create it39uint64_t create_flags = WALLET_FLAG_DESCRIPTORS;40auto database = MakeInMemoryWalletDatabase();41auto wallet = TestCreateWallet(std::move(database), context, create_flags);43// For a descriptor wallet, fill with num_combo combo descriptors with random keys44// This benchmarks a non-HD wallet migrated to descriptors45if (num_combo > 0) {46LOCK(wallet->cs_wallet);47for (int i = 0; i < num_combo; ++i) {48CKey key;49key.MakeNewKey(/*fCompressed=*/true);50FlatSigningProvider keys;51std::string error;52std::vector<std::unique_ptr<Descriptor>> desc = Parse("combo(" + EncodeSecret(key) + ")", keys, error, /*require_checksum=*/false);53WalletDescriptor w_desc(std::move(desc.at(0)), /*creation_time=*/0, /*range_start=*/0, /*range_end=*/0, /*next_index=*/0);54Assert(wallet->AddWalletDescriptor(w_desc, keys, /*label=*/"", /*internal=*/false));55}56}58const CScript script = GetScriptForDestination(DecodeDestination(ADDRESS_BCRT1_UNSPENDABLE));60bench.run([&] {61LOCK(wallet->cs_wallet);62bool mine = wallet->IsMine(script);63assert(!mine);64});66TestUnloadWallet(std::move(wallet));67}69static void WalletIsMineDescriptors(benchmark::Bench& bench) { WalletIsMine(bench); }70static void WalletIsMineMigratedDescriptors(benchmark::Bench& bench) { WalletIsMine(bench, /*num_combo=*/2000); }71BENCHMARK(WalletIsMineDescriptors);72BENCHMARK(WalletIsMineMigratedDescriptors);73} // namespace wallet
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.