wallet: rename UnloadWallet to WaitForDeleteWallet

And update function's documentation.
This commit is contained in:
furszy 2024-08-13 23:00:45 -03:00
parent 5d15485aaf
commit 8872b4a6ca
No known key found for this signature in database
GPG key ID: 5DD23CCC686AA623
7 changed files with 13 additions and 16 deletions

View file

@ -42,7 +42,7 @@ static void WalletCreate(benchmark::Bench& bench, bool encrypted)
// Release wallet // Release wallet
RemoveWallet(context, wallet, /*load_on_start=*/ std::nullopt); RemoveWallet(context, wallet, /*load_on_start=*/ std::nullopt);
UnloadWallet(std::move(wallet)); WaitForDeleteWallet(std::move(wallet));
fs::remove_all(wallet_path); fs::remove_all(wallet_path);
}); });
} }

View file

@ -178,7 +178,7 @@ void UnloadWallets(WalletContext& context)
wallets.pop_back(); wallets.pop_back();
std::vector<bilingual_str> warnings; std::vector<bilingual_str> warnings;
RemoveWallet(context, wallet, /* load_on_start= */ std::nullopt, warnings); RemoveWallet(context, wallet, /* load_on_start= */ std::nullopt, warnings);
UnloadWallet(std::move(wallet)); WaitForDeleteWallet(std::move(wallet));
} }
} }
} // namespace wallet } // namespace wallet

View file

@ -495,7 +495,7 @@ static RPCHelpMan unloadwallet()
} }
} }
UnloadWallet(std::move(wallet)); WaitForDeleteWallet(std::move(wallet));
UniValue result(UniValue::VOBJ); UniValue result(UniValue::VOBJ);
PushWarnings(warnings, result); PushWarnings(warnings, result);

View file

@ -74,7 +74,7 @@ void TestUnloadWallet(std::shared_ptr<CWallet>&& wallet)
// Calls SyncWithValidationInterfaceQueue // Calls SyncWithValidationInterfaceQueue
wallet->chain().waitForNotificationsIfTipChanged({}); wallet->chain().waitForNotificationsIfTipChanged({});
wallet->m_chain_notifications_handler.reset(); wallet->m_chain_notifications_handler.reset();
UnloadWallet(std::move(wallet)); WaitForDeleteWallet(std::move(wallet));
} }
std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database) std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database)

View file

@ -889,7 +889,7 @@ BOOST_FIXTURE_TEST_CASE(CreateWalletWithoutChain, BasicTestingSetup)
context.args = &m_args; context.args = &m_args;
auto wallet = TestLoadWallet(context); auto wallet = TestLoadWallet(context);
BOOST_CHECK(wallet); BOOST_CHECK(wallet);
UnloadWallet(std::move(wallet)); WaitForDeleteWallet(std::move(wallet));
} }
BOOST_FIXTURE_TEST_CASE(RemoveTxs, TestChain100Setup) BOOST_FIXTURE_TEST_CASE(RemoveTxs, TestChain100Setup)

View file

@ -233,18 +233,18 @@ static void ReleaseWallet(CWallet* wallet)
wallet->WalletLogPrintf("Releasing wallet\n"); wallet->WalletLogPrintf("Releasing wallet\n");
wallet->Flush(); wallet->Flush();
delete wallet; delete wallet;
// Wallet is now released, notify UnloadWallet, if any. // Wallet is now released, notify WaitForDeleteWallet, if any.
{ {
LOCK(g_wallet_release_mutex); LOCK(g_wallet_release_mutex);
if (g_unloading_wallet_set.erase(name) == 0) { if (g_unloading_wallet_set.erase(name) == 0) {
// UnloadWallet was not called for this wallet, all done. // WaitForDeleteWallet was not called for this wallet, all done.
return; return;
} }
} }
g_wallet_release_cv.notify_all(); g_wallet_release_cv.notify_all();
} }
void UnloadWallet(std::shared_ptr<CWallet>&& wallet) void WaitForDeleteWallet(std::shared_ptr<CWallet>&& wallet)
{ {
// Mark wallet for unloading. // Mark wallet for unloading.
const std::string name = wallet->GetName(); const std::string name = wallet->GetName();
@ -4387,7 +4387,7 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(const std::string& walle
if (!RemoveWallet(context, wallet, /*load_on_start=*/std::nullopt, warnings)) { if (!RemoveWallet(context, wallet, /*load_on_start=*/std::nullopt, warnings)) {
return util::Error{_("Unable to unload the wallet before migrating")}; return util::Error{_("Unable to unload the wallet before migrating")};
} }
UnloadWallet(std::move(wallet)); WaitForDeleteWallet(std::move(wallet));
was_loaded = true; was_loaded = true;
} else { } else {
// Check if the wallet is BDB // Check if the wallet is BDB
@ -4531,7 +4531,7 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(const std::string& walle
error += _("\nUnable to cleanup failed migration"); error += _("\nUnable to cleanup failed migration");
return util::Error{error}; return util::Error{error};
} }
UnloadWallet(std::move(w)); WaitForDeleteWallet(std::move(w));
} else { } else {
// Unloading for wallets in local context // Unloading for wallets in local context
assert(w.use_count() == 1); assert(w.use_count() == 1);

View file

@ -83,12 +83,9 @@ struct bilingual_str;
namespace wallet { namespace wallet {
struct WalletContext; struct WalletContext;
//! Explicitly unload and delete the wallet. //! Explicitly delete the wallet.
//! Blocks the current thread after signaling the unload intent so that all //! Blocks the current thread until the wallet is destructed.
//! wallet pointer owners release the wallet. void WaitForDeleteWallet(std::shared_ptr<CWallet>&& wallet);
//! Note that, when blocking is not required, the wallet is implicitly unloaded
//! by the shared pointer deleter.
void UnloadWallet(std::shared_ptr<CWallet>&& wallet);
bool AddWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet); bool AddWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet);
bool RemoveWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet, std::optional<bool> load_on_start, std::vector<bilingual_str>& warnings); bool RemoveWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet, std::optional<bool> load_on_start, std::vector<bilingual_str>& warnings);