Skip to content

Commit

Permalink
Merge branch 'develop' into feature/fastlaunch
Browse files Browse the repository at this point in the history
  • Loading branch information
cdonnachie authored Sep 5, 2023
2 parents 4d8db4d + 229d5b0 commit a0cfadf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/txdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,23 @@ bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) {
return true;
}

bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex)
bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex, int& nHighest)
{
std::unique_ptr<CDBIterator> pcursor(NewIterator());

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

int nCount = 0;
int nLastPercent = -1;

// Load m_block_index
while (pcursor->Valid()) {
int nPercent = 100 * nCount / nHighest;
if (nPercent > nLastPercent && nPercent % 10 == 0) {
uiInterface.InitMessage(strprintf(_("Loading blocks... %d%%").translated, (100 * nCount) / nHighest));
nLastPercent = nPercent;
}
nCount++;
if (ShutdownRequested()) return false;
std::pair<uint8_t, uint256> key;
if (pcursor->GetKey(key) && key.first == DB_BLOCK_INDEX) {
Expand All @@ -289,6 +298,8 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
CBlockIndex* pindexNew = insertBlockIndex(diskindex.GetBlockHash());
pindexNew->pprev = insertBlockIndex(diskindex.hashPrev);
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 @@ -84,7 +84,7 @@ class CBlockTreeDB : public CDBWrapper
void ReadReindexing(bool &fReindexing);
bool WriteFlag(const std::string &name, bool fValue);
bool ReadFlag(const std::string &name, bool &fValue);
bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex);
bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex, int& nHighest);
};

#endif // DIGIBYTE_TXDB_H
11 changes: 10 additions & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3872,7 +3872,8 @@ bool BlockManager::LoadBlockIndex(
CBlockTreeDB& blocktree,
std::set<CBlockIndex*, CBlockIndexWorkComparator>& block_index_candidates)
{
if (!blocktree.LoadBlockIndexGuts(consensus_params, [this](const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return this->InsertBlockIndex(hash); }))
int nHighest = 1;
if (!blocktree.LoadBlockIndexGuts(consensus_params, [this](const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return this->InsertBlockIndex(hash); }, nHighest))
return false;

// Calculate nChainWork
Expand All @@ -3884,8 +3885,15 @@ bool BlockManager::LoadBlockIndex(
vSortedByHeight.push_back(std::make_pair(pindex->nHeight, pindex));
}
sort(vSortedByHeight.begin(), vSortedByHeight.end());
int nHeight = 0;
int nLastPercent = -1;
for (const std::pair<int, CBlockIndex*>& item : vSortedByHeight)
{
int nPercent = 100 * nHeight / nHighest;
if (nPercent > nLastPercent && nPercent % 10 == 0) {
uiInterface.InitMessage(strprintf(_("Indexing blocks... %d%%").translated, (100 * nHeight) / nHighest));
nLastPercent = nPercent;
}
if (ShutdownRequested()) return false;
CBlockIndex* pindex = item.second;

Expand All @@ -3895,6 +3903,7 @@ bool BlockManager::LoadBlockIndex(
pindex->lastAlgoBlocks[pindex->GetAlgo()] = pindex;
}

nHeight = pindex-> nHeight;
pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + GetBlockProof(*pindex);
pindex->nTimeMax = (pindex->pprev ? std::max(pindex->pprev->nTimeMax, pindex->nTime) : pindex->nTime);
// We can link the chain of blocks for which we've received transactions at some point.
Expand Down

0 comments on commit a0cfadf

Please sign in to comment.