@@ -205,8 +205,14 @@ static FlatFileSeq BlockFileSeq();
205
205
static FlatFileSeq UndoFileSeq ();
206
206
207
207
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)
208
213
{
209
214
AssertLockHeld (cs_main);
215
+ assert (std::addressof (*::ChainActive ().Tip ()) == std::addressof (*active_chain_tip));
210
216
211
217
// By convention a negative value for flags indicates that the
212
218
// current network-enforced consensus rules should be used. In
@@ -222,15 +228,15 @@ bool CheckFinalTx(const CTransaction &tx, int flags)
222
228
// evaluated is what is used. Thus if we want to know if a
223
229
// transaction can be part of the *next* block, we need to call
224
230
// IsFinalTx() with one more than ::ChainActive().Height().
225
- const int nBlockHeight = :: ChainActive (). Height () + 1 ;
231
+ const int nBlockHeight = active_chain_tip-> nHeight + 1 ;
226
232
227
233
// BIP113 requires that time-locked transactions have nLockTime set to
228
234
// less than the median time of the previous block they're contained in.
229
235
// When the next block is created its previous block will be the current
230
236
// chain tip, so we use that to calculate the median time passed to
231
237
// IsFinalTx() if LOCKTIME_MEDIAN_TIME_PAST is set.
232
238
const int64_t nBlockTime = (flags & LOCKTIME_MEDIAN_TIME_PAST)
233
- ? :: ChainActive (). Tip () ->GetMedianTimePast ()
239
+ ? active_chain_tip ->GetMedianTimePast ()
234
240
: GetAdjustedTime ();
235
241
236
242
return IsFinalTx (tx, nBlockHeight, nBlockTime);
@@ -599,7 +605,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
599
605
// Only accept nLockTime-using transactions that can be mined in the next
600
606
// block; we don't want our mempool filled up with transactions that can't
601
607
// be mined yet.
602
- if (!CheckFinalTx (tx, STANDARD_LOCKTIME_VERIFY_FLAGS))
608
+ if (!CheckFinalTx (:: ChainActive (). Tip (), tx, STANDARD_LOCKTIME_VERIFY_FLAGS))
603
609
return state.Invalid (TxValidationResult::TX_PREMATURE_SPEND, " non-final" );
604
610
605
611
// is it already in the memory pool?
0 commit comments