bench: Add wallet_balance benchmarks

This commit is contained in:
MarcoFalke 2019-04-10 15:06:31 -04:00
parent 78295e97b8
commit fa46ac3127
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
5 changed files with 76 additions and 1 deletions

View file

@ -39,6 +39,7 @@
<ClCompile Include="..\..\src\bench\rpc_mempool.cpp" />
<ClCompile Include="..\..\src\bench\merkle_root.cpp" />
<ClCompile Include="..\..\src\bench\rollingbloom.cpp" />
<ClCompile Include="..\..\src\bench\wallet_balance.cpp" />
<ClCompile Include="..\..\src\bench\verify_script.cpp" />
</ItemGroup>
<ItemGroup>

View file

@ -64,6 +64,7 @@ endif
if ENABLE_WALLET
bench_bench_bitcoin_SOURCES += bench/coin_selection.cpp
bench_bench_bitcoin_SOURCES += bench/wallet_balance.cpp
endif
bench_bench_bitcoin_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(CRYPTO_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(MINIUPNPC_LIBS)

View file

@ -0,0 +1,68 @@
// 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 <bench/bench.h>
#include <interfaces/chain.h>
#include <key_io.h>
#include <optional.h>
#include <test/util.h>
#include <validationinterface.h>
#include <wallet/wallet.h>
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::State& state, const bool set_dirty, const bool add_watchonly, const bool add_mine)
{
const auto& ADDRESS_WATCHONLY = ADDRESS_BCRT1_UNSPENDABLE;
WalletTestingSetup wallet_t{};
auto& wallet = wallet_t.m_wallet;
{
bool first_run;
if (wallet.LoadWallet(first_run) != DBErrors::LOAD_OK) assert(false);
wallet_t.handleNotifications();
}
const Optional<std::string> address_mine{add_mine ? Optional<std::string>{getnewaddress(wallet)} : nullopt};
if (add_watchonly) importaddress(wallet, ADDRESS_WATCHONLY);
for (int i = 0; i < 100; ++i) {
generatetoaddress(address_mine.get_value_or(ADDRESS_WATCHONLY));
generatetoaddress(ADDRESS_WATCHONLY);
}
SyncWithValidationInterfaceQueue();
auto bal = wallet.GetBalance(); // Cache
while (state.KeepRunning()) {
if (set_dirty) wallet.MarkDirty();
bal = wallet.GetBalance();
if (add_mine) assert(bal.m_mine_trusted > 0);
if (add_watchonly) assert(bal.m_watchonly_trusted > 0);
}
}
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);

View file

@ -22,6 +22,8 @@
#include <boost/thread.hpp>
const std::string ADDRESS_BCRT1_UNSPENDABLE = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj";
#ifdef ENABLE_WALLET
std::string getnewaddress(CWallet& w)
{
@ -75,7 +77,6 @@ CTxIn MineBlock(const CScript& coinbase_scriptPubKey)
return CTxIn{block->vtx[0]->GetHash(), 0};
}
std::shared_ptr<CBlock> PrepareBlock(const CScript& coinbase_scriptPubKey)
{
auto block = std::make_shared<CBlock>(

View file

@ -13,6 +13,10 @@ class CScript;
class CTxIn;
class CWallet;
// Constants //
extern const std::string ADDRESS_BCRT1_UNSPENDABLE;
// Lower-level utils //
/** Returns the generated coin */