mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 15:50:07 +01:00
dcb032dcdfqa: Ensure wallet unload during walletpassphrase timeout (João Barbosa)75b5d8c4earpc: Fix wallet unload during walletpassphrase timeout (João Barbosa) Pull request description: Backport #14453 to 0.17 Tree-SHA512: fce0adccbb07b6635bb773a71beb4a9b814bceb77bbe7bbc5bcb7d151aabb1148c791622f58c990afe202012ca1971cd466cb536fc6f37e22cdc58738720b593
This commit is contained in:
@@ -2546,13 +2546,6 @@ static UniValue keypoolrefill(const JSONRPCRequest& request)
|
||||
}
|
||||
|
||||
|
||||
static void LockWallet(CWallet* pWallet)
|
||||
{
|
||||
LOCK(pWallet->cs_wallet);
|
||||
pWallet->nRelockTime = 0;
|
||||
pWallet->Lock();
|
||||
}
|
||||
|
||||
static UniValue walletpassphrase(const JSONRPCRequest& request)
|
||||
{
|
||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||
@@ -2622,7 +2615,18 @@ static UniValue walletpassphrase(const JSONRPCRequest& request)
|
||||
pwallet->TopUpKeyPool();
|
||||
|
||||
pwallet->nRelockTime = GetTime() + nSleepTime;
|
||||
RPCRunLater(strprintf("lockwallet(%s)", pwallet->GetName()), std::bind(LockWallet, pwallet), nSleepTime);
|
||||
|
||||
// Keep a weak pointer to the wallet so that it is possible to unload the
|
||||
// wallet before the following callback is called. If a valid shared pointer
|
||||
// is acquired in the callback then the wallet is still loaded.
|
||||
std::weak_ptr<CWallet> weak_wallet = wallet;
|
||||
RPCRunLater(strprintf("lockwallet(%s)", pwallet->GetName()), [weak_wallet] {
|
||||
if (auto shared_wallet = weak_wallet.lock()) {
|
||||
LOCK(shared_wallet->cs_wallet);
|
||||
shared_wallet->Lock();
|
||||
shared_wallet->nRelockTime = 0;
|
||||
}
|
||||
}, nSleepTime);
|
||||
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user