Rename ReleaseWallet to FlushAndDeleteWallet

To better describe the function's behavior.
And add wallet name to logprint.
This commit is contained in:
furszy 2024-08-15 11:08:17 -03:00
parent 64e736d79e
commit f550a8e035
No known key found for this signature in database
GPG key ID: 5DD23CCC686AA623

View file

@ -227,10 +227,10 @@ static std::set<std::string> g_loading_wallet_set GUARDED_BY(g_loading_wallet_mu
static std::set<std::string> g_unloading_wallet_set GUARDED_BY(g_wallet_release_mutex); static std::set<std::string> g_unloading_wallet_set GUARDED_BY(g_wallet_release_mutex);
// Custom deleter for shared_ptr<CWallet>. // Custom deleter for shared_ptr<CWallet>.
static void ReleaseWallet(CWallet* wallet) static void FlushAndDeleteWallet(CWallet* wallet)
{ {
const std::string name = wallet->GetName(); const std::string name = wallet->GetName();
wallet->WalletLogPrintf("Releasing wallet\n"); wallet->WalletLogPrintf("Releasing wallet %s..\n", name);
wallet->Flush(); wallet->Flush();
delete wallet; delete wallet;
// Wallet is now released, notify WaitForDeleteWallet, if any. // Wallet is now released, notify WaitForDeleteWallet, if any.
@ -255,7 +255,7 @@ void WaitForDeleteWallet(std::shared_ptr<CWallet>&& wallet)
// Multiple threads could simultaneously be waiting for deletion. // Multiple threads could simultaneously be waiting for deletion.
} }
// Time to ditch our shared_ptr and wait for ReleaseWallet call. // Time to ditch our shared_ptr and wait for FlushAndDeleteWallet call.
wallet.reset(); wallet.reset();
{ {
WAIT_LOCK(g_wallet_release_mutex, lock); WAIT_LOCK(g_wallet_release_mutex, lock);
@ -2972,7 +2972,7 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
const auto start{SteadyClock::now()}; const auto start{SteadyClock::now()};
// TODO: Can't use std::make_shared because we need a custom deleter but // TODO: Can't use std::make_shared because we need a custom deleter but
// should be possible to use std::allocate_shared. // should be possible to use std::allocate_shared.
std::shared_ptr<CWallet> walletInstance(new CWallet(chain, name, std::move(database)), ReleaseWallet); std::shared_ptr<CWallet> walletInstance(new CWallet(chain, name, std::move(database)), FlushAndDeleteWallet);
walletInstance->m_keypool_size = std::max(args.GetIntArg("-keypool", DEFAULT_KEYPOOL_SIZE), int64_t{1}); walletInstance->m_keypool_size = std::max(args.GetIntArg("-keypool", DEFAULT_KEYPOOL_SIZE), int64_t{1});
walletInstance->m_notify_tx_changed_script = args.GetArg("-walletnotify", ""); walletInstance->m_notify_tx_changed_script = args.GetArg("-walletnotify", "");