@@ -178,20 +178,12 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
178
178
std::vector<CScriptCheck>* pvChecks = nullptr )
179
179
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
180
180
181
- bool CheckFinalTx (const CBlockIndex* active_chain_tip, const CTransaction &tx, int flags )
181
+ bool CheckFinalTxAtTip (const CBlockIndex* active_chain_tip, const CTransaction& tx )
182
182
{
183
183
AssertLockHeld (cs_main);
184
184
assert (active_chain_tip); // TODO: Make active_chain_tip a reference
185
185
186
- // By convention a negative value for flags indicates that the
187
- // current network-enforced consensus rules should be used. In
188
- // a future soft-fork scenario that would mean checking which
189
- // rules would be enforced for the next block and setting the
190
- // appropriate flags. At the present time no soft-forks are
191
- // scheduled, so no flags are set.
192
- flags = std::max (flags, 0 );
193
-
194
- // CheckFinalTx() uses active_chain_tip.Height()+1 to evaluate
186
+ // CheckFinalTxAtTip() uses active_chain_tip.Height()+1 to evaluate
195
187
// nLockTime because when IsFinalTx() is called within
196
188
// AcceptBlock(), the height of the block *being*
197
189
// evaluated is what is used. Thus if we want to know if a
@@ -203,26 +195,23 @@ bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction &tx, i
203
195
// less than the median time of the previous block they're contained in.
204
196
// When the next block is created its previous block will be the current
205
197
// chain tip, so we use that to calculate the median time passed to
206
- // IsFinalTx() if LOCKTIME_MEDIAN_TIME_PAST is set.
207
- const int64_t nBlockTime = (flags & LOCKTIME_MEDIAN_TIME_PAST)
208
- ? active_chain_tip->GetMedianTimePast ()
209
- : GetAdjustedTime ();
198
+ // IsFinalTx().
199
+ const int64_t nBlockTime{active_chain_tip->GetMedianTimePast ()};
210
200
211
201
return IsFinalTx (tx, nBlockHeight, nBlockTime);
212
202
}
213
203
214
- bool CheckSequenceLocks (CBlockIndex* tip,
204
+ bool CheckSequenceLocksAtTip (CBlockIndex* tip,
215
205
const CCoinsView& coins_view,
216
206
const CTransaction& tx,
217
- int flags,
218
207
LockPoints* lp,
219
208
bool useExistingLockPoints)
220
209
{
221
210
assert (tip != nullptr );
222
211
223
212
CBlockIndex index;
224
213
index.pprev = tip;
225
- // CheckSequenceLocks () uses active_chainstate.m_chain.Height()+1 to evaluate
214
+ // CheckSequenceLocksAtTip () uses active_chainstate.m_chain.Height()+1 to evaluate
226
215
// height based locks because when SequenceLocks() is called within
227
216
// ConnectBlock(), the height of the block *being*
228
217
// evaluated is what is used.
@@ -252,7 +241,7 @@ bool CheckSequenceLocks(CBlockIndex* tip,
252
241
prevheights[txinIndex] = coin.nHeight ;
253
242
}
254
243
}
255
- lockPair = CalculateSequenceLocks (tx, flags , prevheights, index);
244
+ lockPair = CalculateSequenceLocks (tx, STANDARD_LOCKTIME_VERIFY_FLAGS , prevheights, index);
256
245
if (lp) {
257
246
lp->height = lockPair.first ;
258
247
lp->time = lockPair.second ;
@@ -268,7 +257,7 @@ bool CheckSequenceLocks(CBlockIndex* tip,
268
257
// lockPair from CalculateSequenceLocks against tip+1. We know
269
258
// EvaluateSequenceLocks will fail if there was a non-zero sequence
270
259
// lock on a mempool input, so we can use the return value of
271
- // CheckSequenceLocks to indicate the LockPoints validity
260
+ // CheckSequenceLocksAtTip to indicate the LockPoints validity
272
261
int maxInputHeight = 0 ;
273
262
for (const int height : prevheights) {
274
263
// Can ignore mempool inputs since we'll fail if they had non-zero locks
@@ -358,26 +347,26 @@ void CChainState::MaybeUpdateMempoolForReorg(
358
347
// Also updates valid entries' cached LockPoints if needed.
359
348
// If false, the tx is still valid and its lockpoints are updated.
360
349
// If true, the tx would be invalid in the next block; remove this entry and all of its descendants.
361
- const auto filter_final_and_mature = [this , flags=STANDARD_LOCKTIME_VERIFY_FLAGS ](CTxMemPool::txiter it)
350
+ const auto filter_final_and_mature = [this ](CTxMemPool::txiter it)
362
351
EXCLUSIVE_LOCKS_REQUIRED (m_mempool->cs , ::cs_main) {
363
352
AssertLockHeld (m_mempool->cs );
364
353
AssertLockHeld (::cs_main);
365
354
const CTransaction& tx = it->GetTx ();
366
355
367
356
// The transaction must be final.
368
- if (!CheckFinalTx (m_chain.Tip (), tx, flags )) return true ;
357
+ if (!CheckFinalTxAtTip (m_chain.Tip (), tx)) return true ;
369
358
LockPoints lp = it->GetLockPoints ();
370
359
const bool validLP{TestLockPointValidity (m_chain, lp)};
371
360
CCoinsViewMemPool view_mempool (&CoinsTip (), *m_mempool);
372
- // CheckSequenceLocks checks if the transaction will be final in the next block to be
361
+ // CheckSequenceLocksAtTip checks if the transaction will be final in the next block to be
373
362
// created on top of the new chain. We use useExistingLockPoints=false so that, instead of
374
363
// using the information in lp (which might now refer to a block that no longer exists in
375
364
// the chain), it will update lp to contain LockPoints relevant to the new chain.
376
- if (!CheckSequenceLocks (m_chain.Tip (), view_mempool, tx, flags , &lp, validLP)) {
377
- // If CheckSequenceLocks fails, remove the tx and don't depend on the LockPoints.
365
+ if (!CheckSequenceLocksAtTip (m_chain.Tip (), view_mempool, tx, &lp, validLP)) {
366
+ // If CheckSequenceLocksAtTip fails, remove the tx and don't depend on the LockPoints.
378
367
return true ;
379
368
} else if (!validLP) {
380
- // If CheckSequenceLocks succeeded, it also updated the LockPoints.
369
+ // If CheckSequenceLocksAtTip succeeded, it also updated the LockPoints.
381
370
// Now update the mempool entry lockpoints as well.
382
371
m_mempool->mapTx .modify (it, [&lp](CTxMemPoolEntry& e) { e.UpdateLockPoints (lp); });
383
372
}
@@ -722,8 +711,9 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
722
711
// Only accept nLockTime-using transactions that can be mined in the next
723
712
// block; we don't want our mempool filled up with transactions that can't
724
713
// be mined yet.
725
- if (!CheckFinalTx (m_active_chainstate.m_chain .Tip (), tx, STANDARD_LOCKTIME_VERIFY_FLAGS))
714
+ if (!CheckFinalTxAtTip (m_active_chainstate.m_chain .Tip (), tx)) {
726
715
return state.Invalid (TxValidationResult::TX_PREMATURE_SPEND, " non-final" );
716
+ }
727
717
728
718
if (m_pool.exists (GenTxid::Wtxid (tx.GetWitnessHash ()))) {
729
719
// Exact transaction already exists in the mempool.
@@ -803,8 +793,9 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
803
793
// be mined yet.
804
794
// Pass in m_view which has all of the relevant inputs cached. Note that, since m_view's
805
795
// backend was removed, it no longer pulls coins from the mempool.
806
- if (!CheckSequenceLocks (m_active_chainstate.m_chain .Tip (), m_view, tx, STANDARD_LOCKTIME_VERIFY_FLAGS, &lp))
796
+ if (!CheckSequenceLocksAtTip (m_active_chainstate.m_chain .Tip (), m_view, tx, &lp)) {
807
797
return state.Invalid (TxValidationResult::TX_PREMATURE_SPEND, " non-BIP68-final" );
798
+ }
808
799
809
800
// The mempool holds txs for the next block, so pass height+1 to CheckTxInputs
810
801
if (!Consensus::CheckTxInputs (tx, state, m_view, m_active_chainstate.m_chain .Height () + 1 , ws.m_base_fees )) {
0 commit comments