Skip to content

Commit

Permalink
gui: Fix race in WalletModel::pollBalanceChanged
Browse files Browse the repository at this point in the history
Poll function was wrongly setting cached height to the current chain height
instead of the chain height at the time of polling.

This bug could cause balances to appear out of date, and was first introduced
bitcoin@a0704a8#diff-2e3836af182cfb375329c3463ffd91f8L117.
Before that commit, there wasn't a problem because cs_main was held during the
poll update.

Currently, the problem should be rare. But if
8937d99 from bitcoin#17954 were merged, the problem
would get worse, because the wrong cachedNumBlocks value would be set if the
wallet was polled in the interval between a block being connected and it
processing the BlockConnected notification.

Thanks to John Newbery <john@johnnewbery.com> for catching this while reviewing
bitcoin#17954.
  • Loading branch information
ryanofsky committed Feb 11, 2020
1 parent 98264e2 commit 37d27bc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/qt/walletmodel.cpp
Expand Up @@ -82,12 +82,12 @@ void WalletModel::pollBalanceChanged()
return;
}

if(fForceCheckBalanceChanged || m_node.getNumBlocks() != cachedNumBlocks)
if(fForceCheckBalanceChanged || numBlocks != cachedNumBlocks)
{
fForceCheckBalanceChanged = false;

// Balance and number of transactions might have changed
cachedNumBlocks = m_node.getNumBlocks();
cachedNumBlocks = numBlocks;

checkBalanceChanged(new_balances);
if(transactionTableModel)
Expand Down

0 comments on commit 37d27bc

Please sign in to comment.