/
githubmirror
/
bitcoin
Обзор
Документация
Войти
/
githubmirror
/
bitcoin
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/bench/wallet_balance.cpp
75 строк
3 KB
Pablo Martin
bench: replace CreateMockableWalletDatabase with MakeInMemoryWalletDatabase
13 июл 2026, 07:06
13 июл 2026, 07:06
7508ac3
Код
Авторство
О чём код?
// Copyright (c) 2012-present The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <bench/bench.h> #include <interfaces/chain.h> #include <interfaces/handler.h> #include <kernel/chainparams.h> #include <primitives/block.h> #include <primitives/transaction.h> #include <sync.h> #include <test/util/mining.h> #include <test/util/setup_common.h> #include <test/util/time.h> #include <uint256.h> #include <util/check.h> #include <validation.h> #include <wallet/db.h> #include <wallet/receive.h> #include <wallet/sqlite.h> #include <wallet/test/util.h> #include <wallet/wallet.h> #include <wallet/walletutil.h> #include <memory> #include <optional> #include <string> namespace wallet { static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_mine) { const auto test_setup = MakeNoLogFileContext<const TestingSetup>(); const auto& ADDRESS_WATCHONLY = ADDRESS_BCRT1_UNSPENDABLE; // Set clock to genesis block, so the descriptors/keys creation time don't interfere with the blocks scanning process. // The reason is 'generatetoaddress', which creates a chain with deterministic timestamps in the past. FakeNodeClock clock{test_setup->m_node.chainman->GetParams().GenesisBlock().Time()}; CWallet wallet{test_setup->m_node.chain.get(), "", MakeInMemoryWalletDatabase()}; { LOCK(wallet.cs_wallet); wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS); wallet.SetupDescriptorScriptPubKeyMans(); } auto handler = test_setup->m_node.chain->handleNotifications({&wallet, [](CWallet*) {}}); const std::optional<std::string> address_mine{add_mine ? std::optional<std::string>{getnewaddress(wallet)} : std::nullopt}; for (int i = 0; i < 100; ++i) { generatetoaddress(test_setup->m_node, address_mine.value_or(ADDRESS_WATCHONLY)); generatetoaddress(test_setup->m_node, ADDRESS_WATCHONLY); } // Calls SyncWithValidationInterfaceQueue wallet.chain().waitForNotificationsIfTipChanged(uint256::ZERO); auto bal = GetBalance(wallet); // Cache bench.setup([&] { if (set_dirty) wallet.MarkDirty(); }) .run([&] { bal = GetBalance(wallet); ankerl::nanobench::doNotOptimizeAway(bal); assert(add_mine == (bal.m_mine_trusted > 0)); }); } static void WalletBalanceDirty(benchmark::Bench& bench) { WalletBalance(bench, /*set_dirty=*/true, /*add_mine=*/true); } static void WalletBalanceClean(benchmark::Bench& bench) { WalletBalance(bench, /*set_dirty=*/false, /*add_mine=*/true); } static void WalletBalanceWatch(benchmark::Bench& bench) { WalletBalance(bench, /*set_dirty=*/false, /*add_mine=*/false); } BENCHMARK(WalletBalanceDirty); BENCHMARK(WalletBalanceClean); BENCHMARK(WalletBalanceWatch); } // namespace wallet