Browse Source

Prevent RPC 'move' from deadlocking

It seemed to create two CWalletDB objects that both grab the
database lock.
pull/1/head
Pieter Wuille 10 years ago
parent
commit
4291e8feab
  1. 4
      src/rpcwallet.cpp
  2. 10
      src/wallet.cpp
  3. 2
      src/wallet.h

4
src/rpcwallet.cpp

@ -573,7 +573,7 @@ Value movecmd(const Array& params, bool fHelp) @@ -573,7 +573,7 @@ Value movecmd(const Array& params, bool fHelp)
// Debit
CAccountingEntry debit;
debit.nOrderPos = pwalletMain->IncOrderPosNext();
debit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb);
debit.strAccount = strFrom;
debit.nCreditDebit = -nAmount;
debit.nTime = nNow;
@ -583,7 +583,7 @@ Value movecmd(const Array& params, bool fHelp) @@ -583,7 +583,7 @@ Value movecmd(const Array& params, bool fHelp)
// Credit
CAccountingEntry credit;
credit.nOrderPos = pwalletMain->IncOrderPosNext();
credit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb);
credit.strAccount = strTo;
credit.nCreditDebit = nAmount;
credit.nTime = nNow;

10
src/wallet.cpp

@ -291,10 +291,14 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) @@ -291,10 +291,14 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
return true;
}
int64 CWallet::IncOrderPosNext()
int64 CWallet::IncOrderPosNext(CWalletDB *pwalletdb)
{
int64 nRet = nOrderPosNext;
CWalletDB(strWalletFile).WriteOrderPosNext(++nOrderPosNext);
int64 nRet = nOrderPosNext++;
if (pwalletdb) {
pwalletdb->WriteOrderPosNext(nOrderPosNext);
} else {
CWalletDB(strWalletFile).WriteOrderPosNext(nOrderPosNext);
}
return nRet;
}

2
src/wallet.h

@ -149,7 +149,7 @@ public: @@ -149,7 +149,7 @@ public:
/** Increment the next transaction order id
@return next transaction order id
*/
int64 IncOrderPosNext();
int64 IncOrderPosNext(CWalletDB *pwalletdb = NULL);
typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair;
typedef std::multimap<int64, TxPair > TxItems;

Loading…
Cancel
Save