Skip to content

Commit b6a16fa

Browse files
committed
Merge #18123: gui: Fix race in WalletModel::pollBalanceChanged
bf36a3c gui: Fix race in WalletModel::pollBalanceChanged (Russell Yanofsky) Pull request description: 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/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 #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. MarcoFalke also points out that a0704a8 could lead to GUI hangs as well, because previously the pollBalanceChanged method, which runs on the GUI thread, would only make a nonblocking TRY_LOCK(cs_main) call, but after could make blocking LOCK(cs_main) calls, potentially locking up the GUI. Thanks to John Newbery for finding this bug this while reviewing bitcoin/bitcoin#17954. ACKs for top commit: Empact: utACK bitcoin/bitcoin@bf36a3c jonasschnelli: utACK bf36a3c Tree-SHA512: 1f4f229fa70a6d1fcf7be3806dca3252e86bc1755168fb421258389eb95aae67f863cb1216e6dc086b596c33560d1136215a4c87b5ff890abc8baaa3333b47f4
2 parents 2bdc476 + bf36a3c commit b6a16fa

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/qt/walletmodel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ void WalletModel::pollBalanceChanged()
8282
return;
8383
}
8484

85-
if(fForceCheckBalanceChanged || m_node.getNumBlocks() != cachedNumBlocks)
85+
if(fForceCheckBalanceChanged || numBlocks != cachedNumBlocks)
8686
{
8787
fForceCheckBalanceChanged = false;
8888

8989
// Balance and number of transactions might have changed
90-
cachedNumBlocks = m_node.getNumBlocks();
90+
cachedNumBlocks = numBlocks;
9191

9292
checkBalanceChanged(new_balances);
9393
if(transactionTableModel)

0 commit comments

Comments
 (0)