From 55a1db4fa2cf62b9766ef382c1e14b3ecbdf67fe Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 15 Apr 2014 17:38:25 +0200 Subject: Solve chainActive-related locking issues - In wallet and GUI code LOCK cs_main as well as cs_wallet when necessary - In main.cpp SendMessages move the TRY_LOCK(cs_main) up, to encompass the call to IsInitialBlockDownload. - Make ActivateBestChain, AddToBlockIndex, IsInitialBlockDownload, InitBlockIndex acquire the cs_main lock Fixes #3997 --- src/qt/walletmodel.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'src/qt/walletmodel.cpp') diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 424c9ee279..61f26107af 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -98,11 +98,21 @@ void WalletModel::updateStatus() void WalletModel::pollBalanceChanged() { - if(chainActive.Height() != cachedNumBlocks) + bool heightChanged = false; + { + LOCK(cs_main); + if(chainActive.Height() != cachedNumBlocks) + { + // Balance and number of transactions might have changed + cachedNumBlocks = chainActive.Height(); + heightChanged = true; + } + } + if(heightChanged) { - // Balance and number of transactions might have changed - cachedNumBlocks = chainActive.Height(); checkBalanceChanged(); + if(transactionTableModel) + transactionTableModel->updateConfirmations(); } } @@ -520,7 +530,7 @@ bool WalletModel::getPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const // returns a list of COutputs from COutPoints void WalletModel::getOutputs(const std::vector& vOutpoints, std::vector& vOutputs) { - LOCK(wallet->cs_wallet); + LOCK2(cs_main, wallet->cs_wallet); BOOST_FOREACH(const COutPoint& outpoint, vOutpoints) { if (!wallet->mapWallet.count(outpoint.hash)) continue; @@ -533,7 +543,7 @@ void WalletModel::getOutputs(const std::vector& vOutpoints, std::vect bool WalletModel::isSpent(const COutPoint& outpoint) const { - LOCK(wallet->cs_wallet); + LOCK2(cs_main, wallet->cs_wallet); return wallet->IsSpent(outpoint.hash, outpoint.n); } @@ -543,7 +553,7 @@ void WalletModel::listCoins(std::map >& mapCoins) std::vector vCoins; wallet->AvailableCoins(vCoins); - LOCK(wallet->cs_wallet); // ListLockedCoins, mapWallet + LOCK2(cs_main, wallet->cs_wallet); // ListLockedCoins, mapWallet std::vector vLockedCoins; wallet->ListLockedCoins(vLockedCoins); @@ -575,25 +585,25 @@ void WalletModel::listCoins(std::map >& mapCoins) bool WalletModel::isLockedCoin(uint256 hash, unsigned int n) const { - LOCK(wallet->cs_wallet); + LOCK2(cs_main, wallet->cs_wallet); return wallet->IsLockedCoin(hash, n); } void WalletModel::lockCoin(COutPoint& output) { - LOCK(wallet->cs_wallet); + LOCK2(cs_main, wallet->cs_wallet); wallet->LockCoin(output); } void WalletModel::unlockCoin(COutPoint& output) { - LOCK(wallet->cs_wallet); + LOCK2(cs_main, wallet->cs_wallet); wallet->UnlockCoin(output); } void WalletModel::listLockedCoins(std::vector& vOutpts) { - LOCK(wallet->cs_wallet); + LOCK2(cs_main, wallet->cs_wallet); wallet->ListLockedCoins(vOutpts); } -- cgit v1.2.3