aboutsummaryrefslogtreecommitdiff
path: root/src/validation.cpp
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2020-09-16 17:17:45 -0400
committerCarl Dong <contact@carldong.me>2021-02-18 14:43:28 -0500
commitd015eaa550027a387cd548cf0bcfa1a4c31a3374 (patch)
treef4eb6c6dde406c7ffcd2d37e9cf694a9fbdee22a /src/validation.cpp
parent252b489c9f9c9e7dceb919e9cbd208ea72d75e68 (diff)
downloadbitcoin-d015eaa550027a387cd548cf0bcfa1a4c31a3374.tar.xz
validation: Pass in chain tip to ::CheckFinalTx
Diffstat (limited to 'src/validation.cpp')
-rw-r--r--src/validation.cpp12
1 files changed, 9 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?