Skip to content

Commit f77b1de

Browse files
author
Antoine Riard
committed
Only return early from BlockUntilSyncedToCurrentChain if current tip
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.
1 parent 769ff05 commit f77b1de

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

src/interfaces/chain.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,11 @@ class ChainImpl : public Chain
353353
{
354354
return MakeUnique<NotificationsHandlerImpl>(*this, notifications);
355355
}
356-
void waitForNotificationsIfNewBlocksConnected(const uint256& old_tip) override
356+
void waitForNotificationsIfTipChanged(const uint256& old_tip) override
357357
{
358358
if (!old_tip.IsNull()) {
359359
LOCK(::cs_main);
360360
if (old_tip == ::ChainActive().Tip()->GetBlockHash()) return;
361-
CBlockIndex* block = LookupBlockIndex(old_tip);
362-
if (block && block->GetAncestor(::ChainActive().Height()) == ::ChainActive().Tip()) return;
363361
}
364362
SyncWithValidationInterfaceQueue();
365363
}

src/interfaces/chain.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,8 @@ class Chain
236236
virtual std::unique_ptr<Handler> handleNotifications(Notifications& notifications) = 0;
237237

238238
//! Wait for pending notifications to be processed unless block hash points to the current
239-
//! chain tip, or to a possible descendant of the current chain tip that isn't currently
240-
//! connected.
241-
virtual void waitForNotificationsIfNewBlocksConnected(const uint256& old_tip) = 0;
239+
//! chain tip.
240+
virtual void waitForNotificationsIfTipChanged(const uint256& old_tip) = 0;
242241

243242
//! Register handler for RPC. Command is not copied, so reference
244243
//! needs to remain valid until Handler is disconnected.

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ void CWallet::BlockUntilSyncedToCurrentChain() {
11131113
// for the queue to drain enough to execute it (indicating we are caught up
11141114
// at least with the time we entered this function).
11151115
uint256 last_block_hash = WITH_LOCK(cs_wallet, return m_last_block_processed);
1116-
chain().waitForNotificationsIfNewBlocksConnected(last_block_hash);
1116+
chain().waitForNotificationsIfTipChanged(last_block_hash);
11171117
}
11181118

11191119

0 commit comments

Comments
 (0)