Skip to content

Commit

Permalink
Move COINBASE_MATURITY to the consensus parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
langerhans committed Jul 31, 2015
1 parent 9b58d31 commit 38a8300
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/auxpow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "auxpow.h"

#include "chainparams.h"
#include "consensus/validation.h"
#include "main.h"
#include "script/script.h"
Expand Down Expand Up @@ -89,7 +90,8 @@ int CMerkleTx::GetBlocksToMaturity() const
{
if (!IsCoinBase())
return 0;
return std::max(0, (COINBASE_MATURITY + 1) - GetDepthInMainChain());
int nCoinbaseMaturity = Params().GetConsensus(chainActive.Height()).nCoinbaseMaturity;
return std::max(0, (nCoinbaseMaturity + 1) - GetDepthInMainChain());
}


Expand Down
3 changes: 3 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ class CMainParams : public CChainParams {
consensus.fAllowLegacyBlocks = true;
consensus.nHeightEffective = 0;
consensus.fDigishieldDifficultyCalculation = false;
consensus.nCoinbaseMaturity = 30;

// Blocks 145000 - 371336 are Digishield without AuxPoW
digishieldConsensus = consensus;
digishieldConsensus.nHeightEffective = 145000;
digishieldConsensus.fSimplifiedRewards = true;
digishieldConsensus.fDigishieldDifficultyCalculation = true;
digishieldConsensus.nPowTargetTimespan = 60; // post-digishield: 1 minute
digishieldConsensus.nCoinbaseMaturity = 240;

// Blocks 371337+ are AuxPoW
auxpowConsensus = digishieldConsensus;
Expand Down Expand Up @@ -203,6 +205,7 @@ class CTestNetParams : public CMainParams {
digishieldConsensus.fDigishieldDifficultyCalculation = true;
digishieldConsensus.fSimplifiedRewards = true;
digishieldConsensus.fPowAllowMinDifficultyBlocks = false;
digishieldConsensus.nCoinbaseMaturity = 240;

// Blocks 157500 - 158099 are Digishield with minimum difficulty on all blocks
minDifficultyConsensus = digishieldConsensus;
Expand Down
6 changes: 0 additions & 6 deletions src/consensus/consensus.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
static const unsigned int MAX_BLOCK_SIZE = 1000000;
/** The maximum allowed number of signature check operations in a block (network rule) */
static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
static const int COINBASE_MATURITY = 60*4; // 4 hours of blocks
/** Coinbase maturity before block 145000 **/
static const int COINBASE_MATURITY_OLD = 30;
/** Block at which COINBASE_MATURITY_OLD was deprecated **/
static const int COINBASE_MATURITY_SWITCH = 145000;
/** Threshold for nLockTime: below this value it is interpreted as block number, otherwise as UNIX timestamp. */
static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC

Expand Down
1 change: 1 addition & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct Params {
int nMajorityEnforceBlockUpgrade;
int nMajorityRejectBlockOutdated;
int nMajorityWindow;
int nCoinbaseMaturity;
/** Proof of work parameters */
uint256 powLimit;
bool fPowAllowMinDifficultyBlocks;
Expand Down
4 changes: 1 addition & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1446,9 +1446,7 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
// If prev is coinbase, check that it's matured
if (coins->IsCoinBase()) {
// Dogecoin: Switch maturity at depth 145,000
int nCoinbaseMaturity = coins->nHeight < COINBASE_MATURITY_SWITCH
? COINBASE_MATURITY_OLD
: COINBASE_MATURITY;
int nCoinbaseMaturity = Params().GetConsensus(coins->nHeight).nCoinbaseMaturity;
if (nSpendHeight - coins->nHeight < nCoinbaseMaturity)
return state.Invalid(
error("CheckInputs(): tried to spend coinbase at depth %d", nSpendHeight - coins->nHeight),
Expand Down
5 changes: 3 additions & 2 deletions src/qt/transactiondesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "transactionrecord.h"

#include "base58.h"
#include "chainparams.h"
#include "consensus/consensus.h"
#include "main.h"
#include "script/script.h"
Expand Down Expand Up @@ -264,8 +265,8 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco

if (wtx.IsCoinBase())
{
quint32 numBlocksToMaturity = COINBASE_MATURITY + 1;
strHTML += "<br>" + tr("Generated coins must mature %1 blocks before they can be spent. When you generated this block, it was broadcast to the network to be added to the block chain. If it fails to get into the chain, its state will change to \"not accepted\" and it won't be spendable. This may occasionally happen if another node generates a block within a few seconds of yours.").arg(QString::number(numBlocksToMaturity)) + "<br>";
quint32 nCoinbaseMaturity = Params().GetConsensus(chainActive.Height()).nCoinbaseMaturity + 1;
strHTML += "<br>" + tr("Generated coins must mature %1 blocks before they can be spent. When you generated this block, it was broadcast to the network to be added to the block chain. If it fails to get into the chain, its state will change to \"not accepted\" and it won't be spendable. This may occasionally happen if another node generates a block within a few seconds of yours.").arg(QString::number(nCoinbaseMaturity)) + "<br>";
}

//
Expand Down
4 changes: 3 additions & 1 deletion src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "txmempool.h"

#include "chainparams.h"
#include "clientversion.h"
#include "consensus/consensus.h"
#include "consensus/validation.h"
Expand Down Expand Up @@ -166,7 +167,8 @@ void CTxMemPool::removeCoinbaseSpends(const CCoinsViewCache *pcoins, unsigned in
continue;
const CCoins *coins = pcoins->AccessCoins(txin.prevout.hash);
if (fSanityCheck) assert(coins);
if (!coins || (coins->IsCoinBase() && nMemPoolHeight - coins->nHeight < COINBASE_MATURITY)) {
int nCoinbaseMaturity = Params().GetConsensus(coins->nHeight).nCoinbaseMaturity;
if (!coins || (coins->IsCoinBase() && nMemPoolHeight - coins->nHeight < nCoinbaseMaturity)) {
transactionsToRemove.push_back(tx);
break;
}
Expand Down

0 comments on commit 38a8300

Please sign in to comment.