Skip to content

Commit

Permalink
Only return early from BlockUntilSyncedToCurrentChain if current tip
Browse files Browse the repository at this point in the history
is exact match

In the next commit, we start using BlockConnected/BlockDisconnected
callbacks to establish tx depth, rather than querying the chain
directly.

Currently, BlockUntilSyncedToCurrentChain will return early if
the best block processed by the wallet is a descendant of the node'tip.
That means that in the case of a re-org, it won't wait for the
BlockDisconnected callbacks that have been enqueued during the re-org
but have not yet been triggered in the wallet.

Change BlockUntilSyncedToCurrentChain to only return early if the
wallet's m_last_block_processed matches the tip exactly. This ensures
that there are no BlockDisconnected or BlockConnected callbacks
in-flight.

Adaptation of btc@f77b1de16feee097a88e99d2ecdd4d84beb4f915
  • Loading branch information
furszy committed Mar 10, 2021
1 parent 8aa2d31 commit 9adeb61
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1363,12 +1363,9 @@ void CWallet::BlockUntilSyncedToCurrentChain() {
uint256 last_block_hash = WITH_LOCK(cs_wallet, return m_last_block_processed);
LOCK(cs_main);
const CBlockIndex* initialChainTip = chainActive.Tip();

if (!last_block_hash.IsNull()) {
auto it = mapBlockIndex.find(last_block_hash);
if (it == mapBlockIndex.end() || it->second->GetAncestor(initialChainTip->nHeight) == initialChainTip) {
if (!last_block_hash.IsNull() && initialChainTip &&
last_block_hash == initialChainTip->GetBlockHash()) {
return;
}
}
}

Expand Down

0 comments on commit 9adeb61

Please sign in to comment.