Skip to content

Commit fa4e30b

Browse files
author
MarcoFalke
committed
policy: Remove unused locktime flags
1 parent 2935bd9 commit fa4e30b

File tree

3 files changed

+29
-45
lines changed

3 files changed

+29
-45
lines changed

src/test/miner_tests.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ using node::CBlockTemplate;
3030
namespace miner_tests {
3131
struct MinerTestingSetup : public TestingSetup {
3232
void TestPackageSelection(const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs);
33-
bool TestSequenceLocks(const CTransaction& tx, int flags) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs)
33+
bool TestSequenceLocks(const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs)
3434
{
3535
CCoinsViewMemPool view_mempool(&m_node.chainman->ActiveChainstate().CoinsTip(), *m_node.mempool);
36-
return CheckSequenceLocks(m_node.chainman->ActiveChain().Tip(), view_mempool, tx, flags);
36+
return CheckSequenceLocks(m_node.chainman->ActiveChain().Tip(), view_mempool, tx);
3737
}
3838
BlockAssembler AssemblerForTest(const CChainParams& params);
3939
};
@@ -410,7 +410,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
410410

411411
// non-final txs in mempool
412412
SetMockTime(m_node.chainman->ActiveChain().Tip()->GetMedianTimePast()+1);
413-
int flags = LOCKTIME_VERIFY_SEQUENCE|LOCKTIME_MEDIAN_TIME_PAST;
413+
const int flags{LOCKTIME_VERIFY_SEQUENCE | LOCKTIME_MEDIAN_TIME_PAST};
414414
// height map
415415
std::vector<int> prevheights;
416416

@@ -429,8 +429,8 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
429429
tx.nLockTime = 0;
430430
hash = tx.GetHash();
431431
m_node.mempool->addUnchecked(entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
432-
BOOST_CHECK(CheckFinalTx(m_node.chainman->ActiveChain().Tip(), CTransaction(tx), flags)); // Locktime passes
433-
BOOST_CHECK(!TestSequenceLocks(CTransaction(tx), flags)); // Sequence locks fail
432+
BOOST_CHECK(CheckFinalTx(m_node.chainman->ActiveChain().Tip(), CTransaction{tx})); // Locktime passes
433+
BOOST_CHECK(!TestSequenceLocks(CTransaction{tx})); // Sequence locks fail
434434

435435
{
436436
CBlockIndex* active_chain_tip = m_node.chainman->ActiveChain().Tip();
@@ -443,8 +443,8 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
443443
prevheights[0] = baseheight + 2;
444444
hash = tx.GetHash();
445445
m_node.mempool->addUnchecked(entry.Time(GetTime()).FromTx(tx));
446-
BOOST_CHECK(CheckFinalTx(m_node.chainman->ActiveChain().Tip(), CTransaction(tx), flags)); // Locktime passes
447-
BOOST_CHECK(!TestSequenceLocks(CTransaction(tx), flags)); // Sequence locks fail
446+
BOOST_CHECK(CheckFinalTx(m_node.chainman->ActiveChain().Tip(), CTransaction{tx})); // Locktime passes
447+
BOOST_CHECK(!TestSequenceLocks(CTransaction{tx})); // Sequence locks fail
448448

449449
for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++)
450450
m_node.chainman->ActiveChain().Tip()->GetAncestor(m_node.chainman->ActiveChain().Tip()->nHeight - i)->nTime += 512; //Trick the MedianTimePast
@@ -464,8 +464,8 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
464464
tx.nLockTime = m_node.chainman->ActiveChain().Tip()->nHeight + 1;
465465
hash = tx.GetHash();
466466
m_node.mempool->addUnchecked(entry.Time(GetTime()).FromTx(tx));
467-
BOOST_CHECK(!CheckFinalTx(m_node.chainman->ActiveChain().Tip(), CTransaction(tx), flags)); // Locktime fails
468-
BOOST_CHECK(TestSequenceLocks(CTransaction(tx), flags)); // Sequence locks pass
467+
BOOST_CHECK(!CheckFinalTx(m_node.chainman->ActiveChain().Tip(), CTransaction{tx})); // Locktime fails
468+
BOOST_CHECK(TestSequenceLocks(CTransaction{tx})); // Sequence locks pass
469469
BOOST_CHECK(IsFinalTx(CTransaction(tx), m_node.chainman->ActiveChain().Tip()->nHeight + 2, m_node.chainman->ActiveChain().Tip()->GetMedianTimePast())); // Locktime passes on 2nd block
470470

471471
// absolute time locked
@@ -475,23 +475,23 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
475475
prevheights[0] = baseheight + 4;
476476
hash = tx.GetHash();
477477
m_node.mempool->addUnchecked(entry.Time(GetTime()).FromTx(tx));
478-
BOOST_CHECK(!CheckFinalTx(m_node.chainman->ActiveChain().Tip(), CTransaction(tx), flags)); // Locktime fails
479-
BOOST_CHECK(TestSequenceLocks(CTransaction(tx), flags)); // Sequence locks pass
478+
BOOST_CHECK(!CheckFinalTx(m_node.chainman->ActiveChain().Tip(), CTransaction{tx})); // Locktime fails
479+
BOOST_CHECK(TestSequenceLocks(CTransaction{tx})); // Sequence locks pass
480480
BOOST_CHECK(IsFinalTx(CTransaction(tx), m_node.chainman->ActiveChain().Tip()->nHeight + 2, m_node.chainman->ActiveChain().Tip()->GetMedianTimePast() + 1)); // Locktime passes 1 second later
481481

482482
// mempool-dependent transactions (not added)
483483
tx.vin[0].prevout.hash = hash;
484484
prevheights[0] = m_node.chainman->ActiveChain().Tip()->nHeight + 1;
485485
tx.nLockTime = 0;
486486
tx.vin[0].nSequence = 0;
487-
BOOST_CHECK(CheckFinalTx(m_node.chainman->ActiveChain().Tip(), CTransaction(tx), flags)); // Locktime passes
488-
BOOST_CHECK(TestSequenceLocks(CTransaction(tx), flags)); // Sequence locks pass
487+
BOOST_CHECK(CheckFinalTx(m_node.chainman->ActiveChain().Tip(), CTransaction{tx})); // Locktime passes
488+
BOOST_CHECK(TestSequenceLocks(CTransaction{tx})); // Sequence locks pass
489489
tx.vin[0].nSequence = 1;
490-
BOOST_CHECK(!TestSequenceLocks(CTransaction(tx), flags)); // Sequence locks fail
490+
BOOST_CHECK(!TestSequenceLocks(CTransaction{tx})); // Sequence locks fail
491491
tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG;
492-
BOOST_CHECK(TestSequenceLocks(CTransaction(tx), flags)); // Sequence locks pass
492+
BOOST_CHECK(TestSequenceLocks(CTransaction{tx})); // Sequence locks pass
493493
tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | 1;
494-
BOOST_CHECK(!TestSequenceLocks(CTransaction(tx), flags)); // Sequence locks fail
494+
BOOST_CHECK(!TestSequenceLocks(CTransaction{tx})); // Sequence locks fail
495495

496496
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
497497

src/validation.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,11 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
178178
std::vector<CScriptCheck>* pvChecks = nullptr)
179179
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
180180

