diff options
| author | Ross Nicoll <[email protected]> | 2018-01-08 19:39:10 +0000 |
|---|---|---|
| committer | Ross Nicoll <[email protected]> | 2018-09-19 21:09:16 +0100 |
| commit | 7b81f4de0a006a6c01b88c79b6ab34a921eb86b5 (patch) | |
| tree | 71f86cbdb71ef365ec893073d63f05ccfe1f8252 | |
| parent | Check only the base block version (#1411) (diff) | |
| download | discoin-7b81f4de0a006a6c01b88c79b6ab34a921eb86b5.tar.xz discoin-7b81f4de0a006a6c01b88c79b6ab34a921eb86b5.zip | |
Move COINBASE_MATURITY to the consensus parameters (#1426)
| -rw-r--r-- | src/auxpow.cpp | 4 | ||||
| -rw-r--r-- | src/chainparams.cpp | 15 | ||||
| -rw-r--r-- | src/chainparams.h | 16 | ||||
| -rw-r--r-- | src/consensus/consensus.h | 4 | ||||
| -rw-r--r-- | src/consensus/params.h | 3 | ||||
| -rw-r--r-- | src/qt/transactiondesc.cpp | 5 | ||||
| -rw-r--r-- | src/txmempool.cpp | 4 | ||||
| -rw-r--r-- | src/validation.cpp | 4 |
8 files changed, 28 insertions, 27 deletions
diff --git a/src/auxpow.cpp b/src/auxpow.cpp index 46fe6f650..56b919d3b 100644 --- a/src/auxpow.cpp +++ b/src/auxpow.cpp @@ -7,6 +7,7 @@ #include "auxpow.h" +#include "chainparams.h" #include "compat/endian.h" #include "consensus/consensus.h" #include "consensus/merkle.h" @@ -64,7 +65,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()); } diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 1781c1f5a..b7d69c071 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -88,6 +88,7 @@ public: consensus.nPowTargetTimespan = 4 * 60 * 60; // pre-digishield: 4 hours consensus.nPowTargetSpacing = 60; // 1 minute consensus.fDigishieldDifficultyCalculation = false; + consensus.nCoinbaseMaturity = 30; consensus.fPowAllowMinDifficultyBlocks = false; consensus.fPowAllowDigishieldMinDifficultyBlocks = false; consensus.fPowNoRetargeting = false; @@ -467,6 +468,20 @@ const CChainParams &Params() { return *pCurrentParams; } +const Consensus::Params *Consensus::Params::GetConsensus(uint32_t nTargetHeight) const { + if (nTargetHeight < this -> nHeightEffective && this -> pLeft != NULL) { + return this -> pLeft -> GetConsensus(nTargetHeight); + } else if (nTargetHeight > this -> nHeightEffective && this -> pRight != NULL) { + const Consensus::Params *pCandidate = this -> pRight -> GetConsensus(nTargetHeight); + if (pCandidate->nHeightEffective <= nTargetHeight) { + return pCandidate; + } + } + + // No better match below the target height + return this; +} + CChainParams& Params(const std::string& chain) { if (chain == CBaseChainParams::MAIN) diff --git a/src/chainparams.h b/src/chainparams.h index 14ceff4c7..d19cdcba5 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -57,21 +57,7 @@ public: }; const Consensus::Params& GetConsensus(uint32_t nTargetHeight) const { - return *GetConsensus(nTargetHeight, pConsensusRoot); - } - - Consensus::Params *GetConsensus(uint32_t nTargetHeight, Consensus::Params *pRoot) const { - if (nTargetHeight < pRoot -> nHeightEffective && pRoot -> pLeft != NULL) { - return GetConsensus(nTargetHeight, pRoot -> pLeft); - } else if (nTargetHeight > pRoot -> nHeightEffective && pRoot -> pRight != NULL) { - Consensus::Params *pCandidate = GetConsensus(nTargetHeight, pRoot -> pRight); - if (pCandidate->nHeightEffective <= nTargetHeight) { - return pCandidate; - } - } - - // No better match below the target height - return pRoot; + return *(pConsensusRoot -> GetConsensus(nTargetHeight)); } const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; } diff --git a/src/consensus/consensus.h b/src/consensus/consensus.h index 2876abefb..b7053e869 100644 --- a/src/consensus/consensus.h +++ b/src/consensus/consensus.h @@ -18,10 +18,6 @@ static const unsigned int MAX_BLOCK_BASE_SIZE = 1000000; static const int64_t MAX_BLOCK_SIGOPS_COST = 80000; /** 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; /** Flags for nSequence and nLockTime locks */ enum { diff --git a/src/consensus/params.h b/src/consensus/params.h index a3a61747d..98c744149 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -43,7 +43,6 @@ struct Params { int nMajorityEnforceBlockUpgrade; int nMajorityRejectBlockOutdated; int nMajorityWindow; - int nCoinbaseMaturity; /** Block height and hash at which BIP34 becomes active */ int BIP34Height; uint256 BIP34Hash; @@ -59,6 +58,7 @@ struct Params { uint32_t nRuleChangeActivationThreshold; uint32_t nMinerConfirmationWindow; BIP9Deployment vDeployments[MAX_VERSION_BITS_DEPLOYMENTS]; + uint32_t nCoinbaseMaturity; /** Proof of work parameters */ uint256 powLimit; bool fPowAllowMinDifficultyBlocks; @@ -84,6 +84,7 @@ struct Params { uint32_t nHeightEffective; // When these parameters come into use struct Params *pLeft; // Left hand branch struct Params *pRight; // Right hand branch + const Consensus::Params *GetConsensus(uint32_t nTargetHeight) const; }; } // namespace Consensus diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index 7e16cc9dd..d823f6273 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -10,6 +10,7 @@ #include "transactionrecord.h" #include "base58.h" +#include "chainparams.h" #include "consensus/consensus.h" #include "validation.h" #include "script/script.h" @@ -266,8 +267,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>"; } // diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 72547b582..de0a1489e 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -5,6 +5,7 @@ #include "txmempool.h" +#include "chainparams.h" #include "clientversion.h" #include "consensus/consensus.h" #include "consensus/validation.h" @@ -556,7 +557,8 @@ 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() && ((signed long)nMemPoolHeight) - coins->nHeight < COINBASE_MATURITY)) { + int nCoinbaseMaturity = Params().GetConsensus(coins->nHeight).nCoinbaseMaturity; + if (!coins || (coins->IsCoinBase() && ((signed long)nMemPoolHeight) - coins->nHeight < nCoinbaseMaturity)) { txToRemove.insert(it); break; } diff --git a/src/validation.cpp b/src/validation.cpp index 990323923..13f98cdaa 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1414,9 +1414,7 @@ bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoins // 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(false, REJECT_INVALID, "bad-txns-premature-spend-of-coinbase", |