mirror of
https://github.com/dashpay/dash.git
synced 2024-12-28 05:23:01 +01:00
Extra wallet locking fixes
* Fix sign error in calculation of seconds to sleep * Do not mix GetTime() (seconds) and Sleep() (milliseconds) * Do not sleep forever if walletlock() is called * Do locking within critical section
This commit is contained in:
parent
b0529ffd95
commit
aa625ed6ed
@ -353,7 +353,7 @@ Value getinfo(const Array& params, bool fHelp)
|
|||||||
obj.push_back(Pair("keypoolsize", pwalletMain->GetKeyPoolSize()));
|
obj.push_back(Pair("keypoolsize", pwalletMain->GetKeyPoolSize()));
|
||||||
obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
|
obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
|
||||||
if (pwalletMain->IsCrypted())
|
if (pwalletMain->IsCrypted())
|
||||||
obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime));
|
obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime / 1000));
|
||||||
obj.push_back(Pair("errors", GetWarnings("statusbar")));
|
obj.push_back(Pair("errors", GetWarnings("statusbar")));
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
@ -1537,7 +1537,7 @@ void ThreadTopUpKeyPool(void* parg)
|
|||||||
|
|
||||||
void ThreadCleanWalletPassphrase(void* parg)
|
void ThreadCleanWalletPassphrase(void* parg)
|
||||||
{
|
{
|
||||||
int64 nMyWakeTime = GetTime() + *((int*)parg);
|
int64 nMyWakeTime = GetTimeMillis() + *((int*)parg) * 1000;
|
||||||
|
|
||||||
ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime);
|
ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime);
|
||||||
|
|
||||||
@ -1545,17 +1545,25 @@ void ThreadCleanWalletPassphrase(void* parg)
|
|||||||
{
|
{
|
||||||
nWalletUnlockTime = nMyWakeTime;
|
nWalletUnlockTime = nMyWakeTime;
|
||||||
|
|
||||||
while (GetTime() < nWalletUnlockTime)
|
do
|
||||||
{
|
{
|
||||||
int64 nToSleep = GetTime() - nWalletUnlockTime;
|
if (nWalletUnlockTime==0)
|
||||||
|
break;
|
||||||
|
int64 nToSleep = nWalletUnlockTime - GetTimeMillis();
|
||||||
|
if (nToSleep <= 0)
|
||||||
|
break;
|
||||||
|
|
||||||
LEAVE_CRITICAL_SECTION(cs_nWalletUnlockTime);
|
LEAVE_CRITICAL_SECTION(cs_nWalletUnlockTime);
|
||||||
Sleep(nToSleep);
|
Sleep(nToSleep);
|
||||||
ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime);
|
ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime);
|
||||||
}
|
|
||||||
|
|
||||||
nWalletUnlockTime = 0;
|
} while(1);
|
||||||
pwalletMain->Lock();
|
|
||||||
|
if (nWalletUnlockTime)
|
||||||
|
{
|
||||||
|
nWalletUnlockTime = 0;
|
||||||
|
pwalletMain->Lock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1653,9 +1661,9 @@ Value walletlock(const Array& params, bool fHelp)
|
|||||||
if (!pwalletMain->IsCrypted())
|
if (!pwalletMain->IsCrypted())
|
||||||
throw JSONRPCError(-15, "Error: running with an unencrypted wallet, but walletlock was called.");
|
throw JSONRPCError(-15, "Error: running with an unencrypted wallet, but walletlock was called.");
|
||||||
|
|
||||||
pwalletMain->Lock();
|
|
||||||
CRITICAL_BLOCK(cs_nWalletUnlockTime)
|
CRITICAL_BLOCK(cs_nWalletUnlockTime)
|
||||||
{
|
{
|
||||||
|
pwalletMain->Lock();
|
||||||
nWalletUnlockTime = 0;
|
nWalletUnlockTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user