bench: Use DescriptorScriptPubKeyMan for wallet things
For wallet related benchmarks that need a ScriptPubKeyMan for operation, use a DescriptorScriptPubKeyMan
This commit is contained in:
1 parent
5e54aa9b90
commit
9bf0243872
3 files changed
+8
-21
No files matched your search
@@ -33,7 +33,6 @@ static void CoinSelection(benchmark::Bench& bench)
|
|||||||
NodeContext node;
|
NodeContext node;
|
||||||
auto chain = interfaces::MakeChain(node);
|
auto chain = interfaces::MakeChain(node);
|
||||||
CWallet wallet(chain.get(), "", CreateDummyWalletDatabase());
|
CWallet wallet(chain.get(), "", CreateDummyWalletDatabase());
|
||||||
wallet.SetupLegacyScriptPubKeyMan();
|
|
||||||
std::vector<std::unique_ptr<CWalletTx>> wtxs;
|
std::vector<std::unique_ptr<CWalletTx>> wtxs;
|
||||||
LOCK(wallet.cs_wallet);
|
LOCK(wallet.cs_wallet);
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_watchonly, const bool add_mine)
|
static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_mine)
|
||||||
{
|
{
|
||||||
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
|
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
|
||||||
|
|
||||||
@@ -22,13 +22,14 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b
|
|||||||
|
|
||||||
CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockWalletDatabase()};
|
CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockWalletDatabase()};
|
||||||
{
|
{
|
||||||
wallet.SetupLegacyScriptPubKeyMan();
|
LOCK(wallet.cs_wallet);
|
||||||
|
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
||||||
|
wallet.SetupDescriptorScriptPubKeyMans();
|
||||||
if (wallet.LoadWallet() != DBErrors::LOAD_OK) assert(false);
|
if (wallet.LoadWallet() != DBErrors::LOAD_OK) assert(false);
|
||||||
}
|
}
|
||||||
auto handler = test_setup->m_node.chain->handleNotifications({&wallet, [](CWallet*) {}});
|
auto handler = test_setup->m_node.chain->handleNotifications({&wallet, [](CWallet*) {}});
|
||||||
|
|
||||||
const std::optional<std::string> address_mine{add_mine ? std::optional<std::string>{getnewaddress(wallet)} : std::nullopt};
|
const std::optional<std::string> address_mine{add_mine ? std::optional<std::string>{getnewaddress(wallet)} : std::nullopt};
|
||||||
if (add_watchonly) importaddress(wallet, ADDRESS_WATCHONLY);
|
|
||||||
|
|
||||||
for (int i = 0; i < 100; ++i) {
|
for (int i = 0; i < 100; ++i) {
|
||||||
generatetoaddress(test_setup->m_node, address_mine.value_or(ADDRESS_WATCHONLY));
|
generatetoaddress(test_setup->m_node, address_mine.value_or(ADDRESS_WATCHONLY));
|
||||||
@@ -42,14 +43,13 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b
|
|||||||
if (set_dirty) wallet.MarkDirty();
|
if (set_dirty) wallet.MarkDirty();
|
||||||
bal = GetBalance(wallet);
|
bal = GetBalance(wallet);
|
||||||
if (add_mine) assert(bal.m_mine_trusted > 0);
|
if (add_mine) assert(bal.m_mine_trusted > 0);
|
||||||
if (add_watchonly) assert(bal.m_watchonly_trusted > 0);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static void WalletBalanceDirty(benchmark::Bench& bench) { WalletBalance(bench, /* set_dirty */ true, /* add_watchonly */ true, /* add_mine */ true); }
|
static void WalletBalanceDirty(benchmark::Bench& bench) { WalletBalance(bench, /* set_dirty */ true, /* add_mine */ true); }
|
||||||
static void WalletBalanceClean(benchmark::Bench& bench) { WalletBalance(bench, /* set_dirty */ false, /* add_watchonly */ true, /* add_mine */ true); }
|
static void WalletBalanceClean(benchmark::Bench& bench) { WalletBalance(bench, /* set_dirty */ false, /* add_mine */ true); }
|
||||||
static void WalletBalanceMine(benchmark::Bench& bench) { WalletBalance(bench, /* set_dirty */ false, /* add_watchonly */ false, /* add_mine */ true); }
|
static void WalletBalanceMine(benchmark::Bench& bench) { WalletBalance(bench, /* set_dirty */ false, /* add_mine */ true); }
|
||||||
static void WalletBalanceWatch(benchmark::Bench& bench) { WalletBalance(bench, /* set_dirty */ false, /* add_watchonly */ true, /* add_mine */ false); }
|
static void WalletBalanceWatch(benchmark::Bench& bench) { WalletBalance(bench, /* set_dirty */ false, /* add_mine */ false); }
|
||||||
|
|
||||||
BENCHMARK(WalletBalanceDirty);
|
BENCHMARK(WalletBalanceDirty);
|
||||||
BENCHMARK(WalletBalanceClean);
|
BENCHMARK(WalletBalanceClean);
|
||||||
|
|||||||
@@ -25,16 +25,4 @@ std::string getnewaddress(CWallet& w)
|
|||||||
return EncodeDestination(dest);
|
return EncodeDestination(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
void importaddress(CWallet& wallet, const std::string& address)
|
|
||||||
{
|
|
||||||
auto spk_man = wallet.GetLegacyScriptPubKeyMan();
|
|
||||||
LOCK2(wallet.cs_wallet, spk_man->cs_KeyStore);
|
|
||||||
const auto dest = DecodeDestination(address);
|
|
||||||
assert(IsValidDestination(dest));
|
|
||||||
const auto script = GetScriptForDestination(dest);
|
|
||||||
wallet.MarkDirty();
|
|
||||||
assert(!spk_man->HaveWatchOnly(script));
|
|
||||||
if (!spk_man->AddWatchOnly(script, 0 /* nCreateTime */)) assert(false);
|
|
||||||
wallet.SetAddressBook(dest, /* label */ "", "receive");
|
|
||||||
}
|
|
||||||
#endif // ENABLE_WALLET
|
#endif // ENABLE_WALLET
|
||||||
Reference in new issue
Block a user