Skip to content

Commit 03a5dc9

Browse files
committed
[wallet] Make CWallet::FundTransaction atomic
1 parent 95d4450 commit 03a5dc9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/wallet/wallet.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2605,6 +2605,10 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
26052605
coinControl.Select(txin.prevout);
26062606
}
26072607

2608+
// Acquire the locks to prevent races to the new locked unspents between the
2609+
// CreateTransaction call and LockCoin calls (when lockUnspents is true).
2610+
LOCK2(cs_main, cs_wallet);
2611+
26082612
CReserveKey reservekey(this);
26092613
CWalletTx wtx;
26102614
if (!CreateTransaction(vecSend, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, coinControl, false)) {
@@ -2630,7 +2634,6 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
26302634
tx.vin.push_back(txin);
26312635

26322636
if (lockUnspents) {
2633-
LOCK2(cs_main, cs_wallet);
26342637
LockCoin(txin.prevout);
26352638
}
26362639
}

0 commit comments

Comments
 (0)