diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5d431d10fe..4a21be8ce4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -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) { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 265e39afa6..272693e500 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2510,6 +2510,7 @@ bool CWallet::SelectCoinsMinConf(const CAmountMap& mapTargetValue, const CoinEli bool CWallet::SelectCoins(const std::vector& vAvailableCoins, const CAmountMap& mapTargetValue, std::set& setCoinsRet, CAmountMap& mapValueRet, const CCoinControl& coin_control, CoinSelectionParams& coin_selection_params, bool& bnb_used) const { + AssertLockHeld(cs_wallet); // mapWallet std::vector vCoins(vAvailableCoins); // coin control -> return all selected outputs (we want all selected to go into the transaction for sure) @@ -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 vPresetInputs; coinControl.ListSelected(vPresetInputs); @@ -2700,11 +2706,6 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC vChangeKey.push_back(std::unique_ptr(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)) {