Skip to content

Commit

Permalink
Report reindexing progress in GUI
Browse files Browse the repository at this point in the history
(cherry picked from commit b4d24e1)

Zcash: Excludes GUI changes (as we don't have the QT GUI).
  • Loading branch information
sipa authored and str4d committed Aug 9, 2021
1 parent d6d3944 commit d3ccecd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
4 changes: 3 additions & 1 deletion qa/rpc-tests/reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, \
start_node, stop_node, wait_bitcoinds

import time

class ReindexTest(BitcoinTestFramework):

Expand All @@ -30,6 +30,8 @@ def reindex(self, justchainstate=False):
stop_node(self.nodes[0], 0)
wait_bitcoinds()
self.nodes[0]=start_node(0, self.options.tmpdir, ["-debug", "-reindex-chainstate" if justchainstate else "-reindex", "-checkblockindex=1"])
while self.nodes[0].getblockcount() < blockcount:
time.sleep(0.1)
assert_equal(self.nodes[0].getblockcount(), blockcount)
print("Success")

Expand Down
39 changes: 39 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4076,6 +4076,28 @@ static bool ActivateBestChainStep(CValidationState& state, const CChainParams& c
return true;
}

static void NotifyHeaderTip(const Consensus::Params& params) {
bool fNotify = false;
bool fInitialBlockDownload = false;
static CBlockIndex* pindexHeaderOld = NULL;
CBlockIndex* pindexHeader = NULL;
{
LOCK(cs_main);
if (!setBlockIndexCandidates.empty()) {
pindexHeader = *setBlockIndexCandidates.rbegin();
}
if (pindexHeader != pindexHeaderOld) {
fNotify = true;
fInitialBlockDownload = IsInitialBlockDownload(params);
pindexHeaderOld = pindexHeader;
}
}
// Send block tip changed notifications without cs_main
if (fNotify) {
uiInterface.NotifyHeaderTip(fInitialBlockDownload, pindexHeader);
}
}

/**
* Make the best chain active, in multiple steps. The result is either failure
* or an activated best chain. pblock is either NULL or a pointer to a block
Expand Down Expand Up @@ -4896,6 +4918,8 @@ bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, c
return error("%s: AcceptBlock FAILED", __func__);
}

NotifyHeaderTip(chainparams.GetConsensus());

if (!ActivateBestChain(state, chainparams, pblock))
return error("%s: ActivateBestChain failed", __func__);

Expand Down Expand Up @@ -5735,6 +5759,16 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
LogPrint("reindex", "Block Import: already had block %s at height %d\n", hash.ToString(), mapBlockIndex[hash]->nHeight);
}

// Activate the genesis block so normal node progress can continue
if (hash == chainparams.GetConsensus().hashGenesisBlock) {
CValidationState state;
if (!ActivateBestChain(state, chainparams)) {
break;
}
}

NotifyHeaderTip(chainparams.GetConsensus());

// Recursively process earlier encountered successors of this block
deque<uint256> queue;
queue.push_back(hash);
Expand All @@ -5756,6 +5790,7 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
}
}
range.first = mapBlocksUnknownParent.erase(range.first);
NotifyHeaderTip(chainparams.GetConsensus());
}
}
} catch (const std::exception& e) {
Expand Down Expand Up @@ -6772,6 +6807,7 @@ bool static ProcessMessage(const CChainParams& chainparams, CNode* pfrom, string
ReadCompactSize(vRecv); // ignore tx count; assume it is 0.
}

{
LOCK(cs_main);

if (nCount == 0) {
Expand Down Expand Up @@ -6825,6 +6861,9 @@ bool static ProcessMessage(const CChainParams& chainparams, CNode* pfrom, string
}

CheckBlockIndex(chainparams.GetConsensus());
}

NotifyHeaderTip(chainparams.GetConsensus());
}

else if (strCommand == "block" && !fImporting && !fReindex) // Ignore blocks received while importing
Expand Down
3 changes: 3 additions & 0 deletions src/ui_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class CClientUIInterface
/** New block has been accepted */
boost::signals2::signal<void (bool, const CBlockIndex *)> NotifyBlockTip;

/** Best header has changed */
boost::signals2::signal<void (bool, const CBlockIndex *)> NotifyHeaderTip;

/** Banlist did change. */
boost::signals2::signal<void (void)> BannedListChanged;

Expand Down

0 comments on commit d3ccecd

Please sign in to comment.