From f536a8126eaae7ac9e16e4166f6518242355ca70 Mon Sep 17 00:00:00 2001 From: lateminer Date: Sun, 17 Dec 2017 15:21:59 +0300 Subject: [PATCH] Replace COINBASE_MATURITY... ...with nCoinbaseMaturity --- src/chainparams.cpp | 1 + src/consensus/params.h | 1 + src/main.cpp | 4 ++-- src/qt/transactiondesc.cpp | 2 +- src/test/test_bitcoin.cpp | 2 +- src/txmempool.cpp | 2 +- src/wallet/wallet.cpp | 2 +- 7 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index e69b8c7a5..0cc6cc8e5 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -102,6 +102,7 @@ public: consensus.nProtocolV3Time = 1444028400; consensus.nLastPOWBlock = 10000; consensus.nStakeTimestampMask = 0xf; // 15 + consensus.nCoinbaseMaturity = 500; consensus.nStakeMinConfirmations = 500; consensus.nStakeMinAge = 8 * 60 * 60; // 8 hours diff --git a/src/consensus/params.h b/src/consensus/params.h index f2d916869..4921c7a5f 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -70,6 +70,7 @@ struct Params { unsigned int GetTargetSpacing(int nHeight) { return IsProtocolV2(nHeight) ? 64 : 60; } int nLastPOWBlock; int nStakeTimestampMask; + int nCoinbaseMaturity; int nStakeMinConfirmations; unsigned int nStakeMinAge; }; diff --git a/src/main.cpp b/src/main.cpp index 4bbc94f00..66a12d5ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1915,7 +1915,7 @@ bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoins // If prev is coinbase or coinstake, check that it's matured if (coins->IsCoinBase() || coins->IsCoinStake()) { - if (nSpendHeight - coins->nHeight < COINBASE_MATURITY) + if (nSpendHeight - coins->nHeight < Params().nCoinbaseMaturity) return state.Invalid( error("CheckInputs(): tried to spend %s at depth %d", coins->IsCoinBase() ? "coinbase" : "coinstake", nSpendHeight - coins->nHeight), REJECT_INVALID, "bad-txns-premature-spend-of-coinbase"); @@ -2476,7 +2476,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin REJECT_INVALID, "bad-cs-kernel"); // Check proof-of-stake min confirmations - if (pindex->nHeight - coins->nHeight < Params().GetConsensus().nStakeMinConfirmations) + if (pindex->nHeight - coins->nHeight < chainparams.GetConsensus().nStakeMinConfirmations) return state.DoS(100, error("%s: tried to stake at depth %d", __func__, pindex->nHeight - coins->nHeight), REJECT_INVALID, "bad-cs-premature"); diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index 56ac2bffe..8d82e8305 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -262,7 +262,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco if (wtx.IsCoinBase()) { - quint32 numBlocksToMaturity = COINBASE_MATURITY + 1; + quint32 numBlocksToMaturity = Params().GetConsensus().nCoinbaseMaturity + 1; strHTML += "
" + 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)) + "
"; } diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp index eb7400cf5..ccce6e071 100644 --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -101,7 +101,7 @@ TestChain100Setup::TestChain100Setup() : TestingSetup(CBaseChainParams::REGTEST) // Generate a 100-block chain: coinbaseKey.MakeNewKey(true); CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG; - for (int i = 0; i < COINBASE_MATURITY; i++) + for (int i = 0; i < Params().GetConsensus().nCoinbaseMaturity; i++) { std::vector noTxns; CBlock b = CreateAndProcessBlock(noTxns, scriptPubKey); diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 55356189a..97a335a99 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -665,7 +665,7 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem continue; const CCoins *coins = pcoins->AccessCoins(txin.prevout.hash); if (nCheckFrequency != 0) assert(coins); - if (!coins || (coins->IsCoinBase() || coins->IsCoinStake() && ((signed long)nMemPoolHeight) - coins->nHeight < COINBASE_MATURITY)) { + if (!coins || (coins->IsCoinBase() || coins->IsCoinStake() && ((signed long)nMemPoolHeight) - coins->nHeight < Params().GetConsensus().nCoinbaseMaturity)) { transactionsToRemove.push_back(tx); break; } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 1209c3fec..aef70773f 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3520,7 +3520,7 @@ int CMerkleTx::GetBlocksToMaturity() const { if (!(IsCoinBase() || IsCoinStake())) return 0; - return max(0, (COINBASE_MATURITY+1) - GetDepthInMainChain()); + return max(0, (Params().GetConsensus().nCoinbaseMaturity+1) - GetDepthInMainChain()); }