Skip to content

Commit fa8d4d9

Browse files
author
MarcoFalke
committed
scripted-diff: Clarify CheckFinalTxAtTip name
This checks finality at the current Tip, so clarify this in its name. -BEGIN VERIFY SCRIPT- ren() { sed -i "s/\<$1\>/$2/g" $( git grep -l "$1" ./src/ ) ; } ren CheckSequenceLocks CheckSequenceLocksAtTip ren CheckFinalTx CheckFinalTxAtTip -END VERIFY SCRIPT-
1 parent fa4e30b commit fa8d4d9

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

src/test/miner_tests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct MinerTestingSetup : public TestingSetup {
3333
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);
36+
return CheckSequenceLocksAtTip(m_node.chainman->ActiveChain().Tip(), view_mempool, tx);
3737
}
3838
BlockAssembler AssemblerForTest(const CChainParams& params);
3939
};
@@ -429,7 +429,7 @@ 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})); // Locktime passes
432+
BOOST_CHECK(CheckFinalTxAtTip(m_node.chainman->ActiveChain().Tip(), CTransaction{tx})); // Locktime passes
433433
BOOST_CHECK(!TestSequenceLocks(CTransaction{tx})); // Sequence locks fail
434434

435435
{
@@ -443,7 +443,7 @@ 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})); // Locktime passes
446+
BOOST_CHECK(CheckFinalTxAtTip(m_node.chainman->ActiveChain().Tip(), CTransaction{tx})); // Locktime passes
447447
BOOST_CHECK(!TestSequenceLocks(CTransaction{tx})); // Sequence locks fail
448448

449449
for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++)
@@ -464,7 +464,7 @@ 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})); // Locktime fails
467+
BOOST_CHECK(!CheckFinalTxAtTip(m_node.chainman->ActiveChain().Tip(), CTransaction{tx})); // Locktime fails
468468
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

@@ -475,7 +475,7 @@ 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})); // Locktime fails
478+
BOOST_CHECK(!CheckFinalTxAtTip(m_node.chainman->ActiveChain().Tip(), CTransaction{tx})); // Locktime fails
479479
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

@@ -484,7 +484,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
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})); // Locktime passes
487+
BOOST_CHECK(CheckFinalTxAtTip(m_node.chainman->ActiveChain().Tip(), CTransaction{tx})); // Locktime passes
488488
BOOST_CHECK(TestSequenceLocks(CTransaction{tx})); // Sequence locks pass
489489
tx.vin[0].nSequence = 1;
490490
BOOST_CHECK(!TestSequenceLocks(CTransaction{tx})); // Sequence locks fail

src/validation.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ 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)
181+
bool CheckFinalTxAtTip(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-
// CheckFinalTx() uses active_chain_tip.Height()+1 to evaluate
186+
// CheckFinalTxAtTip() uses active_chain_tip.Height()+1 to evaluate
187187
// nLockTime because when IsFinalTx() is called within
188188
// AcceptBlock(), the height of the block *being*
189189
// evaluated is what is used. Thus if we want to know if a
@@ -201,7 +201,7 @@ bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction& tx)
201201
return IsFinalTx(tx, nBlockHeight, nBlockTime);
202202
}
203203

