bench: clean up migrated descriptor wallets via loader teardown

`MigrateLegacyToDescriptor` returns both a spendable descriptor wallet and a watch‑only wallet.
If these remain attached, their files stay open and on Windows this can hang CI when removing the test directory.

By constructing them via `MakeWalletLoader` (which owns the `WalletContext`), both wallets are automatically unloaded when the loader is destroyed at the end.
This ensures no lingering handles or resource leaks when running the benchmark on CI with `-sanity-check`.

Co-authored-by: furszy <matiasfurszyfer@protonmail.com>
This commit is contained in:
Lőrinc 2025-04-19 13:35:21 +02:00
parent 06439a14c8
commit 1da11dbc44

View file

@ -3,14 +3,15 @@
// file COPYING or https://www.opensource.org/licenses/mit-license.php.
#include <bench/bench.h>
#include <kernel/chain.h>
#include <interfaces/chain.h>
#include <interfaces/wallet.h>
#include <kernel/chain.h>
#include <node/context.h>
#include <test/util/mining.h>
#include <test/util/setup_common.h>
#include <wallet/test/util.h>
#include <wallet/context.h>
#include <wallet/receive.h>
#include <wallet/test/util.h>
#include <wallet/wallet.h>
#include <optional>
@ -19,11 +20,8 @@ namespace wallet{
static void WalletMigration(benchmark::Bench& bench)
{
const auto test_setup = MakeNoLogFileContext<TestingSetup>();
WalletContext context;
context.args = &test_setup->m_args;
context.chain = test_setup->m_node.chain.get();
const auto test_setup{MakeNoLogFileContext<TestingSetup>()};
const auto loader{MakeWalletLoader(*test_setup->m_node.chain, test_setup->m_args)};
// Number of imported watch only addresses
int NUM_WATCH_ONLY_ADDR = 20;
@ -63,8 +61,9 @@ static void WalletMigration(benchmark::Bench& bench)
batch.WriteKey(pubkey, key.GetPrivKey(), CKeyMetadata());
}
bench.epochs(/*numEpochs=*/1).run([&context, &wallet] {
util::Result<MigrationResult> res = MigrateLegacyToDescriptor(std::move(wallet), /*passphrase=*/"", context, /*was_loaded=*/false);
bench.epochs(/*numEpochs=*/1)
.run([&] {
auto res{MigrateLegacyToDescriptor(std::move(wallet), /*passphrase=*/"", *loader->context(), /*was_loaded=*/false)};
assert(res);
assert(res->wallet);
assert(res->watchonly_wallet);