diff options
author | Jorge Timón <jtimon@jtimon.cc> | 2015-04-01 16:03:11 +0200 |
---|---|---|
committer | Jorge Timón <jtimon@jtimon.cc> | 2015-05-15 16:12:30 +0200 |
commit | 935bd0a447834fa48c218ddae2a5d835a67979ef (patch) | |
tree | 1d45c3edbc3208a22894a2e6bef1743550a5b81c /src/main.cpp | |
parent | ac75bafafdc394f60f819ede18181682eb5aa662 (diff) |
Chainparams: Refactor: Decouple main::GetBlockValue() from Params() [renamed GetBlockSubsidy]
Remove redundant getter CChainParams::SubsidyHalvingInterval()
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/main.cpp b/src/main.cpp index 5fd9c62486..462b74b937 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1188,19 +1188,17 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex) return true; } -CAmount GetBlockValue(int nHeight, const CAmount& nFees) +CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) { - CAmount nSubsidy = 50 * COIN; - int halvings = nHeight / Params().SubsidyHalvingInterval(); - + int halvings = nHeight / consensusParams.nSubsidyHalvingInterval; // Force block reward to zero when right shift is undefined. if (halvings >= 64) - return nFees; + return 0; + CAmount nSubsidy = 50 * COIN; // Subsidy is cut in half every 210,000 blocks which will occur approximately every 4 years. nSubsidy >>= halvings; - - return nSubsidy + nFees; + return nSubsidy; } bool IsInitialBlockDownload() @@ -1809,10 +1807,11 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin int64_t nTime1 = GetTimeMicros(); nTimeConnect += nTime1 - nTimeStart; LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime1 - nTimeStart) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime1 - nTimeStart) / (nInputs-1), nTimeConnect * 0.000001); - if (block.vtx[0].GetValueOut() > GetBlockValue(pindex->nHeight, nFees)) + CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, chainparams.GetConsensus()); + if (block.vtx[0].GetValueOut() > blockReward) return state.DoS(100, error("ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)", - block.vtx[0].GetValueOut(), GetBlockValue(pindex->nHeight, nFees)), + block.vtx[0].GetValueOut(), blockReward), REJECT_INVALID, "bad-cb-amount"); if (!control.Wait()) |