Skip to content

Commit 4386edd

Browse files
presstabFuzzbawls
authored andcommitted
Do not delete and recalculate accumulators on initial block verificat… (PIVX-Project#46)
* Do not delete and recalculate accumulators on initial block verification. * Close unclosed statement.
1 parent c163d80 commit 4386edd

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

src/init.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,17 +1317,21 @@ bool AppInit2(boost::thread_group& threadGroup)
13171317
CAccumulators::getInstance().ClearAccCheckpointsNoDB();
13181318

13191319
uiInterface.InitMessage(_("Verifying blocks..."));
1320+
fVerifyingBlocks = true;
13201321
if (!CVerifyDB().VerifyDB(pcoinsdbview, GetArg("-checklevel", 4), // Zerocoin must check at level 4
13211322
GetArg("-checkblocks", 500))) {
13221323
strLoadError = _("Corrupted block database detected");
1324+
fVerifyingBlocks = false;
13231325
break;
13241326
}
13251327
} catch (std::exception& e) {
13261328
if (fDebug) LogPrintf("%s\n", e.what());
13271329
strLoadError = _("Error opening block database");
1330+
fVerifyingBlocks = false;
13281331
break;
13291332
}
13301333

1334+
fVerifyingBlocks = false;
13311335
fLoaded = true;
13321336
} while (false);
13331337

src/main.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ bool fReindex = false;
7575
bool fTxIndex = true;
7676
bool fIsBareMultisigStd = true;
7777
bool fCheckBlockIndex = false;
78+
bool fVerifyingBlocks = false;
7879
unsigned int nCoinCacheSize = 5000;
7980
bool fAlerts = DEFAULT_ALERTS;
8081

@@ -2625,14 +2626,15 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
26252626
if (tx.ContainsZerocoins()) {
26262627
if (tx.IsZerocoinSpend()) {
26272628
//erase all zerocoinspends in this transaction
2628-
for (const CTxIn txin : tx.vin){
2629+
for (const CTxIn txin : tx.vin) {
26292630
if (txin.scriptSig.IsZerocoinSpend()) {
26302631
CoinSpend spend = TxInToZerocoinSpend(txin);
2631-
if(!CAccumulators::getInstance().EraseCoinSpend(spend.getCoinSerialNumber()))
2632+
if (!CAccumulators::getInstance().EraseCoinSpend(spend.getCoinSerialNumber()))
26322633
return error("failed to erase spent zerocoin in block");
26332634
}
26342635
}
2635-
} else if (tx.IsZerocoinMint()) {
2636+
}
2637+
if (tx.IsZerocoinMint()) {
26362638
//erase all zerocoinmints in this transaction
26372639
for (const CTxOut txout : tx.vout) {
26382640
if (txout.scriptPubKey.empty() || !txout.scriptPubKey.IsZerocoinMint())
@@ -2705,11 +2707,13 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
27052707
// move best block pointer to prevout block
27062708
view.SetBestBlock(pindex->pprev->GetBlockHash());
27072709

2708-
//if block is an accumulator checkpoint block, remove checkpoint and checksums from db
2709-
uint256 nCheckpoint = pindex->nAccumulatorCheckpoint;
2710-
if(nCheckpoint != pindex->pprev->nAccumulatorCheckpoint) {
2711-
if(!CAccumulators::getInstance().EraseAccumulatorValues(nCheckpoint, pindex->pprev->nAccumulatorCheckpoint))
2712-
return error("DisconnectBlock(): failed to erase checkpoint");
2710+
if (!fVerifyingBlocks) {
2711+
//if block is an accumulator checkpoint block, remove checkpoint and checksums from db
2712+
uint256 nCheckpoint = pindex->nAccumulatorCheckpoint;
2713+
if(nCheckpoint != pindex->pprev->nAccumulatorCheckpoint) {
2714+
if(!CAccumulators::getInstance().EraseAccumulatorValues(nCheckpoint, pindex->pprev->nAccumulatorCheckpoint))
2715+
return error("DisconnectBlock(): failed to erase checkpoint");
2716+
}
27132717
}
27142718

27152719
if (pfClean) {
@@ -2946,7 +2950,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
29462950
}
29472951

29482952
// zerocoin accumulator: if a new accumulator checkpoint was generated, check that it is the correct value
2949-
if (block.nVersion >= Params().Zerocoin_HeaderVersion() && pindex->nHeight % 10 == 0) {
2953+
if (!fVerifyingBlocks && block.nVersion >= Params().Zerocoin_HeaderVersion() && pindex->nHeight % 10 == 0) {
29502954
uint256 nCheckpointCalculated = 0;
29512955
if (!CAccumulators::getInstance().GetCheckpoint(pindex->nHeight, nCheckpointCalculated))
29522956
return state.DoS(100, error("ConnectBlock() : failed to calculate accumulator checkpoint"));
@@ -2955,7 +2959,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
29552959
LogPrintf("%s: block=%d calculated: %s\n block: %s\n", __func__, pindex->nHeight, nCheckpointCalculated.GetHex(), block.nAccumulatorCheckpoint.GetHex());
29562960
return state.DoS(100, error("ConnectBlock() : accumulator does not match calculated value"));
29572961
}
2958-
} else {
2962+
} else if (!fVerifyingBlocks) {
29592963
if (block.nAccumulatorCheckpoint != pindex->pprev->nAccumulatorCheckpoint) {
29602964
return state.DoS(100, error("ConnectBlock() : new accumulator checkpoint generated on a block that is not multiple of 10"));
29612965
}

src/main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ extern bool fCheckBlockIndex;
144144
extern unsigned int nCoinCacheSize;
145145
extern CFeeRate minRelayTxFee;
146146
extern bool fAlerts;
147+
extern bool fVerifyingBlocks;
147148

148149
extern bool fLargeWorkForkFound;
149150
extern bool fLargeWorkInvalidChainFound;

0 commit comments

Comments
 (0)