204-
bool CheckSequenceLocks(CBlockIndex* tip,
204+
bool CheckSequenceLocksAtTip(CBlockIndex* tip,
205205
const CCoinsView& coins_view,
206206
const CTransaction& tx,
207207
LockPoints* lp,
@@ -211,7 +211,7 @@ bool CheckSequenceLocks(CBlockIndex* tip,
211211

212212
CBlockIndex index;
213213
index.pprev = tip;
214-
// CheckSequenceLocks() uses active_chainstate.m_chain.Height()+1 to evaluate
214+
// CheckSequenceLocksAtTip() uses active_chainstate.m_chain.Height()+1 to evaluate
215215
// height based locks because when SequenceLocks() is called within
216216
// ConnectBlock(), the height of the block *being*
217217
// evaluated is what is used.
@@ -257,7 +257,7 @@ bool CheckSequenceLocks(CBlockIndex* tip,
257257
// lockPair from CalculateSequenceLocks against tip+1. We know
258258
// EvaluateSequenceLocks will fail if there was a non-zero sequence
259259
// lock on a mempool input, so we can use the return value of
260-
// CheckSequenceLocks to indicate the LockPoints validity
260+
// CheckSequenceLocksAtTip to indicate the LockPoints validity
261261
int maxInputHeight = 0;
262262
for (const int height : prevheights) {
263263
// Can ignore mempool inputs since we'll fail if they had non-zero locks
@@ -352,19 +352,19 @@ void CChainState::MaybeUpdateMempoolForReorg(
352352
const CTransaction& tx = it->GetTx();
353353

354354
// The transaction must be final.
355-
if (!CheckFinalTx(m_chain.Tip(), tx)) return true;
355+
if (!CheckFinalTxAtTip(m_chain.Tip(), tx)) return true;
356356
LockPoints lp = it->GetLockPoints();
357357
const bool validLP{TestLockPointValidity(m_chain, lp)};
358358
CCoinsViewMemPool view_mempool(&CoinsTip(), *m_mempool);
359-
// CheckSequenceLocks checks if the transaction will be final in the next block to be
359+
// CheckSequenceLocksAtTip checks if the transaction will be final in the next block to be
360360
// created on top of the new chain. We use useExistingLockPoints=false so that, instead of
361361
// using the information in lp (which might now refer to a block that no longer exists in
362362
// the chain), it will update lp to contain LockPoints relevant to the new chain.
363-
if (!CheckSequenceLocks(m_chain.Tip(), view_mempool, tx, &lp, validLP)) {
364-
// If CheckSequenceLocks fails, remove the tx and don't depend on the LockPoints.
363+
if (!CheckSequenceLocksAtTip(m_chain.Tip(), view_mempool, tx, &lp, validLP)) {
364+
// If CheckSequenceLocksAtTip fails, remove the tx and don't depend on the LockPoints.
365365
return true;
366366
} else if (!validLP) {
367-
// If CheckSequenceLocks succeeded, it also updated the LockPoints.
367+
// If CheckSequenceLocksAtTip succeeded, it also updated the LockPoints.
368368
// Now update the mempool entry lockpoints as well.
369369
m_mempool->mapTx.modify(it, [&lp](CTxMemPoolEntry& e) { e.UpdateLockPoints(lp); });
370370
}
@@ -688,7 +688,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
688688
// Only accept nLockTime-using transactions that can be mined in the next
689689
// block; we don't want our mempool filled up with transactions that can't
690690
// be mined yet.
691-
if (!CheckFinalTx(m_active_chainstate.m_chain.Tip(), tx)) {
691+
if (!CheckFinalTxAtTip(m_active_chainstate.m_chain.Tip(), tx)) {
692692
return state.Invalid(TxValidationResult::TX_PREMATURE_SPEND, "non-final");
693693
}
694694

@@ -770,7 +770,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
770770
// be mined yet.
771771
// Pass in m_view which has all of the relevant inputs cached. Note that, since m_view's
772772
// backend was removed, it no longer pulls coins from the mempool.
773-
if (!CheckSequenceLocks(m_active_chainstate.m_chain.Tip(), m_view, tx, &lp)) {
773+
if (!CheckSequenceLocksAtTip(m_active_chainstate.m_chain.Tip(), m_view, tx, &lp)) {
774774
return state.Invalid(TxValidationResult::TX_PREMATURE_SPEND, "non-BIP68-final");
775775
}
776776

src/validation.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ PackageMempoolAcceptResult ProcessNewPackage(CChainState& active_chainstate, CTx
278278
/**
279279
* Check if transaction will be final in the next block to be created.
280280
*/
281-
bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
281+
bool CheckFinalTxAtTip(const CBlockIndex* active_chain_tip, const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
282282

283283
/**
284284
* Check if transaction will be BIP68 final in the next block to be created on top of tip.
@@ -295,9 +295,9 @@ bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction& tx) E
295295
* Optionally stores in LockPoints the resulting height and time calculated and the hash
296296
* of the block needed for calculation or skips the calculation and uses the LockPoints
297297
* passed in for evaluation.
298-
* The LockPoints should not be considered valid if CheckSequenceLocks returns false.
298+
* The LockPoints should not be considered valid if CheckSequenceLocksAtTip returns false.
299299
*/
300-
bool CheckSequenceLocks(CBlockIndex* tip,
300+
bool CheckSequenceLocksAtTip(CBlockIndex* tip,
301301
const CCoinsView& coins_view,
302302
const CTransaction& tx,
303303
LockPoints* lp = nullptr,

0 commit comments

Comments
 (0)