Skip to content

Commit df932b8

Browse files
committed
[Core][Cleanup] CBlockIndex: remove vMintDenominationsInBlock
- remove RecalculateZPIVSpent and RecalculateZPIVMinted main functions - remove MintedDenomination CBlockIndex method
1 parent 2b48844 commit df932b8

File tree

7 files changed

+14
-121
lines changed

7 files changed

+14
-121
lines changed

src/chain.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ void CBlockIndex::SetNull()
103103
// Start supply of each denomination with 0s
104104
for (auto& denom : libzerocoin::zerocoinDenomList)
105105
mapZerocoinSupply.insert(std::make_pair(denom, 0));
106-
vMintDenominationsInBlock.clear();
107106
}
108107

109108
std::string CBlockIndex::ToString() const
@@ -287,7 +286,3 @@ int64_t CBlockIndex::GetZcMintsAmount(libzerocoin::CoinDenomination denom) const
287286
return libzerocoin::ZerocoinDenominationToAmount(denom) * GetZcMints(denom);
288287
}
289288

290-
bool CBlockIndex::MintedDenomination(libzerocoin::CoinDenomination denom) const
291-
{
292-
return std::find(vMintDenominationsInBlock.begin(), vMintDenominationsInBlock.end(), denom) != vMintDenominationsInBlock.end();
293-
}

src/chain.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ class CBlockIndex
234234

235235
//! zerocoin specific fields
236236
std::map<libzerocoin::CoinDenomination, int64_t> mapZerocoinSupply;
237-
std::vector<libzerocoin::CoinDenomination> vMintDenominationsInBlock;
238237

239238
CBlockIndex() { SetNull(); }
240239
CBlockIndex(const CBlock& block);
@@ -287,7 +286,6 @@ class CBlockIndex
287286
int64_t GetZerocoinSupply() const;
288287
int64_t GetZcMints(libzerocoin::CoinDenomination denom) const;
289288
int64_t GetZcMintsAmount(libzerocoin::CoinDenomination denom) const;
290-
bool MintedDenomination(libzerocoin::CoinDenomination denom) const;
291289
};
292290

293291
/** Used to marshal pointers into hashes for db storage. */
@@ -333,15 +331,10 @@ class CDiskBlockIndex : public CBlockIndex
333331
if (nStatus & BLOCK_HAVE_UNDO)
334332
READWRITE(VARINT(nUndoPos));
335333

