Skip to content

Commit bed79e2

Browse files
committed
Guard against division by zero for reindex zerocoin/accumulators
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.
1 parent 48e502a commit bed79e2

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/init.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,11 +1437,13 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
14371437

14381438
// Drop all information from the zerocoinDB and repopulate
14391439
if (GetBoolArg("-reindexzerocoin", false)) {
1440-
uiInterface.InitMessage(_("Reindexing zerocoin database..."));
1441-
std::string strError = ReindexZerocoinDB();
1442-
if (strError != "") {
1443-
strLoadError = strError;
1444-
break;
1440+
if (chainActive.Height() > Params().Zerocoin_StartHeight()) {
1441+
uiInterface.InitMessage(_("Reindexing zerocoin database..."));
1442+
std::string strError = ReindexZerocoinDB();
1443+
if (strError != "") {
1444+
strLoadError = strError;
1445+
break;
1446+
}
14451447
}
14461448
}
14471449

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

14571459
// Force recalculation of accumulators.
14581460
if (GetBoolArg("-reindexaccumulators", false)) {
1459-
CBlockIndex* pindex = chainActive[Params().Zerocoin_StartHeight()];
1460-
while (pindex->nHeight < chainActive.Height()) {
1461-
if (!count(listAccCheckpointsNoDB.begin(), listAccCheckpointsNoDB.end(), pindex->nAccumulatorCheckpoint))
1462-
listAccCheckpointsNoDB.emplace_back(pindex->nAccumulatorCheckpoint);
1463-
pindex = chainActive.Next(pindex);
1461+
if (chainActive.Height() > Params().Zerocoin_Block_V2_Start()) {
1462+
CBlockIndex *pindex = chainActive[Params().Zerocoin_Block_V2_Start()];
1463+
while (pindex->nHeight < chainActive.Height()) {
1464+
if (!count(listAccCheckpointsNoDB.begin(), listAccCheckpointsNoDB.end(),
1465+
pindex->nAccumulatorCheckpoint))
1466+
listAccCheckpointsNoDB.emplace_back(pindex->nAccumulatorCheckpoint);
1467+
pindex = chainActive.Next(pindex);
1468+
}
14641469
}
14651470
}
14661471

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2760,8 +2760,8 @@ bool RecalculatePIVSupply(int nHeightStart)
27602760
bool ReindexAccumulators(list<uint256>& listMissingCheckpoints, string& strError)
27612761
{
27622762
// PIVX: recalculate Accumulator Checkpoints that failed to database properly
2763-
uiInterface.ShowProgress(_("Calculating missing accumulators..."), 0);
2764-
if (!listMissingCheckpoints.empty() && chainActive.Height() >= Params().Zerocoin_StartHeight()) {
2763+
if (!listMissingCheckpoints.empty()) {
2764+
uiInterface.ShowProgress(_("Calculating missing accumulators..."), 0);
27652765
LogPrintf("%s : finding missing checkpoints\n", __func__);
27662766

27672767
//search the chain to see when zerocoin started

0 commit comments

Comments
 (0)