diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp index a9c1778bc..b2afe63b2 100644 --- a/src/bench/wallet_balance.cpp +++ b/src/bench/wallet_balance.cpp @@ -1,95 +1,81 @@ // Copyright (c) 2012-2019 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 -#include // For Params() #include #include #include #include #include #include #include -struct WalletTestingSetup { - std::unique_ptr m_chain = interfaces::MakeChain(); - CWallet m_wallet; - - WalletTestingSetup() - : m_wallet{Params(), m_chain.get(), WalletLocation(), - WalletDatabase::CreateMock()} {} - - void handleNotifications() { - m_wallet.m_chain_notifications_handler = - m_chain->handleNotifications(m_wallet); - } -}; - static void WalletBalance(benchmark::State &state, const bool set_dirty, const bool add_watchonly, const bool add_mine) { const auto &ADDRESS_WATCHONLY = ADDRESS_BCHREG_UNSPENDABLE; - WalletTestingSetup wallet_t{}; - auto &wallet = wallet_t.m_wallet; + const Config &config = GetConfig(); + + std::unique_ptr chain = interfaces::MakeChain(); + CWallet wallet{config.GetChainParams(), chain.get(), WalletLocation(), + WalletDatabase::CreateMock()}; { bool first_run; if (wallet.LoadWallet(first_run) != DBErrors::LOAD_OK) { assert(false); } - wallet_t.handleNotifications(); + wallet.handleNotifications(); } - const Config &config = GetConfig(); - const Optional address_mine{ add_mine ? Optional{getnewaddress(config, wallet)} : nullopt}; if (add_watchonly) { importaddress(wallet, ADDRESS_WATCHONLY); } for (int i = 0; i < 100; ++i) { generatetoaddress(config, address_mine.get_value_or(ADDRESS_WATCHONLY)); generatetoaddress(config, ADDRESS_WATCHONLY); } SyncWithValidationInterfaceQueue(); // Cache auto bal = wallet.GetBalance(); while (state.KeepRunning()) { if (set_dirty) { wallet.MarkDirty(); } bal = wallet.GetBalance(); if (add_mine) { assert(bal.m_mine_trusted > Amount::zero()); } if (add_watchonly) { assert(bal.m_watchonly_trusted > Amount::zero()); } } } static void WalletBalanceDirty(benchmark::State &state) { WalletBalance(state, /* set_dirty */ true, /* add_watchonly */ true, /* add_mine */ true); } static void WalletBalanceClean(benchmark::State &state) { WalletBalance(state, /* set_dirty */ false, /* add_watchonly */ true, /* add_mine */ true); } static void WalletBalanceMine(benchmark::State &state) { WalletBalance(state, /* set_dirty */ false, /* add_watchonly */ false, /* add_mine */ true); } static void WalletBalanceWatch(benchmark::State &state) { WalletBalance(state, /* set_dirty */ false, /* add_watchonly */ true, /* add_mine */ false); } BENCHMARK(WalletBalanceDirty, 2500); BENCHMARK(WalletBalanceClean, 8000); BENCHMARK(WalletBalanceMine, 16000); BENCHMARK(WalletBalanceWatch, 8000); diff --git a/src/wallet/test/wallet_test_fixture.cpp b/src/wallet/test/wallet_test_fixture.cpp index a45a5e9b3..c07289e17 100644 --- a/src/wallet/test/wallet_test_fixture.cpp +++ b/src/wallet/test/wallet_test_fixture.cpp @@ -1,24 +1,23 @@ // Copyright (c) 2016 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 #include #include #include #include #include #include WalletTestingSetup::WalletTestingSetup(const std::string &chainName) : TestingSetup(chainName), m_wallet(Params(), m_chain.get(), WalletLocation(), WalletDatabase::CreateMock()) { bool fFirstRun; m_wallet.LoadWallet(fFirstRun); - m_wallet.m_chain_notifications_handler = - m_chain->handleNotifications(m_wallet); + m_wallet.handleNotifications(); m_chain_client->registerRpcs(); } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index b70033e17..f01ec9558 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1,4988 +1,4991 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2016 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include