Skip to content

Commit

Permalink
[wallet] Make CWallet::FundTransaction atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
promag authored and fdoving committed Dec 20, 2021
1 parent 9912ef8 commit 9da3382
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3199,6 +3199,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)) {
Expand All @@ -3224,7 +3228,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);
}
}
Expand Down

0 comments on commit 9da3382

Please sign in to comment.