diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2012-11-13 23:52:37 +0100 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2012-11-14 00:31:56 +0100 |
commit | 4291e8feab308cb9c7840d74fc7aacf137a7c21f (patch) | |
tree | fd2376f4546dfd496dbd8367e5536ee47dae5304 | |
parent | eb49457ff279721cc3cef10fe68fd75b4aa71833 (diff) |
Prevent RPC 'move' from deadlocking
It seemed to create two CWalletDB objects that both grab the
database lock.
-rw-r--r-- | src/rpcwallet.cpp | 4 | ||||
-rw-r--r-- | src/wallet.cpp | 10 | ||||
-rw-r--r-- | src/wallet.h | 2 |
3 files changed, 10 insertions, 6 deletions
diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index cc2e8ab46b..9e914f336d 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -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) // Credit CAccountingEntry credit; - credit.nOrderPos = pwalletMain->IncOrderPosNext(); + credit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb); credit.strAccount = strTo; credit.nCreditDebit = nAmount; credit.nTime = nNow; diff --git a/src/wallet.cpp b/src/wallet.cpp index 1a6a1082b1..3e3d5eac57 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -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; } diff --git a/src/wallet.h b/src/wallet.h index c5f1243907..5c312ef5eb 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -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; |