aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorJoão Barbosa <joao.paulo.barbosa@gmail.com>2017-12-14 03:18:29 +0000
committerJoão Barbosa <joao.paulo.barbosa@gmail.com>2017-12-14 03:18:29 +0000
commit03a5dc9c3c522c500c77fdecd52d091db048d1b0 (patch)
tree0241368b9a37bed869fde518cf7be99196bee67e /src/wallet
parent95d4450a41e9b3f7a739eeefec322bf9366ce824 (diff)
downloadbitcoin-03a5dc9c3c522c500c77fdecd52d091db048d1b0.tar.xz
[wallet] Make CWallet::FundTransaction atomic
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/wallet.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 4777641e72..106c910258 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -2605,6 +2605,10 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
coinControl.Select(txin.prevout);
}
+ // Acquire the locks to prevent races to the new locked unspents between the
+ // CreateTransaction call and LockCoin calls (when lockUnspents is true).
+ LOCK2(cs_main, cs_wallet);
+
CReserveKey reservekey(this);
CWalletTx wtx;
if (!CreateTransaction(vecSend, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, coinControl, false)) {
@@ -2630,7 +2634,6 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
tx.vin.push_back(txin);
if (lockUnspents) {
- LOCK2(cs_main, cs_wallet);
LockCoin(txin.prevout);
}
}