Skip to content

Commit

Permalink
[Cleanup] Remove reindexzerocoin init option
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Dec 2, 2020
1 parent c340155 commit e6ca43b
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 109 deletions.
17 changes: 0 additions & 17 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "checkpoints.h"
#include "compat/sanity.h"
#include "consensus/upgrades.h"
#include "consensus/zerocoin_verify.h"
#include "fs.h"
#include "httpserver.h"
#include "httprpc.h"
Expand Down Expand Up @@ -531,9 +530,6 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-masternodeaddr=<n>", strprintf(_("Set external address:port to get to this masternode (example: %s)"), "128.127.106.235:51472"));
strUsage += HelpMessageOpt("-budgetvotemode=<mode>", _("Change automatic finalized budget voting behavior. mode=auto: Vote for only exact finalized budget match to my generated budget. (string, default: auto)"));

strUsage += HelpMessageGroup(_("Zerocoin options:"));
strUsage += HelpMessageOpt("-reindexzerocoin=<n>", strprintf(_("Delete all zerocoin spends and mints that have been recorded to the blockchain database and reindex them (0-1, default: %u)"), 0));

strUsage += HelpMessageGroup(_("Node relay options:"));
strUsage += HelpMessageOpt("-datacarrier", strprintf(_("Relay and mine data carrier transactions (default: %u)"), DEFAULT_ACCEPT_DATACARRIER));
strUsage += HelpMessageOpt("-datacarriersize", strprintf(_("Maximum size of data in data carrier transactions we relay and mine (default: %u)"), MAX_OP_RETURN_RELAY));
Expand Down Expand Up @@ -1563,8 +1559,6 @@ bool AppInit2()
invalid_out::LoadOutpoints();
invalid_out::LoadSerials();

bool fReindexZerocoin = gArgs.GetBoolArg("-reindexzerocoin", false);

int chainHeight;
bool fZerocoinActive;
{
Expand All @@ -1582,17 +1576,6 @@ bool AppInit2()
}
}

// Drop all information from the zerocoinDB and repopulate
if (fReindexZerocoin && fZerocoinActive) {
LOCK(cs_main);
uiInterface.InitMessage(_("Reindexing zerocoin database..."));
std::string strError = ReindexZerocoinDB();
if (strError != "") {
strLoadError = strError;
break;
}
}

if (!fReindex) {
uiInterface.InitMessage(_("Verifying blocks..."));

Expand Down
91 changes: 0 additions & 91 deletions src/zpivchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,97 +247,6 @@ bool IsSerialInBlockchain(const uint256& hashSerial, int& nHeightTx, uint256& tx
return IsTransactionInChain(txidSpend, nHeightTx, tx);
}

std::string ReindexZerocoinDB()
{
AssertLockHeld(cs_main);

if (!zerocoinDB->WipeCoins("spends") || !zerocoinDB->WipeCoins("mints")) {
return _("Failed to wipe zerocoinDB");
}

const Consensus::Params& consensus = Params().GetConsensus();
const int zc_start_height = consensus.vUpgrades[Consensus::UPGRADE_ZC].nActivationHeight;
CBlockIndex* pindex = chainActive[zc_start_height];
std::vector<std::pair<libzerocoin::CoinSpend, uint256> > vSpendInfo;
std::vector<std::pair<libzerocoin::PublicCoin, uint256> > vMintInfo;
while (pindex) {
uiInterface.ShowProgress(_("Reindexing zerocoin database..."), std::max(1, std::min(99, (int)((double)(pindex->nHeight - zc_start_height) / (double)(chainActive.Height() - zc_start_height) * 100))));

if (pindex->nHeight % 1000 == 0)
LogPrintf("Reindexing zerocoin : block %d...\n", pindex->nHeight);

CBlock block;
if (!ReadBlockFromDisk(block, pindex)) {
return _("Reindexing zerocoin failed");
}

for (const auto& txIn : block.vtx) {
const CTransaction& tx = *txIn;
for (unsigned int i = 0; i < tx.vin.size(); i++) {
if (tx.IsCoinBase())
break;

if (tx.ContainsZerocoins()) {
uint256 txid = tx.GetHash();
//Record Serials
if (tx.HasZerocoinSpendInputs()) {
for (auto& in : tx.vin) {
bool isPublicSpend = in.IsZerocoinPublicSpend();
if (!in.IsZerocoinSpend() && !isPublicSpend)
continue;
if (isPublicSpend) {
libzerocoin::ZerocoinParams* params = consensus.Zerocoin_Params(false);
PublicCoinSpend publicSpend(params);
CValidationState state;
if (!ZPIVModule::ParseZerocoinPublicSpend(in, tx, state, publicSpend)){
return _("Failed to parse public spend");
}
vSpendInfo.emplace_back(publicSpend, txid);
} else {
libzerocoin::CoinSpend spend = TxInToZerocoinSpend(in);
vSpendInfo.emplace_back(spend, txid);
}
}
}

//Record mints
if (tx.HasZerocoinMintOutputs()) {
for (auto& out : tx.vout) {
if (!out.IsZerocoinMint())
continue;

CValidationState state;
const bool v1params = !consensus.NetworkUpgradeActive(pindex->nHeight, Consensus::UPGRADE_ZC_V2);
libzerocoin::PublicCoin coin(consensus.Zerocoin_Params(v1params));
TxOutToPublicCoin(out, coin, state);
vMintInfo.emplace_back(coin, txid);
}
}
}
}
}

// Flush the zerocoinDB to disk every 100 blocks
if (pindex->nHeight % 100 == 0) {
if ((!vSpendInfo.empty() && !zerocoinDB->WriteCoinSpendBatch(vSpendInfo)) || (!vMintInfo.empty() && !zerocoinDB->WriteCoinMintBatch(vMintInfo)))
return _("Error writing zerocoinDB to disk");
vSpendInfo.clear();
vMintInfo.clear();
}

pindex = chainActive.Next(pindex);
}
uiInterface.ShowProgress("", 100);

// Final flush to disk in case any remaining information exists
if ((!vSpendInfo.empty() && !zerocoinDB->WriteCoinSpendBatch(vSpendInfo)) || (!vMintInfo.empty() && !zerocoinDB->WriteCoinMintBatch(vMintInfo)))
return _("Error writing zerocoinDB to disk");

uiInterface.ShowProgress("", 100);

return "";
}

bool RemoveSerialFromDB(const CBigNum& bnSerial)
{
return zerocoinDB->EraseCoinSpend(bnSerial);
Expand Down
1 change: 0 additions & 1 deletion src/zpivchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ bool IsSerialInBlockchain(const CBigNum& bnSerial, int& nHeightTx);
bool IsSerialInBlockchain(const uint256& hashSerial, int& nHeightTx, uint256& txidSpend);
bool IsSerialInBlockchain(const uint256& hashSerial, int& nHeightTx, uint256& txidSpend, CTransaction& tx);
bool RemoveSerialFromDB(const CBigNum& bnSerial);
std::string ReindexZerocoinDB();
libzerocoin::CoinSpend TxInToZerocoinSpend(const CTxIn& txin);
bool TxOutToPublicCoin(const CTxOut& txout, libzerocoin::PublicCoin& pubCoin, CValidationState& state);
std::list<libzerocoin::CoinDenomination> ZerocoinSpendListFromBlock(const CBlock& block, bool fFilterInvalid);
Expand Down

0 comments on commit e6ca43b

Please sign in to comment.