336-
if (fOldSer) {
337-
int64_t nMint = 0;
338-
READWRITE(nMint);
339-
}
340-
READWRITE(nMoneySupply);
341-
READWRITE(nFlags);
342-
343334
if (fNewSer) {
344335
// Serialization with client version > 4009900
336+
READWRITE(nMoneySupply);
337+
READWRITE(nFlags);
345338
READWRITE(vStakeModifier);
346339
// block header
347340
READWRITE(this->nVersion);
@@ -353,7 +346,6 @@ class CDiskBlockIndex : public CBlockIndex
353346
if(this->nVersion > 3) {
354347
READWRITE(mapZerocoinSupply);
355348
if(this->nVersion < 7) READWRITE(nAccumulatorCheckpoint);
356-
READWRITE(vMintDenominationsInBlock);
357349
}
358350

359351
} else {
@@ -381,6 +373,7 @@ class CDiskBlockIndex : public CBlockIndex
381373
READWRITE(nBits);
382374
READWRITE(nNonce);
383375
if(this->nVersion > 3) {
376+
std::vector<libzerocoin::CoinDenomination> vMintDenominationsInBlock;
384377
READWRITE(nAccumulatorCheckpoint);
385378
READWRITE(mapZerocoinSupply);
386379
READWRITE(vMintDenominationsInBlock);

src/init.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,10 +1543,6 @@ bool AppInit2()
15431543

15441544
// Recalculate money supply for blocks that are impacted by accounting issue after zerocoin activation
15451545
if (GetBoolArg("-reindexmoneysupply", false) || reindexZerocoin) {
1546-
if (chainHeight > Params().Zerocoin_StartHeight()) {
1547-
RecalculateZPIVMinted();
1548-
RecalculateZPIVSpent();
1549-
}
15501546
// Recalculate from the zerocoin activation or from scratch.
15511547
RecalculatePIVSupply(reindexZerocoin ? Params().Zerocoin_StartHeight() : 1);
15521548
}

src/main.cpp

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,87 +2673,6 @@ void AddWrappedSerialsInflation()
26732673
uiInterface.ShowProgress("", 100);
26742674
}
26752675

2676-
void RecalculateZPIVMinted()
2677-
{
2678-
CBlockIndex *pindex = chainActive[Params().Zerocoin_StartHeight()];
2679-
const int chainHeight = chainActive.Height();
2680-
uiInterface.ShowProgress(_("Recalculating minted ZPIV..."), 0);
2681-
while (true) {
2682-
// Log Message and feedback message every 1000 blocks
2683-
if (pindex->nHeight % 1000 == 0) {
2684-
LogPrintf("%s : block %d...\n", __func__, pindex->nHeight);
2685-
int percent = std::max(1, std::min(99, (int)((double)(pindex->nHeight - Params().Zerocoin_StartHeight()) * 100 / (chainHeight - Params().Zerocoin_StartHeight()))));
2686-
uiInterface.ShowProgress(_("Recalculating minted ZPIV..."), percent);
2687-
}
2688-
2689-
//overwrite possibly wrong vMintsInBlock data
2690-
CBlock block;
2691-
assert(ReadBlockFromDisk(block, pindex));
2692-
2693-
std::list<CZerocoinMint> listMints;
2694-
BlockToZerocoinMintList(block, listMints, true);
2695-
2696-
std::vector<libzerocoin::CoinDenomination> vDenomsBefore = pindex->vMintDenominationsInBlock;
2697-
pindex->vMintDenominationsInBlock.clear();
2698-
for (auto mint : listMints)
2699-
pindex->vMintDenominationsInBlock.emplace_back(mint.GetDenomination());
2700-
2701-
if (pindex->nHeight < chainHeight)
2702-
pindex = chainActive.Next(pindex);
2703-
else
2704-
break;
2705-
}
2706-
uiInterface.ShowProgress("", 100);
2707-
}
2708-
2709-
void RecalculateZPIVSpent()
2710-
{
2711-
CBlockIndex* pindex = chainActive[Params().Zerocoin_StartHeight()];
2712-
const int chainHeight = chainActive.Height();
2713-
uiInterface.ShowProgress(_("Recalculating spent ZPIV..."), 0);
2714-
while (true) {
2715-
if (pindex->nHeight % 1000 == 0) {
2716-
LogPrintf("%s : block %d...\n", __func__, pindex->nHeight);
2717-
int percent = std::max(1, std::min(99, (int)((double)(pindex->nHeight - Params().Zerocoin_StartHeight()) * 100 / (chainHeight - Params().Zerocoin_StartHeight()))));
2718-
uiInterface.ShowProgress(_("Recalculating spent ZPIV..."), percent);
2719-
}
2720-
2721-
//Rewrite zPIV supply
2722-
CBlock block;
2723-
assert(ReadBlockFromDisk(block, pindex));
2724-
2725-
std::list<libzerocoin::CoinDenomination> listDenomsSpent = ZerocoinSpendListFromBlock(block, true);
2726-
2727-
//Reset the supply to previous block
2728-
pindex->mapZerocoinSupply = pindex->pprev->mapZerocoinSupply;
2729-
2730-
//Add mints to zPIV supply
2731-
for (auto denom : libzerocoin::zerocoinDenomList) {
2732-
long nDenomAdded = count(pindex->vMintDenominationsInBlock.begin(), pindex->vMintDenominationsInBlock.end(), denom);
2733-
pindex->mapZerocoinSupply.at(denom) += nDenomAdded;
2734-
}
2735-
2736-
//Remove spends from zPIV supply
2737-
for (auto denom : listDenomsSpent)
2738-
pindex->mapZerocoinSupply.at(denom)--;
2739-
2740-
// Add inflation from Wrapped Serials if block is Zerocoin_Block_EndFakeSerial()
2741-
if (pindex->nHeight == Params().Zerocoin_Block_EndFakeSerial() + 1)
2742-
for (auto denom : libzerocoin::zerocoinDenomList) {
2743-
pindex->mapZerocoinSupply.at(denom) += GetWrapppedSerialInflation(denom);
2744-
}
2745-
2746-
//Rewrite money supply
2747-
assert(pblocktree->WriteBlockIndex(CDiskBlockIndex(pindex)));
2748-
2749-
if (pindex->nHeight < chainHeight)
2750-
pindex = chainActive.Next(pindex);
2751-
else
2752-
break;
2753-
}
2754-
uiInterface.ShowProgress("", 100);
2755-
}
2756-
27572676
bool RecalculatePIVSupply(int nHeightStart)
27582677
{
27592678
const int chainHeight = chainActive.Height();
@@ -2846,12 +2765,10 @@ bool UpdateZPIVSupply(const CBlock& block, CBlockIndex* pindex, bool fJustCheck)
28462765

28472766
// Track zerocoin money supply
28482767
CAmount nAmountZerocoinSpent = 0;
2849-
pindex->vMintDenominationsInBlock.clear();
28502768
if (pindex->pprev) {
28512769
std::set<uint256> setAddedToWallet;
28522770
for (auto& m : listMints) {
28532771
libzerocoin::CoinDenomination denom = m.GetDenomination();
2854-
pindex->vMintDenominationsInBlock.push_back(m.GetDenomination());
28552772
pindex->mapZerocoinSupply.at(denom)++;
28562773

28572774
//Remove any of our own mints from the mintpool
@@ -3095,8 +3012,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
30953012

30963013
//A one-time event where money supply counts were off and recalculated on a certain block.
30973014
if (pindex->nHeight == Params().Zerocoin_Block_RecalculateAccumulators() + 1) {
3098-
RecalculateZPIVMinted();
3099-
RecalculateZPIVSpent();
31003015
RecalculatePIVSupply(Params().Zerocoin_StartHeight());
31013016
}
31023017

src/main.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,6 @@ bool IsTransactionInChain(const uint256& txId, int& nHeightTx);
290290
bool IsBlockHashInChain(const uint256& hashBlock);
291291
bool ValidOutPoint(const COutPoint& out, int nHeight);
292292
void AddWrappedSerialsInflation();
293-
void RecalculateZPIVSpent();
294-
void RecalculateZPIVMinted();
295293
bool RecalculatePIVSupply(int nHeightStart);
296294

297295
// Fake Serial attack Range

src/txdb.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
216216
pcursor->Seek(ssKeySet.str());
217217

218218
// Load mapBlockIndex
219-
uint256 nPreviousCheckpoint;
220219
while (pcursor->Valid()) {
221220
boost::this_thread::interruption_point();
222221
try {
@@ -249,7 +248,6 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
249248
//zerocoin
250249
pindexNew->nAccumulatorCheckpoint = diskindex.nAccumulatorCheckpoint;
251250
pindexNew->mapZerocoinSupply = diskindex.mapZerocoinSupply;
252-
pindexNew->vMintDenominationsInBlock = diskindex.vMintDenominationsInBlock;
253251

254252
//Proof Of Stake
255253
pindexNew->nMoneySupply = diskindex.nMoneySupply;

src/wallet/rpcwallet.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4313,19 +4313,17 @@ UniValue spendrawzerocoin(const UniValue& params, bool fHelp)
43134313
CBlockIndex* pindex = chainActive.Tip();
43144314
while (!found && pindex && pindex->nHeight >= Params().Zerocoin_StartHeight()) {
43154315
LogPrintf("%s : Checking block %d...\n", __func__, pindex->nHeight);
4316-
if (pindex->MintedDenomination(denom)) {
4317-
CBlock block;
4318-
if (!ReadBlockFromDisk(block, pindex))
4319-
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read block from disk");
4320-
std::list<CZerocoinMint> listMints;
4321-
BlockToZerocoinMintList(block, listMints, true);
4322-
for (const CZerocoinMint& m : listMints) {
4323-
if (m.GetValue() == mintValue && m.GetDenomination() == denom) {
4324-
// mint found. update txid
4325-
mint.SetTxHash(m.GetTxHash());
4326-
found = true;
4327-
break;
4328-
}
4316+
CBlock block;
4317+
if (!ReadBlockFromDisk(block, pindex))
4318+
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read block from disk");
4319+
std::list<CZerocoinMint> listMints;
4320+
BlockToZerocoinMintList(block, listMints, true);
4321+
for (const CZerocoinMint& m : listMints) {
4322+
if (m.GetValue() == mintValue && m.GetDenomination() == denom) {
4323+
// mint found. update txid
4324+
mint.SetTxHash(m.GetTxHash());
4325+
found = true;
4326+
break;
43294327
}
43304328
}
43314329
pindex = pindex->pprev;

0 commit comments

Comments
 (0)