aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-11-13 23:52:37 +0100
committerLuke Dashjr <luke-jr+git@utopios.org>2012-11-16 18:47:41 +0000
commit2a333587bdd4d77a96cbcf1166310af4aee7efeb (patch)
tree2307f8d087e048283ff7c3e5d3882d35364e6acf
parentacbdc055603905d3a9221662799e6b29df4bc1af (diff)
downloadbitcoin-2a333587bdd4d77a96cbcf1166310af4aee7efeb.tar.xz
Prevent RPC 'move' from deadlocking
It seemed to create two CWalletDB objects that both grab the database lock.
-rw-r--r--src/rpcwallet.cpp4
-rw-r--r--src/wallet.cpp10
-rw-r--r--src/wallet.h2
3 files changed, 10 insertions, 6 deletions
diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp
index 73205102e9..65c5523c83 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 1cfc6cab0c..5fceea7633 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;