Skip to content

Commit

Permalink
Add extra lock check for OSX build
Browse files Browse the repository at this point in the history
Apparently my upstream checkpoint was in the middle of a series of
commits by ianofsky separating wallet from the main code.  This means
that I have to add this main lock which will be replaced by the
locked_chain interface in a subsequence catchup.
  • Loading branch information
stevenroose committed May 15, 2019
1 parent 872d39f commit ad3d496
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5493,6 +5493,7 @@ UniValue claimpegin(const JSONRPCRequest& request)

// To check if it's not double spending an existing pegin UTXO, we check mempool acceptance.
CValidationState acceptState;
LockAnnotation lock(::cs_main); //TODO(stevenroose) replace with locked_chain later
bool accepted = ::AcceptToMemoryPool(mempool, acceptState, MakeTransactionRef(mtx), nullptr /* pfMissingInputs */,
nullptr /* plTxnReplaced */, false /* bypass_limits */, maxTxFee, true /* test_accept */);
if (!accepted) {
Expand Down
11 changes: 6 additions & 5 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2510,6 +2510,7 @@ bool CWallet::SelectCoinsMinConf(const CAmountMap& mapTargetValue, const CoinEli

bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAmountMap& mapTargetValue, std::set<CInputCoin>& setCoinsRet, CAmountMap& mapValueRet, const CCoinControl& coin_control, CoinSelectionParams& coin_selection_params, bool& bnb_used) const
{
AssertLockHeld(cs_wallet); // mapWallet
std::vector<COutput> vCoins(vAvailableCoins);

// coin control -> return all selected outputs (we want all selected to go into the transaction for sure)
Expand Down Expand Up @@ -2684,6 +2685,11 @@ 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).
auto locked_chain = chain().lock();
LOCK(cs_wallet);

// Also account for the assets in the preset inputs.
std::vector<COutPoint> vPresetInputs;
coinControl.ListSelected(vPresetInputs);
Expand All @@ -2700,11 +2706,6 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
vChangeKey.push_back(std::unique_ptr<CReserveKey>(new CReserveKey(this)));
}

// Acquire the locks to prevent races to the new locked unspents between the
// CreateTransaction call and LockCoin calls (when lockUnspents is true).
auto locked_chain = chain().lock();
LOCK(cs_wallet);

CTransactionRef tx_new;
BlindDetails* blind_details = g_con_elementsmode ? new BlindDetails() : NULL;
if (!CreateTransaction(*locked_chain, vecSend, tx_new, vChangeKey, nFeeRet, nChangePosInOut, strFailReason, coinControl, false, blind_details)) {
Expand Down

0 comments on commit ad3d496

Please sign in to comment.