Skip to content

Commit

Permalink
PPCoin: Fix moneysupply issues since 2a4202a
Browse files Browse the repository at this point in the history
        An issue where moneysupply resets to 0 in a racing shutdown
        An issue where moneysupply/mint could be missing with reorganization
  • Loading branch information
sunnyking committed Sep 21, 2012
1 parent 68c2577 commit b7d3104
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1415,9 +1415,11 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
mapQueuedChanges[tx.GetHash()] = CTxIndex(posThisTx, tx.vout.size());
}

// ppcoin: track money supply
// ppcoin: track money supply and mint amount info
pindex->nMint = nValueOut - nValueIn + nFees;
pindex->nMoneySupply = (pindex->pprev? pindex->pprev->nMoneySupply : 0) + nValueOut - nValueIn;
if (!txdb.WriteBlockIndex(CDiskBlockIndex(pindex)))
return error("Connect() : WriteBlockIndex for pindex failed");

// Write queued txindex changes
for (map<uint256, CTxIndex>::iterator mi = mapQueuedChanges.begin(); mi != mapQueuedChanges.end(); ++mi)
Expand All @@ -1438,7 +1440,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
CDiskBlockIndex blockindexPrev(pindex->pprev);
blockindexPrev.hashNext = pindex->GetBlockHash();
if (!txdb.WriteBlockIndex(blockindexPrev))
return error("ConnectBlock() : WriteBlockIndex failed");
return error("ConnectBlock() : WriteBlockIndex for blockindexPrev failed");
}

// Watch for transactions paying to me
Expand Down Expand Up @@ -1843,13 +1845,6 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos)
if (!SetBestChain(txdb, pindexNew))
return false;

// ppcoin: got mint/moneysupply info in block index, write to db
if (!txdb.TxnBegin())
return false;
txdb.WriteBlockIndex(CDiskBlockIndex(pindexNew));
if (!txdb.TxnCommit())
return false;

txdb.Close();

if (pindexNew == pindexBest)
Expand Down

0 comments on commit b7d3104

Please sign in to comment.