From 43ed8ddca4efa87e62d4cba829ac815ac443be8f Mon Sep 17 00:00:00 2001 From: Riku <46352032+rikublock@users.noreply.github.com> Date: Tue, 15 Oct 2019 11:42:51 +0200 Subject: [PATCH] add missing locks (#144) * add missing locks in GetMasternodeOutpointAndKeys properly locks mutex before selecing masternode collaterals with AvailableCoins * add missing lock in miner properly lock mutex before calling TestBlockValidity --- src/miner.cpp | 9 ++++++--- src/wallet/wallet.cpp | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index bac344da2..177109e68 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -695,9 +695,12 @@ void static XSNMiner(const CChainParams& chainparams, CConnman& connman, } // check if block is valid - CValidationState state; - if (!TestBlockValidity(state, chainparams, *pblock, pindexPrev, false, false)) { - throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, FormatStateMessage(state))); + { + LOCK(cs_main); + CValidationState state; + if (!TestBlockValidity(state, chainparams, *pblock, pindexPrev, false, false)) { + throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, FormatStateMessage(state))); + } } // process proof of stake block diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 21694a9c8..2f8657760 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -5300,7 +5300,10 @@ bool CWallet::GetMasternodeOutpointAndKeys(COutPoint& outpointRet, CPubKey& pubK std::vector vPossibleCoins; CCoinControl coinControl; coinControl.nCoinType = ONLY_MASTERNODE_COLLATERAL; - AvailableCoins(vPossibleCoins, true, &coinControl, 1, MAX_MONEY, MAX_MONEY, 0, 0, 9999999); + { + LOCK2(cs_main, cs_wallet); + AvailableCoins(vPossibleCoins, true, &coinControl, 1, MAX_MONEY, MAX_MONEY, 0, 0, 9999999); + } if(vPossibleCoins.empty()) { LogPrintf("CWallet::GetMasternodeOutpointAndKeys -- Could not locate any valid masternode vin\n"); return false;