merge bitcoin#15779: Add wallet_balance benchmark

This commit is contained in:
Kittywhiskers Van Gogh 2019-04-17 13:27:02 -04:00
parent 438c93bd9a
commit 6cc3648fae
4 changed files with 24 additions and 28 deletions

View File

@ -11,31 +11,16 @@
#include <optional>
struct WalletTestingSetup {
std::unique_ptr<interfaces::Chain> 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<interfaces::Chain> 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();
}

View File

@ -8,12 +8,13 @@
#include <wallet/db.h>
#include <wallet/rpcwallet.h>
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();
}

View File

@ -8,7 +8,6 @@
#include <chain.h>
#include <chainparams.h>
#include <wallet/coinselection.h>
#include <consensus/consensus.h>
#include <consensus/validation.h>
#include <crypto/common.h>
@ -18,7 +17,6 @@
#include <key.h>
#include <key_io.h>
#include <keystore.h>
#include <validation.h>
#include <net.h>
#include <policy/fees.h>
#include <policy/policy.h>
@ -33,6 +31,9 @@
#include <util/fees.h>
#include <util/moneystr.h>
#include <util/validation.h>
#include <validation.h>
#include <wallet/coincontrol.h>
#include <wallet/coinselection.h>
#include <wallet/fees.h>
#include <warnings.h>
@ -5205,7 +5206,7 @@ std::shared_ptr<CWallet> 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> 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

View File

@ -13,12 +13,12 @@
#include <policy/feerate.h>
#include <saltedhasher.h>
#include <streams.h>
#include <script/ismine.h>
#include <tinyformat.h>
#include <ui_interface.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <validationinterface.h>
#include <script/ismine.h>
#include <wallet/coincontrol.h>
#include <wallet/crypter.h>
#include <wallet/coinselection.h>
@ -823,7 +823,10 @@ public:
unsigned int nMasterKeyMaxID = 0;
/** Construct wallet with specified name and database implementation. */
CWallet(interfaces::Chain& chain, const WalletLocation& location, std::unique_ptr<WalletDatabase> database) : m_chain(chain), m_location(location), database(std::move(database))
CWallet(interfaces::Chain& chain, const WalletLocation& location, std::unique_ptr<WalletDatabase> database)
: m_chain(chain),
m_location(location),
database(std::move(database))
{
}
@ -854,6 +857,9 @@ public:
/** Registered interfaces::Chain::Notifications handler. */
std::unique_ptr<interfaces::Handler> m_chain_notifications_handler;
/** Register the wallet for chain notifications */
void handleNotifications();
/** Interface for accessing chain state. */
interfaces::Chain& chain() const { return m_chain; }
@ -1296,8 +1302,6 @@ public:
/** Implement lookup of key origin information through wallet key metadata. */
bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override;
friend struct WalletTestingSetup;
};
/** A key allocated from the key pool. */