Skip to content

Commit

Permalink
Guard against division by zero for reindex zerocoin/accumulators
Browse files Browse the repository at this point in the history
in the event that the local chainActive is equal or below that of the
relevant zerocoin block heights, there is nothing to do, so bypass
the internal process.
  • Loading branch information
Fuzzbawls committed Jun 9, 2018
1 parent 48e502a commit bed79e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
25 changes: 15 additions & 10 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1437,11 +1437,13 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)

// Drop all information from the zerocoinDB and repopulate
if (GetBoolArg("-reindexzerocoin", false)) {
uiInterface.InitMessage(_("Reindexing zerocoin database..."));
std::string strError = ReindexZerocoinDB();
if (strError != "") {
strLoadError = strError;
break;
if (chainActive.Height() > Params().Zerocoin_StartHeight()) {
uiInterface.InitMessage(_("Reindexing zerocoin database..."));
std::string strError = ReindexZerocoinDB();
if (strError != "") {
strLoadError = strError;
break;
}
}
}

Expand All @@ -1456,11 +1458,14 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)

// Force recalculation of accumulators.
if (GetBoolArg("-reindexaccumulators", false)) {
CBlockIndex* pindex = chainActive[Params().Zerocoin_StartHeight()];
while (pindex->nHeight < chainActive.Height()) {
if (!count(listAccCheckpointsNoDB.begin(), listAccCheckpointsNoDB.end(), pindex->nAccumulatorCheckpoint))
listAccCheckpointsNoDB.emplace_back(pindex->nAccumulatorCheckpoint);
pindex = chainActive.Next(pindex);
if (chainActive.Height() > Params().Zerocoin_Block_V2_Start()) {
CBlockIndex *pindex = chainActive[Params().Zerocoin_Block_V2_Start()];
while (pindex->nHeight < chainActive.Height()) {
if (!count(listAccCheckpointsNoDB.begin(), listAccCheckpointsNoDB.end(),
pindex->nAccumulatorCheckpoint))
listAccCheckpointsNoDB.emplace_back(pindex->nAccumulatorCheckpoint);
pindex = chainActive.Next(pindex);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2760,8 +2760,8 @@ bool RecalculatePIVSupply(int nHeightStart)
bool ReindexAccumulators(list<uint256>& listMissingCheckpoints, string& strError)
{
// PIVX: recalculate Accumulator Checkpoints that failed to database properly
uiInterface.ShowProgress(_("Calculating missing accumulators..."), 0);
if (!listMissingCheckpoints.empty() && chainActive.Height() >= Params().Zerocoin_StartHeight()) {
if (!listMissingCheckpoints.empty()) {
uiInterface.ShowProgress(_("Calculating missing accumulators..."), 0);
LogPrintf("%s : finding missing checkpoints\n", __func__);

//search the chain to see when zerocoin started
Expand Down

0 comments on commit bed79e2

Please sign in to comment.