From 6cc3648faef88eeeca8464414c7ae9099b7e9bcb Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Wed, 17 Apr 2019 13:27:02 -0400 Subject: [PATCH] merge bitcoin#15779: Add wallet_balance benchmark --- src/bench/wallet_balance.cpp | 21 +++------------------ src/wallet/test/wallet_test_fixture.cpp | 7 ++++--- src/wallet/wallet.cpp | 12 +++++++++--- src/wallet/wallet.h | 12 ++++++++---- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp index 08b9a3126c..9822956a17 100644 --- a/src/bench/wallet_balance.cpp +++ b/src/bench/wallet_balance.cpp @@ -11,31 +11,16 @@ #include -struct WalletTestingSetup { - std::unique_ptr m_chain = interfaces::MakeChain(); - CWallet m_wallet; - - WalletTestingSetup() - : m_wallet{*m_chain.get(), WalletLocation(), WalletDatabase::CreateMock()} - { - } - - void handleNotifications() - { - m_wallet.m_chain_notifications_handler = m_chain->handleNotifications(m_wallet); - } -}; - static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_watchonly, const bool add_mine, const uint32_t epoch_iters) { const auto& ADDRESS_WATCHONLY = ADDRESS_B58T_UNSPENDABLE; - WalletTestingSetup wallet_t{}; - auto& wallet = wallet_t.m_wallet; + std::unique_ptr chain = interfaces::MakeChain(); + CWallet wallet{*chain.get(), WalletLocation(), WalletDatabase::CreateMock()}; { bool first_run; if (wallet.LoadWallet(first_run) != DBErrors::LOAD_OK) assert(false); - wallet_t.handleNotifications(); + wallet.handleNotifications(); } diff --git a/src/wallet/test/wallet_test_fixture.cpp b/src/wallet/test/wallet_test_fixture.cpp index bd3f1e1f05..dc26ec10f3 100644 --- a/src/wallet/test/wallet_test_fixture.cpp +++ b/src/wallet/test/wallet_test_fixture.cpp @@ -8,12 +8,13 @@ #include #include -WalletTestingSetup::WalletTestingSetup(const std::string& chainName): - TestingSetup(chainName), m_wallet(*m_chain, WalletLocation(), WalletDatabase::CreateMock()) +WalletTestingSetup::WalletTestingSetup(const std::string& chainName) + : TestingSetup(chainName), + m_wallet(*m_chain, 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 923328dd09..70261b394d 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -18,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -33,6 +31,9 @@ #include #include #include +#include +#include +#include #include #include @@ -5205,7 +5206,7 @@ std::shared_ptr CWallet::CreateWalletFromFile(interfaces::Chain& chain, chain.loadWallet(interfaces::MakeWallet(walletInstance)); // Register with the validation interface. It's ok to do this after rescan since we're still holding locked_chain. - walletInstance->m_chain_notifications_handler = chain.handleNotifications(*walletInstance); + walletInstance->handleNotifications(); walletInstance->SetBroadcastTransactions(gArgs.GetBoolArg("-walletbroadcast", DEFAULT_WALLETBROADCAST)); @@ -5220,6 +5221,11 @@ std::shared_ptr CWallet::CreateWalletFromFile(interfaces::Chain& chain, return walletInstance; } +void CWallet::handleNotifications() +{ + m_chain_notifications_handler = m_chain.handleNotifications(*this); +} + void CWallet::postInitProcess() { // Add wallet transactions that aren't already in a block to mempool diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 3c146ae2ae..ce48aad7e7 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -13,12 +13,12 @@ #include #include #include +#include