Skip to content

Commit d015eaa

Browse files
committed
validation: Pass in chain tip to ::CheckFinalTx
1 parent 252b489 commit d015eaa

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/validation.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,14 @@ static FlatFileSeq BlockFileSeq();
205205
static FlatFileSeq UndoFileSeq();
206206

207207
bool CheckFinalTx(const CTransaction &tx, int flags)
208+
{
209+
return CheckFinalTx(::ChainActive().Tip(), tx, flags);
210+
}
211+
212+
bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction &tx, int flags)
208213
{
209214
AssertLockHeld(cs_main);
215+
assert(std::addressof(*::ChainActive().Tip()) == std::addressof(*active_chain_tip));
210216

211217
// By convention a negative value for flags indicates that the
212218
// current network-enforced consensus rules should be used. In
@@ -222,15 +228,15 @@ bool CheckFinalTx(const CTransaction &tx, int flags)
222228
// evaluated is what is used. Thus if we want to know if a
223229
// transaction can be part of the *next* block, we need to call
224230
// IsFinalTx() with one more than ::ChainActive().Height().
225-
const int nBlockHeight = ::ChainActive().Height() + 1;
231+
const int nBlockHeight = active_chain_tip->nHeight + 1;
226232

227233
// BIP113 requires that time-locked transactions have nLockTime set to
228234
// less than the median time of the previous block they're contained in.
229235
// When the next block is created its previous block will be the current
230236
// chain tip, so we use that to calculate the median time passed to
231237
// IsFinalTx() if LOCKTIME_MEDIAN_TIME_PAST is set.
232238
const int64_t nBlockTime = (flags & LOCKTIME_MEDIAN_TIME_PAST)
233-
? ::ChainActive().Tip()->GetMedianTimePast()
239+
? active_chain_tip->GetMedianTimePast()
234240
: GetAdjustedTime();
235241

236242
return IsFinalTx(tx, nBlockHeight, nBlockTime);
@@ -599,7 +605,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
599605
// Only accept nLockTime-using transactions that can be mined in the next
600606
// block; we don't want our mempool filled up with transactions that can't
601607
// be mined yet.
602-
if (!CheckFinalTx(tx, STANDARD_LOCKTIME_VERIFY_FLAGS))
608+
if (!CheckFinalTx(::ChainActive().Tip(), tx, STANDARD_LOCKTIME_VERIFY_FLAGS))
603609
return state.Invalid(TxValidationResult::TX_PREMATURE_SPEND, "non-final");
604610

605611
// is it already in the memory pool?

src/validation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight);
249249
* See consensus/consensus.h for flag definitions.
250250
*/
251251
bool CheckFinalTx(const CTransaction &tx, int flags = -1) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
252+
bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction &tx, int flags = -1) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
252253

253254
/**
254255
* Test whether the LockPoints height and time are still valid on the current chain

0 commit comments

Comments
 (0)