Skip to content

Commit

Permalink
Merge branch 'master' into testnet-2
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlz committed Aug 25, 2017
2 parents 360e383 + 5c84cce commit 797c365
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class CBlockIndex
// proof-of-stake specific fields
COutPoint prevoutStake;
uint256 hashProof; // qtum
uint64_t nMoneySupply;

//! (memory only) Sequential id assigned to distinguish order in which blocks are received.
int32_t nSequenceId;
Expand Down Expand Up @@ -244,6 +245,7 @@ class CBlockIndex
nStakeModifier = uint256();
hashProof = uint256();
prevoutStake.SetNull();
nMoneySupply = 0;
}

CBlockIndex()
Expand All @@ -260,6 +262,7 @@ class CBlockIndex
nTime = block.nTime;
nBits = block.nBits;
nNonce = block.nNonce;
nMoneySupply = 0;
hashStateRoot = block.hashStateRoot; // qtum
hashUTXORoot = block.hashUTXORoot; // qtum
nStakeModifier = uint256();
Expand Down Expand Up @@ -418,6 +421,7 @@ class CDiskBlockIndex : public CBlockIndex
READWRITE(VARINT(nDataPos));
if (nStatus & BLOCK_HAVE_UNDO)
READWRITE(VARINT(nUndoPos));
READWRITE(VARINT(nMoneySupply));

// block header
READWRITE(this->nVersion);
Expand Down
1 change: 1 addition & 0 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ UniValue getinfo(const JSONRPCRequest& request)
diff.push_back(Pair("proof-of-stake", GetDifficulty(GetLastBlockIndex(pindexBestHeader, true))));
obj.push_back(Pair("difficulty", diff));
obj.push_back(Pair("testnet", Params().NetworkIDString() == CBaseChainParams::TESTNET));
obj.push_back(Pair("moneysupply", pindexBestHeader->nMoneySupply / COIN));
#ifdef ENABLE_WALLET
if (pwalletMain) {
obj.push_back(Pair("keypoololdest", pwalletMain->GetOldestKeyPoolTime()));
Expand Down
1 change: 1 addition & 0 deletions src/txdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts(boost::function<CBlockIndex*(const uint256
pindexNew->nTime = diskindex.nTime;
pindexNew->nBits = diskindex.nBits;
pindexNew->nNonce = diskindex.nNonce;
pindexNew->nMoneySupply = diskindex.nMoneySupply;
pindexNew->nStatus = diskindex.nStatus;
pindexNew->nTx = diskindex.nTx;
pindexNew->hashStateRoot = diskindex.hashStateRoot; // qtum
Expand Down
19 changes: 19 additions & 0 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2579,6 +2579,10 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
txdata.reserve(block.vtx.size()); // Required so that pointers to individual PrecomputedTransactionData don't get invalidated
uint64_t blockGasUsed = 0;
CAmount gasRefunds=0;

uint64_t nValueOut=0;
uint64_t nValueIn=0;

for (unsigned int i = 0; i < block.vtx.size(); i++)
{
const CTransaction &tx = *(block.vtx[i]);
Expand Down Expand Up @@ -2645,6 +2649,15 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
}
}

if(tx.IsCoinBase()){
nValueOut += tx.GetValueOut();
}else{
int64_t nTxValueIn = view.GetValueIn(tx);
int64_t nTxValueOut = tx.GetValueOut();
nValueIn += nTxValueIn;
nValueOut += nTxValueOut;
}

///////////////////////////////////////////////////////////////////////////////////////// qtum
if(!tx.HasOpSpend()){
checkBlock.vtx.push_back(block.vtx[i]);
Expand Down Expand Up @@ -2833,6 +2846,12 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
}
//////////////////////////////////////////////////////////////////

pindex->nMoneySupply = (pindex->pprev? pindex->pprev->nMoneySupply : 0) + nValueOut - nValueIn;
//only start checking this assert after block 5000 and only on testnet and mainnet, not regtest
if(pindex->nHeight > 5000 && !Params().GetConsensus().fPoSNoRetargeting) {
//sanity check to shut down the network in case an exploit happens that allows new coins to be minted
assert(pindex->nMoneySupply <= (uint64_t)(100000000 + ((pindex->nHeight - 5000) * 4)) * COIN);
}
// Write undo information to disk
if (pindex->GetUndoPos().IsNull() || !pindex->IsValid(BLOCK_VALID_SCRIPTS))
{
Expand Down

0 comments on commit 797c365

Please sign in to comment.