Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add progress logs for loading block/index #592

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6019,10 +6019,11 @@ CBlockIndex * InsertBlockIndex(uint256 hash)
bool static LoadBlockIndexDB()
{
const CChainParams& chainparams = Params();
int nHighest = 1;
LogPrintf("%s: start loading guts\n", __func__);
{
LOCK(cs_main);
if (!pblocktree->LoadBlockIndexGuts())
if (!pblocktree->LoadBlockIndexGuts(nHighest))
return false;
}
LogPrintf("%s: loaded guts\n", __func__);
Expand All @@ -6037,10 +6038,18 @@ bool static LoadBlockIndexDB()
vSortedByHeight.push_back(make_pair(pindex->nHeight, pindex));
}
sort(vSortedByHeight.begin(), vSortedByHeight.end());

int nHeight = 0;
int nLastPercent = -1;
for(const auto& item : vSortedByHeight)
{
int nPercent = 100 * nHeight / nHighest;
if (nPercent > nLastPercent && nPercent % 10 == 0) {
LogPrintf("Indexing blocks... %d%%\n", (100 * nHeight) / nHighest);
nLastPercent = nPercent;
}
CBlockIndex* pindex = item.second;
nHeight = pindex-> nHeight;

pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + GetBlockProof(*pindex);
// We can link the chain of blocks for which we've received transactions at some point.
// Pruned nodes may have deleted the block.
Expand Down
15 changes: 13 additions & 2 deletions src/txdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,14 +707,23 @@ bool CBlockTreeDB::blockOnchainActive(const uint256 &hash) {
return true;
}

bool CBlockTreeDB::LoadBlockIndexGuts()
bool CBlockTreeDB::LoadBlockIndexGuts(int& nHighest)
{
boost::scoped_ptr<CDBIterator> pcursor(NewIterator());

pcursor->Seek(make_pair(DB_BLOCK_INDEX, uint256()));

int nCount = 0;
int nLastPercent = -1;

// Load mapBlockIndex
while (pcursor->Valid()) {
int nPercent = 100 * nCount / nHighest;
if (nPercent > nLastPercent && nPercent % 10 == 0) {
LogPrintf("Loading blocks... %d%%\n", (100 * nCount) / nHighest);
nLastPercent = nPercent;
}
nCount++;
boost::this_thread::interruption_point();
std::pair<char, uint256> key;
if (pcursor->GetKey(key) && key.first == DB_BLOCK_INDEX) {
Expand All @@ -723,7 +732,9 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
// Construct block index object
CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetBlockHash());
pindexNew->pprev = InsertBlockIndex(diskindex.hashPrev);
pindexNew->nHeight = diskindex.nHeight;
pindexNew->nHeight = diskindex.nHeight;
if (diskindex.nHeight > nHighest)
nHighest = diskindex.nHeight;
pindexNew->nFile = diskindex.nFile;
pindexNew->nDataPos = diskindex.nDataPos;
pindexNew->nUndoPos = diskindex.nUndoPos;
Expand Down
2 changes: 1 addition & 1 deletion src/txdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class CBlockTreeDB : public CDBWrapper
* NOTE: this does no consistency check beyond verifying records exist
* @returns true on success
*/
bool LoadBlockIndexGuts();
bool LoadBlockIndexGuts(int& nHighest);
/****
* Check if a block is on the active chain
* @param hash the block hash
Expand Down
Loading