Skip to content

Commit 150b5c9

Browse files
committed
wallet: replace reload_wallet with inline functionality
Also, update related comments because a reload is not happening anymore. It is done because the legacy wallets could not have been loaded prior to migration, so I don't think a reload is happening post a successful migration, it's just load IMO.
1 parent 0f86da3 commit 150b5c9

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

src/wallet/wallet.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4226,15 +4226,6 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
42264226

42274227
const std::string wallet_name = local_wallet->GetName();
42284228

4229-
// Helper to reload as normal for some of our exit scenarios
4230-
const auto& reload_wallet = [&](std::shared_ptr<CWallet>& to_reload) {
4231-
assert(to_reload.use_count() == 1);
4232-
std::string name = to_reload->GetName();
4233-
to_reload.reset();
4234-
to_reload = LoadWallet(context, name, /*load_on_start=*/std::nullopt, options, status, error, warnings);
4235-
return to_reload != nullptr;
4236-
};
4237-
42384229
// Before anything else, check if there is something to migrate.
42394230
if (local_wallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
42404231
return util::Error{_("Error: This wallet is already a descriptor wallet")};
@@ -4289,10 +4280,10 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
42894280
}
42904281
}
42914282

4292-
// In case of reloading failure, we need to remember the wallet dirs to remove
4293-
// Set is used as it may be populated with the same wallet directory paths multiple times,
4294-
// both before and after reloading. This ensures the set is complete even if one of the wallets
4295-
// fails to reload.
4283+
// In case of loading failure, we need to remember the wallet dirs to remove.
4284+
// A `set` is used as it may be populated with the same wallet directory paths multiple times,
4285+
// both before and after loading. This ensures the set is complete even if one of the wallets
4286+
// fails to load.
42964287
std::set<fs::path> wallet_dirs;
42974288
if (success) {
42984289
Assume(!res.wallet); // We will set it here.
@@ -4304,15 +4295,17 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
43044295
for (const auto& path_to_remove : paths_to_remove) fs::remove_all(path_to_remove);
43054296
}
43064297

4307-
// Migration successful, unload all wallets locally, then reload them.
4308-
// Note: We use a pointer to the shared_ptr to avoid increasing its reference count,
4309-
// as 'reload_wallet' expects to be the sole owner (use_count == 1).
4298+
// Migration successful, load all the migrated wallets.
43104299
for (std::shared_ptr<CWallet>* wallet_ptr : {&local_wallet, &res.watchonly_wallet, &res.solvables_wallet}) {
43114300
if (success && *wallet_ptr) {
43124301
std::shared_ptr<CWallet>& wallet = *wallet_ptr;
4313-
// Save db path and reload wallet
4302+
// Save db path and load wallet
43144303
wallet_dirs.insert(fs::PathFromString(wallet->GetDatabase().Filename()).parent_path());
4315-
success = reload_wallet(wallet);
4304+
assert(wallet.use_count() == 1);
4305+
std::string wallet_name = wallet->GetName();
4306+
wallet.reset();
4307+
wallet = LoadWallet(context, wallet_name, /*load_on_start=*/std::nullopt, options, status, error, warnings);
4308+
success = (wallet != nullptr);
43164309

43174310
// When no wallet is set, set the main wallet.
43184311
if (!res.wallet) {

0 commit comments

Comments
 (0)