181-
bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction &tx, int flags)
181+
bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction& tx)
182182
{
183183
AssertLockHeld(cs_main);
184184
assert(active_chain_tip); // TODO: Make active_chain_tip a reference
185185

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-
194186
// CheckFinalTx() uses active_chain_tip.Height()+1 to evaluate
195187
// nLockTime because when IsFinalTx() is called within
196188
// AcceptBlock(), the height of the block *being*
@@ -203,18 +195,15 @@ bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction &tx, i
203195
// less than the median time of the previous block they're contained in.
204196
// When the next block is created its previous block will be the current
205197
// 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()};
210200

211201
return IsFinalTx(tx, nBlockHeight, nBlockTime);
212202
}
213203

214204
bool CheckSequenceLocks(CBlockIndex* tip,
215205
const CCoinsView& coins_view,
216206
const CTransaction& tx,
217-
int flags,
218207
LockPoints* lp,
219208
bool useExistingLockPoints)
220209
{
@@ -252,7 +241,7 @@ bool CheckSequenceLocks(CBlockIndex* tip,
252241
prevheights[txinIndex] = coin.nHeight;
253242
}
254243
}
255-
lockPair = CalculateSequenceLocks(tx, flags, prevheights, index);
244+
lockPair = CalculateSequenceLocks(tx, STANDARD_LOCKTIME_VERIFY_FLAGS, prevheights, index);
256245
if (lp) {
257246
lp->height = lockPair.first;
258247
lp->time = lockPair.second;
@@ -356,22 +345,22 @@ void CChainState::MaybeUpdateMempoolForReorg(
356345
// Also updates valid entries' cached LockPoints if needed.
357346
// If false, the tx is still valid and its lockpoints are updated.
358347
// If true, the tx would be invalid in the next block; remove this entry and all of its descendants.
359-
const auto filter_final_and_mature = [this, flags=STANDARD_LOCKTIME_VERIFY_FLAGS](CTxMemPool::txiter it)
348+
const auto filter_final_and_mature = [this](CTxMemPool::txiter it)
360349
EXCLUSIVE_LOCKS_REQUIRED(m_mempool->cs, ::cs_main) {
361350
AssertLockHeld(m_mempool->cs);
362351
AssertLockHeld(::cs_main);
363352
const CTransaction& tx = it->GetTx();
364353

365354
// The transaction must be final.
366-
if (!CheckFinalTx(m_chain.Tip(), tx, flags)) return true;
355+
if (!CheckFinalTx(m_chain.Tip(), tx)) return true;
367356
LockPoints lp = it->GetLockPoints();
368357
const bool validLP{TestLockPointValidity(m_chain, lp)};
369358
CCoinsViewMemPool view_mempool(&CoinsTip(), *m_mempool);
370359
// CheckSequenceLocks checks if the transaction will be final in the next block to be
371360
// created on top of the new chain. We use useExistingLockPoints=false so that, instead of
372361
// using the information in lp (which might now refer to a block that no longer exists in
373362
// the chain), it will update lp to contain LockPoints relevant to the new chain.
374-
if (!CheckSequenceLocks(m_chain.Tip(), view_mempool, tx, flags, &lp, validLP)) {
363+
if (!CheckSequenceLocks(m_chain.Tip(), view_mempool, tx, &lp, validLP)) {
375364
// If CheckSequenceLocks fails, remove the tx and don't depend on the LockPoints.
376365
return true;
377366
} else if (!validLP) {
@@ -699,8 +688,9 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
699688
// Only accept nLockTime-using transactions that can be mined in the next
700689
// block; we don't want our mempool filled up with transactions that can't
701690
// be mined yet.
702-
if (!CheckFinalTx(m_active_chainstate.m_chain.Tip(), tx, STANDARD_LOCKTIME_VERIFY_FLAGS))
691+
if (!CheckFinalTx(m_active_chainstate.m_chain.Tip(), tx)) {
703692
return state.Invalid(TxValidationResult::TX_PREMATURE_SPEND, "non-final");
693+
}
704694

705695
if (m_pool.exists(GenTxid::Wtxid(tx.GetWitnessHash()))) {
706696
// Exact transaction already exists in the mempool.
@@ -780,8 +770,9 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
780770
// be mined yet.
781771
// Pass in m_view which has all of the relevant inputs cached. Note that, since m_view's
782772
// backend was removed, it no longer pulls coins from the mempool.
783-
if (!CheckSequenceLocks(m_active_chainstate.m_chain.Tip(), m_view, tx, STANDARD_LOCKTIME_VERIFY_FLAGS, &lp))
773+
if (!CheckSequenceLocks(m_active_chainstate.m_chain.Tip(), m_view, tx, &lp)) {
784774
return state.Invalid(TxValidationResult::TX_PREMATURE_SPEND, "non-BIP68-final");
775+
}
785776

786777
// The mempool holds txs for the next block, so pass height+1 to CheckTxInputs
787778
if (!Consensus::CheckTxInputs(tx, state, m_view, m_active_chainstate.m_chain.Height() + 1, ws.m_base_fees)) {

src/validation.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,12 @@ PackageMempoolAcceptResult ProcessNewPackage(CChainState& active_chainstate, CTx
273273
const Package& txns, bool test_accept)
274274
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
275275

276-
/** Transaction validation functions */
276+
/* Transaction policy functions */
277277

278278
/**
279279
* Check if transaction will be final in the next block to be created.
280-
*
281-
* Calls IsFinalTx() with current block height and appropriate block time.
282-
*
283-
* See consensus/consensus.h for flag definitions.
284280
*/
285-
bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction &tx, int flags = -1) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
281+
bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
286282

287283
/**
288284
* Check if transaction will be BIP68 final in the next block to be created on top of tip.
@@ -300,13 +296,10 @@ bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction &tx, i
300296
* of the block needed for calculation or skips the calculation and uses the LockPoints
301297
* passed in for evaluation.
302298
* The LockPoints should not be considered valid if CheckSequenceLocks returns false.
303-
*
304-
* See consensus/consensus.h for flag definitions.
305299
*/
306300
bool CheckSequenceLocks(CBlockIndex* tip,
307301
const CCoinsView& coins_view,
308302
const CTransaction& tx,
309-
int flags,
310303
LockPoints* lp = nullptr,
311304
bool useExistingLockPoints = false);
312305

0 commit comments

Comments
 (0)