aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-10-22 09:22:15 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2012-10-23 00:23:39 +0200
commit56424040a469f775f14be0c81d7d62ebcfd8a0d7 (patch)
tree788cb414e4d0b3170b2ce336941ed69b63877a83
parent2ef15697f84208e05764046dd86bcf067029a9b8 (diff)
downloadbitcoin-56424040a469f775f14be0c81d7d62ebcfd8a0d7.tar.xz
Bugfix: off-by-one error in coinbase maturity check
-rw-r--r--src/main.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/main.cpp b/src/main.cpp
index ad5a7b0f19..723b8d75ea 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1319,7 +1319,9 @@ bool CTransaction::CheckInputs(CCoinsViewCache &inputs, enum CheckSig_mode csmod
if (!HaveInputs(inputs))
return error("CheckInputs() : %s inputs unavailable", GetHash().ToString().substr(0,10).c_str());
- CBlockIndex *pindexBlock = inputs.GetBestBlock();
+ // While checking, GetBestBlock() refers to the parent block.
+ // This is also true for mempool checks.
+ int nSpendHeight = inputs.GetBestBlock()->nHeight + 1;
int64 nValueIn = 0;
int64 nFees = 0;
for (unsigned int i = 0; i < vin.size(); i++)
@@ -1329,8 +1331,8 @@ bool CTransaction::CheckInputs(CCoinsViewCache &inputs, enum CheckSig_mode csmod
// If prev is coinbase, check that it's matured
if (coins.IsCoinBase()) {
- if (pindexBlock->nHeight - coins.nHeight < COINBASE_MATURITY)
- return error("CheckInputs() : tried to spend coinbase at depth %d", pindexBlock->nHeight - coins.nHeight);
+ if (nSpendHeight - coins.nHeight < COINBASE_MATURITY)
+ return error("CheckInputs() : tried to spend coinbase at depth %d", nSpendHeight - coins.nHeight);
}
// Check for negative or overflow input values