aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoss Nicoll <[email protected]>2014-04-20 15:09:05 +0100
committerRoss Nicoll <[email protected]>2014-04-20 15:09:05 +0100
commitde7c3d8bf8974c05e4c7c00cbff306e96c34d36e (patch)
tree3433bab12e01b7393b03b71ac3234712de3d61a2 /src
parentMerge pull request #478 from patricklodder/1.7-dev-fix_bloom_tests (diff)
parentDRY calculation for required maturity depth (diff)
downloaddiscoin-de7c3d8bf8974c05e4c7c00cbff306e96c34d36e.tar.xz
discoin-de7c3d8bf8974c05e4c7c00cbff306e96c34d36e.zip
Merge pull request #481 from patricklodder/1.7-dev-maturity-depth
fix maturity depth in CMerkleTx::GetBlocksToMaturity
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp31
-rw-r--r--src/main.h9
2 files changed, 36 insertions, 4 deletions
diff --git a/src/main.cpp b/src/main.cpp
index b5302a9bf..38f567661 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -932,11 +932,21 @@ int CMerkleTx::GetDepthInMainChain(CBlockIndex* &pindexRet) const
return nResult;
}
+int CMerkleTx::GetHeightInMainChain(CBlockIndex* &pindexRet) const
+{
+ return chainActive.Height() - GetDepthInMainChain(pindexRet) + 1;
+}
+
int CMerkleTx::GetBlocksToMaturity() const
{
if (!IsCoinBase())
return 0;
- return max(0, (COINBASE_MATURITY+1) - GetDepthInMainChain());
+
+ int nHeight = GetHeightInMainChain();
+ int nMaturity = GetRequiredMaturityDepth(nHeight);
+
+ return max(0, (nMaturity+20) - GetDepthInMainChain());
+
}
@@ -1530,6 +1540,19 @@ bool VerifySignature(const CCoins& txFrom, const CTransaction& txTo, unsigned in
return CScriptCheck(txFrom, txTo, nIn, flags, nHashType)();
}
+int GetRequiredMaturityDepth(int nHeight)
+{
+
+ if (nHeight >= COINBASE_MATURITY_SWITCH)
+ {
+ return COINBASE_MATURITY_NEW;
+ }
+ else
+ {
+ return COINBASE_MATURITY;
+ }
+}
+
bool CheckInputs(const CTransaction& tx, CValidationState &state, CCoinsViewCache &inputs, bool fScriptChecks, unsigned int flags, std::vector<CScriptCheck> *pvChecks)
{
if (!tx.IsCoinBase())
@@ -1555,9 +1578,9 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, CCoinsViewCach
// If prev is coinbase, check that it's matured
if (coins.IsCoinBase()) {
- int minDepth = COINBASE_MATURITY;
- if(coins.nHeight >= COINBASE_MATURITY_SWITCH)
- minDepth = COINBASE_MATURITY_NEW;
+
+ int minDepth = GetRequiredMaturityDepth(coins.nHeight);
+
if (nSpendHeight - coins.nHeight < minDepth)
return state.Invalid(
error("CheckInputs() : tried to spend coinbase at depth %d", nSpendHeight - coins.nHeight),
diff --git a/src/main.h b/src/main.h
index 155ad413d..542252051 100644
--- a/src/main.h
+++ b/src/main.h
@@ -307,6 +307,13 @@ inline bool AllowFree(double dPriority)
return dPriority > 100 * COIN * 1440 / 250; // Dogecoin: 1440 blocks found a day. Priority cutoff is 100 dogecoin day / 250 bytes.
}
+/** Get the maturity depth for coinbase transactions at a given height.
+ @param[in] nHeight The height at which to check maturity for
+ @return the depth at which the coinbase transaction matures
+ */
+// Dogecoin specific implementation, standardizes checks for the hard maturity change at block 145k
+int GetRequiredMaturityDepth(int nHeight);
+
// Check whether all inputs of this transaction are valid (no double spends, scripts & sigs, amounts)
// This does not modify the UTXO set. If pvChecks is not NULL, script checks are pushed onto it
// instead of being performed inline.
@@ -476,6 +483,8 @@ public:
// >=1 : this many blocks deep in the main chain
int GetDepthInMainChain(CBlockIndex* &pindexRet) const;
int GetDepthInMainChain() const { CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet); }
+ int GetHeightInMainChain(CBlockIndex* &pindexRet) const;
+ int GetHeightInMainChain() const { CBlockIndex *pindexRet; return GetHeightInMainChain(pindexRet); }
bool IsInMainChain() const { CBlockIndex *pindexRet; return GetDepthInMainChainINTERNAL(pindexRet) > 0; }
int GetBlocksToMaturity() const;
bool AcceptToMemoryPool(bool fLimitFree=true);