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.
pull/15931/head
Antoine Riard 5 years ago
parent 769ff05e48
commit f77b1de16f

@ -353,13 +353,11 @@ public:
{ {
return MakeUnique<NotificationsHandlerImpl>(*this, notifications); return MakeUnique<NotificationsHandlerImpl>(*this, notifications);
} }
void waitForNotificationsIfNewBlocksConnected(const uint256& old_tip) override void waitForNotificationsIfTipChanged(const uint256& old_tip) override
{ {
if (!old_tip.IsNull()) { if (!old_tip.IsNull()) {
LOCK(::cs_main); LOCK(::cs_main);
if (old_tip == ::ChainActive().Tip()->GetBlockHash()) return; if (old_tip == ::ChainActive().Tip()->GetBlockHash()) return;
CBlockIndex* block = LookupBlockIndex(old_tip);
if (block && block->GetAncestor(::ChainActive().Height()) == ::ChainActive().Tip()) return;
} }
SyncWithValidationInterfaceQueue(); SyncWithValidationInterfaceQueue();
} }

@ -236,9 +236,8 @@ public:
virtual std::unique_ptr<Handler> handleNotifications(Notifications& notifications) = 0; virtual std::unique_ptr<Handler> handleNotifications(Notifications& notifications) = 0;
//! Wait for pending notifications to be processed unless block hash points to the current //! Wait for pending notifications to be processed unless block hash points to the current
//! chain tip, or to a possible descendant of the current chain tip that isn't currently //! chain tip.
//! connected. virtual void waitForNotificationsIfTipChanged(const uint256& old_tip) = 0;
virtual void waitForNotificationsIfNewBlocksConnected(const uint256& old_tip) = 0;
//! Register handler for RPC. Command is not copied, so reference //! Register handler for RPC. Command is not copied, so reference
//! needs to remain valid until Handler is disconnected. //! needs to remain valid until Handler is disconnected.

@ -1113,7 +1113,7 @@ void CWallet::BlockUntilSyncedToCurrentChain() {
// for the queue to drain enough to execute it (indicating we are caught up // for the queue to drain enough to execute it (indicating we are caught up
// at least with the time we entered this function). // at least with the time we entered this function).
uint256 last_block_hash = WITH_LOCK(cs_wallet, return m_last_block_processed); uint256 last_block_hash = WITH_LOCK(cs_wallet, return m_last_block_processed);
chain().waitForNotificationsIfNewBlocksConnected(last_block_hash); chain().waitForNotificationsIfTipChanged(last_block_hash);
} }

Loading…
Cancel
Save