aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorPeter Todd <pete@petertodd.org>2015-05-25 00:48:33 -0400
committerWladimir J. van der Laan <laanwj@gmail.com>2015-06-01 12:35:49 +0200
commit75a4d512cfc9a451fa627a3487ffed102cc67cab (patch)
tree92c36e64aab3c9fcc553388016536a09afb38ae6 /src/main.cpp
parent2be094eeba976366f19fc0ca839519335a729919 (diff)
downloadbitcoin-75a4d512cfc9a451fa627a3487ffed102cc67cab.tar.xz
Fix off-by-one error w/ nLockTime in the wallet
Previously due to an off-by-one error the wallet ignored nLockTime-by-height transactions that would be valid in the next block even though they are accepted into the mempool. The transactions wouldn't show up until confirmed, nor would they be included in the unconfirmed balance. Similar to the mempool behavior fix in 665bdd3b, the wallet code was calling IsFinalTx() directly without taking into account the fact that doing so tells you if the transaction could have been mined in the *current* block, rather than the next block. To fix this we strip IsFinalTx() of non-consensus-critical functionality, removing the default arguments, and add CheckFinalTx() to check if a transaction will be final in the next block. Github-Pull: #6183 Rebased-From: 28bf06236d3b385e95fe26a7a742395b30efd6ee
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp29
1 files changed, 8 insertions, 21 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 039092cd19..99f4d49438 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -671,14 +671,8 @@ bool IsStandardTx(const CTransaction& tx, string& reason)
bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
{
- AssertLockHeld(cs_main);
- // Time based nLockTime implemented in 0.1.6
if (tx.nLockTime == 0)
return true;
- if (nBlockHeight == 0)
- nBlockHeight = chainActive.Height();
- if (nBlockTime == 0)
- nBlockTime = GetAdjustedTime();
if ((int64_t)tx.nLockTime < ((int64_t)tx.nLockTime < LOCKTIME_THRESHOLD ? (int64_t)nBlockHeight : nBlockTime))
return true;
BOOST_FOREACH(const CTxIn& txin, tx.vin)
@@ -687,6 +681,12 @@ bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
return true;
}
+bool CheckFinalTx(const CTransaction &tx)
+{
+ AssertLockHeld(cs_main);
+ return IsFinalTx(tx, chainActive.Height() + 1, GetAdjustedTime());
+}
+
/**
* Check transaction inputs to mitigate two
* potential denial-of-service attacks:
@@ -903,21 +903,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
// Only accept nLockTime-using transactions that can be mined in the next
// block; we don't want our mempool filled up with transactions that can't
// be mined yet.
- //
- // However, IsFinalTx() is confusing... Without arguments, it uses
- // chainActive.Height() to evaluate nLockTime; when a block is accepted,
- // chainActive.Height() is set to the value of nHeight in the block.
- // However, when IsFinalTx() is called within CBlock::AcceptBlock(), the
- // height of the block *being* evaluated is what is used. Thus if we want
- // to know if a transaction can be part of the *next* block, we need to
- // call IsFinalTx() with one more than chainActive.Height().
- //
- // Timestamps on the other hand don't get any special treatment, because we
- // can't know what timestamp the next block will have, and there aren't
- // timestamp applications where it matters.
- if (!IsFinalTx(tx, chainActive.Height() + 1))
- return state.DoS(0,
- error("AcceptToMemoryPool: non-final"),
+ if (!CheckFinalTx(tx))
+ return state.DoS(0, error("AcceptToMemoryPool: non-final"),
REJECT_NONSTANDARD, "non-final");
// is it already in the memory pool?