Changeset View
Changeset View
Standalone View
Standalone View
src/bench/wallet_balance.cpp
// Copyright (c) 2012-2019 The Bitcoin Core developers | // Copyright (c) 2012-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <bench/bench.h> | #include <bench/bench.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <interfaces/chain.h> | #include <interfaces/chain.h> | ||||
#include <node/context.h> | #include <node/context.h> | ||||
#include <test/util/mining.h> | #include <test/util/mining.h> | ||||
#include <test/util/setup_common.h> | #include <test/util/setup_common.h> | ||||
#include <test/util/wallet.h> | #include <test/util/wallet.h> | ||||
#include <validationinterface.h> | #include <validationinterface.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
static void WalletBalance(benchmark::State &state, const bool set_dirty, | static void WalletBalance(benchmark::State &state, const bool set_dirty, | ||||
const bool add_watchonly, const bool add_mine) { | const bool add_watchonly, const bool add_mine) { | ||||
RegTestingSetup test_setup; | |||||
const auto &ADDRESS_WATCHONLY = ADDRESS_BCHREG_UNSPENDABLE; | const auto &ADDRESS_WATCHONLY = ADDRESS_BCHREG_UNSPENDABLE; | ||||
const Config &config = GetConfig(); | const Config &config = GetConfig(); | ||||
NodeContext node; | NodeContext node; | ||||
std::unique_ptr<interfaces::Chain> chain = | std::unique_ptr<interfaces::Chain> chain = | ||||
interfaces::MakeChain(node, config.GetChainParams()); | interfaces::MakeChain(node, config.GetChainParams()); | ||||
CWallet wallet{chain.get(), WalletLocation(), WalletDatabase::CreateMock()}; | CWallet wallet{chain.get(), WalletLocation(), WalletDatabase::CreateMock()}; | ||||
Show All 10 Lines | static void WalletBalance(benchmark::State &state, const bool set_dirty, | ||||
const std::optional<std::string> address_mine{ | const std::optional<std::string> address_mine{ | ||||
add_mine ? std::optional<std::string>{getnewaddress(config, wallet)} | add_mine ? std::optional<std::string>{getnewaddress(config, wallet)} | ||||
: std::nullopt}; | : std::nullopt}; | ||||
if (add_watchonly) { | if (add_watchonly) { | ||||
importaddress(wallet, ADDRESS_WATCHONLY); | importaddress(wallet, ADDRESS_WATCHONLY); | ||||
} | } | ||||
for (int i = 0; i < 100; ++i) { | for (int i = 0; i < 100; ++i) { | ||||
generatetoaddress(config, g_testing_setup->m_node, | generatetoaddress(config, test_setup.m_node, | ||||
address_mine.value_or(ADDRESS_WATCHONLY)); | address_mine.value_or(ADDRESS_WATCHONLY)); | ||||
generatetoaddress(config, g_testing_setup->m_node, ADDRESS_WATCHONLY); | generatetoaddress(config, test_setup.m_node, ADDRESS_WATCHONLY); | ||||
} | } | ||||
SyncWithValidationInterfaceQueue(); | SyncWithValidationInterfaceQueue(); | ||||
// Cache | // Cache | ||||
auto bal = wallet.GetBalance(); | auto bal = wallet.GetBalance(); | ||||
while (state.KeepRunning()) { | while (state.KeepRunning()) { | ||||
if (set_dirty) { | if (set_dirty) { | ||||
Show All 33 Lines |