diff options
author | Carl Dong <contact@carldong.me> | 2020-09-16 17:17:45 -0400 |
---|---|---|
committer | Carl Dong <contact@carldong.me> | 2021-02-18 14:43:28 -0500 |
commit | d015eaa550027a387cd548cf0bcfa1a4c31a3374 (patch) | |
tree | f4eb6c6dde406c7ffcd2d37e9cf694a9fbdee22a /src | |
parent | 252b489c9f9c9e7dceb919e9cbd208ea72d75e68 (diff) | |
download | bitcoin-d015eaa550027a387cd548cf0bcfa1a4c31a3374.tar.xz |
validation: Pass in chain tip to ::CheckFinalTx
Diffstat (limited to 'src')
-rw-r--r-- | src/validation.cpp | 12 | ||||
-rw-r--r-- | src/validation.h | 1 |
2 files changed, 10 insertions, 3 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index b049acb885..8f076ce789 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -206,7 +206,13 @@ static FlatFileSeq UndoFileSeq(); bool CheckFinalTx(const CTransaction &tx, int flags) { + return CheckFinalTx(::ChainActive().Tip(), tx, flags); +} + +bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction &tx, int flags) +{ AssertLockHeld(cs_main); + assert(std::addressof(*::ChainActive().Tip()) == std::addressof(*active_chain_tip)); // By convention a negative value for flags indicates that the // current network-enforced consensus rules should be used. In @@ -222,7 +228,7 @@ bool CheckFinalTx(const CTransaction &tx, int flags) // 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(). - const int nBlockHeight = ::ChainActive().Height() + 1; + const int nBlockHeight = active_chain_tip->nHeight + 1; // BIP113 requires that time-locked transactions have nLockTime set to // less than the median time of the previous block they're contained in. @@ -230,7 +236,7 @@ bool CheckFinalTx(const CTransaction &tx, int flags) // chain tip, so we use that to calculate the median time passed to // IsFinalTx() if LOCKTIME_MEDIAN_TIME_PAST is set. const int64_t nBlockTime = (flags & LOCKTIME_MEDIAN_TIME_PAST) - ? ::ChainActive().Tip()->GetMedianTimePast() + ? active_chain_tip->GetMedianTimePast() : GetAdjustedTime(); return IsFinalTx(tx, nBlockHeight, nBlockTime); @@ -599,7 +605,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws) // 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. - if (!CheckFinalTx(tx, STANDARD_LOCKTIME_VERIFY_FLAGS)) + if (!CheckFinalTx(::ChainActive().Tip(), tx, STANDARD_LOCKTIME_VERIFY_FLAGS)) return state.Invalid(TxValidationResult::TX_PREMATURE_SPEND, "non-final"); // is it already in the memory pool? diff --git a/src/validation.h b/src/validation.h index 1a71dd0d49..16bf14875b 100644 --- a/src/validation.h +++ b/src/validation.h @@ -249,6 +249,7 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight); * See consensus/consensus.h for flag definitions. */ bool CheckFinalTx(const CTransaction &tx, int flags = -1) EXCLUSIVE_LOCKS_REQUIRED(cs_main); +bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction &tx, int flags = -1) EXCLUSIVE_LOCKS_REQUIRED(cs_main); /** * Test whether the LockPoints height and time are still valid on the current chain |