Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,7 @@ void ThreadScriptCheck() {

bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck)
{
AssertLockHeld(cs_main);
// Check it again in case a previous version let a bad block in
if (!CheckBlock(block, state, !fJustCheck, !fJustCheck))
return false;
Expand Down
6 changes: 6 additions & 0 deletions src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ double ClientModel::getVerificationProgress() const

void ClientModel::updateTimer()
{
// Get required lock upfront. This avoids the GUI from getting stuck on
// periodical polls if the core is holding the locks for a longer time -
// for example, during a wallet rescan.
TRY_LOCK(cs_main, lockMain);
if(!lockMain)
return;
// Some quantities (such as number of blocks) change so fast that we don't want to be notified for each change.
// Periodically check and update with a timer.
int newNumBlocks = getNumBlocks();
Expand Down
21 changes: 14 additions & 7 deletions src/qt/transactiontablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <QDebug>
#include <QIcon>
#include <QList>
#include <QTimer>

// Amount column is right-aligned it contains numbers
static int column_alignments[] = {
Expand Down Expand Up @@ -187,17 +186,25 @@ class TransactionTablePriv
{
TransactionRecord *rec = &cachedWallet[idx];

// Get required locks upfront. This avoids the GUI from getting
// stuck if the core is holding the locks for a longer time - for
// example, during a wallet rescan.
//
// If a status update is needed (blocks came in since last check),
// update the status of this transaction from the wallet. Otherwise,
// simply re-use the cached status.
LOCK2(cs_main, wallet->cs_wallet);
if(rec->statusUpdateNeeded())
TRY_LOCK(cs_main, lockMain);
if(lockMain)
{
std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(rec->hash);

if(mi != wallet->mapWallet.end())
TRY_LOCK(wallet->cs_wallet, lockWallet);
if(lockWallet && rec->statusUpdateNeeded())
{
rec->updateStatus(mi->second);
std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(rec->hash);

if(mi != wallet->mapWallet.end())
{
rec->updateStatus(mi->second);
}
}
}
return rec;
Expand Down
25 changes: 14 additions & 11 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,21 @@ void WalletModel::updateStatus()

void WalletModel::pollBalanceChanged()
{
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)
// Get required locks upfront. This avoids the GUI from getting stuck on
// periodical polls if the core is holding the locks for a longer time -
// for example, during a wallet rescan.
TRY_LOCK(cs_main, lockMain);
if(!lockMain)
return;
TRY_LOCK(wallet->cs_wallet, lockWallet);
if(!lockWallet)
return;

if(chainActive.Height() != cachedNumBlocks)
{
// Balance and number of transactions might have changed
cachedNumBlocks = chainActive.Height();

checkBalanceChanged();
if(transactionTableModel)
transactionTableModel->updateConfirmations();
Expand Down
2 changes: 1 addition & 1 deletion src/test/rpc_wallet_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
// Test RPC calls for various wallet statistics
Value r;

LOCK(pwalletMain->cs_wallet);
LOCK2(cs_main, pwalletMain->cs_wallet);

BOOST_CHECK_NO_THROW(CallRPC("listunspent"));
BOOST_CHECK_THROW(CallRPC("listunspent string"), runtime_error);
Expand Down
3 changes: 3 additions & 0 deletions src/test/script_P2SH_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ BOOST_AUTO_TEST_SUITE(script_P2SH_tests)

BOOST_AUTO_TEST_CASE(sign)
{
LOCK(cs_main);
// Pay-to-script-hash looks like this:
// scriptSig: <sig> <sig...> <serialized_script>
// scriptPubKey: HASH160 <hash> EQUAL
Expand Down Expand Up @@ -147,6 +148,7 @@ BOOST_AUTO_TEST_CASE(norecurse)

BOOST_AUTO_TEST_CASE(set)
{
LOCK(cs_main);
// Test the CScript::Set* methods
CBasicKeyStore keystore;
CKey key[4];
Expand Down Expand Up @@ -250,6 +252,7 @@ BOOST_AUTO_TEST_CASE(switchover)

BOOST_AUTO_TEST_CASE(AreInputsStandard)
{
LOCK(cs_main);
CCoinsView coinsDummy;
CCoinsViewCache coins(coinsDummy);
CBasicKeyStore keystore;
Expand Down
1 change: 1 addition & 0 deletions src/test/transaction_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ BOOST_AUTO_TEST_CASE(test_Get)

BOOST_AUTO_TEST_CASE(test_IsStandard)
{
LOCK(cs_main);
CBasicKeyStore keystore;
CCoinsView coinsDummy;
CCoinsViewCache coins(coinsDummy);
Expand Down