Skip to content

Commit 9af5f9c

Browse files
committed
Move uiInterface.NotifyBlockTip signal above the core/wallet signal
- This will keep getbestblockhash more in sync with blocknotify callbacks
1 parent 4082e46 commit 9af5f9c

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

src/main.cpp

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2606,40 +2606,43 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
26062606
// When we reach this point, we switched to a new tip (stored in pindexNewTip).
26072607

26082608
// Notifications/callbacks that can run without cs_main
2609-
if (!fInitialDownload) {
2610-
// Find the hashes of all blocks that weren't previously in the best chain.
2611-
std::vector<uint256> vHashes;
2612-
CBlockIndex *pindexToAnnounce = pindexNewTip;
2613-
while (pindexToAnnounce != pindexFork) {
2614-
vHashes.push_back(pindexToAnnounce->GetBlockHash());
2615-
pindexToAnnounce = pindexToAnnounce->pprev;
2616-
if (vHashes.size() == MAX_BLOCKS_TO_ANNOUNCE) {
2617-
// Limit announcements in case of a huge reorganization.
2618-
// Rely on the peer's synchronization mechanism in that case.
2619-
break;
2609+
// Always notify the UI if a new block tip was connected
2610+
if (pindexFork != pindexNewTip) {
2611+
uiInterface.NotifyBlockTip(fInitialDownload, pindexNewTip);
2612+
2613+
if (!fInitialDownload) {
2614+
// Find the hashes of all blocks that weren't previously in the best chain.
2615+
std::vector<uint256> vHashes;
2616+
CBlockIndex *pindexToAnnounce = pindexNewTip;
2617+
while (pindexToAnnounce != pindexFork) {
2618+
vHashes.push_back(pindexToAnnounce->GetBlockHash());
2619+
pindexToAnnounce = pindexToAnnounce->pprev;
2620+
if (vHashes.size() == MAX_BLOCKS_TO_ANNOUNCE) {
2621+
// Limit announcements in case of a huge reorganization.
2622+
// Rely on the peer's synchronization mechanism in that case.
2623+
break;
2624+
}
26202625
}
2621-
}
2622-
// Relay inventory, but don't relay old inventory during initial block download.
2623-
int nBlockEstimate = 0;
2624-
if (fCheckpointsEnabled)
2625-
nBlockEstimate = Checkpoints::GetTotalBlocksEstimate(chainparams.Checkpoints());
2626-
{
2627-
LOCK(cs_vNodes);
2628-
BOOST_FOREACH(CNode* pnode, vNodes) {
2629-
if (chainActive.Height() > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate)) {
2630-
BOOST_REVERSE_FOREACH(const uint256& hash, vHashes) {
2631-
pnode->PushBlockHash(hash);
2626+
// Relay inventory, but don't relay old inventory during initial block download.
2627+
int nBlockEstimate = 0;
2628+
if (fCheckpointsEnabled)
2629+
nBlockEstimate = Checkpoints::GetTotalBlocksEstimate(chainparams.Checkpoints());
2630+
{
2631+
LOCK(cs_vNodes);
2632+
BOOST_FOREACH(CNode* pnode, vNodes) {
2633+
if (chainActive.Height() > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate)) {
2634+
BOOST_REVERSE_FOREACH(const uint256& hash, vHashes) {
2635+
pnode->PushBlockHash(hash);
2636+
}
26322637
}
26332638
}
26342639
}
2635-
}
2636-
// Notify external listeners about the new tip.
2637-
if (!vHashes.empty()) {
2638-
GetMainSignals().UpdatedBlockTip(pindexNewTip);
2640+
// Notify external listeners about the new tip.
2641+
if (!vHashes.empty()) {
2642+
GetMainSignals().UpdatedBlockTip(pindexNewTip);
2643+
}
26392644
}
26402645
}
2641-
// Always notify the UI if a new block tip was connected
2642-
uiInterface.NotifyBlockTip(fInitialDownload, pindexNewTip);
26432646
} while(pindexMostWork != chainActive.Tip());
26442647
CheckBlockIndex(chainparams.GetConsensus());
26452648

0 commit comments

Comments
 (0)