Skip to content

Commit 4c15942

Browse files
committed
validation: Pass in chainstate to ::CheckSequenceLocks
1 parent 577b774 commit 4c15942

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

src/test/miner_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct MinerTestingSetup : public TestingSetup {
2828
void TestPackageSelection(const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs);
2929
bool TestSequenceLocks(const CTransaction& tx, int flags) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs)
3030
{
31-
return CheckSequenceLocks(*m_node.mempool, tx, flags);
31+
return CheckSequenceLocks(::ChainstateActive(), *m_node.mempool, tx, flags);
3232
}
3333
BlockAssembler AssemblerForTest(const CChainParams& params);
3434
};

src/txmempool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem
512512
const CTransaction& tx = it->GetTx();
513513
LockPoints lp = it->GetLockPoints();
514514
bool validLP = TestLockPointValidity(&lp);
515-
if (!CheckFinalTx(::ChainActive().Tip(), tx, flags) || !CheckSequenceLocks(*this, tx, flags, &lp, validLP)) {
515+
if (!CheckFinalTx(::ChainActive().Tip(), tx, flags) || !CheckSequenceLocks(::ChainstateActive(), *this, tx, flags, &lp, validLP)) {
516516
// Note if CheckSequenceLocks fails the LockPoints may still be invalid
517517
// So it's critical that we remove the tx and not depend on the LockPoints.
518518
txToRemove.insert(it);

src/validation.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,22 +255,23 @@ bool TestLockPointValidity(const LockPoints* lp)
255255
return true;
256256
}
257257

258-
bool CheckSequenceLocks(const CTxMemPool& pool, const CTransaction& tx, int flags, LockPoints* lp, bool useExistingLockPoints)
258+
bool CheckSequenceLocks(CChainState& active_chainstate, const CTxMemPool& pool, const CTransaction& tx, int flags, LockPoints* lp, bool useExistingLockPoints)
259259
{
260260
AssertLockHeld(cs_main);
261261
AssertLockHeld(pool.cs);
262+
assert(std::addressof(::ChainstateActive()) == std::addressof(active_chainstate));
262263

263-
CBlockIndex* tip = ::ChainActive().Tip();
264+
CBlockIndex* tip = active_chainstate.m_chain.Tip();
264265
assert(tip != nullptr);
265266

266267
CBlockIndex index;
267268
index.pprev = tip;
268-
// CheckSequenceLocks() uses ::ChainActive().Height()+1 to evaluate
269+
// CheckSequenceLocks() uses active_chainstate.m_chain.Height()+1 to evaluate
269270
// height based locks because when SequenceLocks() is called within
270271
// ConnectBlock(), the height of the block *being*
271272
// evaluated is what is used.
272273
// Thus if we want to know if a transaction can be part of the
273-
// *next* block, we need to use one more than ::ChainActive().Height()
274+
// *next* block, we need to use one more than active_chainstate.m_chain.Height()
274275
index.nHeight = tip->nHeight + 1;
275276

276277
std::pair<int, int64_t> lockPair;
@@ -280,8 +281,8 @@ bool CheckSequenceLocks(const CTxMemPool& pool, const CTransaction& tx, int flag
280281
lockPair.second = lp->time;
281282
}
282283
else {
283-
// CoinsTip() contains the UTXO set for ::ChainActive().Tip()
284-
CCoinsViewMemPool viewMemPool(&::ChainstateActive().CoinsTip(), pool);
284+
// CoinsTip() contains the UTXO set for active_chainstate.m_chain.Tip()
285+
CCoinsViewMemPool viewMemPool(&active_chainstate.CoinsTip(), pool);
285286
std::vector<int> prevheights;
286287
prevheights.resize(tx.vin.size());
287288
for (size_t txinIndex = 0; txinIndex < tx.vin.size(); txinIndex++) {
@@ -684,7 +685,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
684685
// be mined yet.
685686
// Must keep pool.cs for this unless we change CheckSequenceLocks to take a
686687
// CoinsViewCache instead of create its own
687-
if (!CheckSequenceLocks(m_pool, tx, STANDARD_LOCKTIME_VERIFY_FLAGS, &lp))
688+
if (!CheckSequenceLocks(::ChainstateActive(), m_pool, tx, STANDARD_LOCKTIME_VERIFY_FLAGS, &lp))
688689
return state.Invalid(TxValidationResult::TX_PREMATURE_SPEND, "non-BIP68-final");
689690

690691
if (!Consensus::CheckTxInputs(tx, state, m_view, g_chainman.m_blockman.GetSpendHeight(m_view), ws.m_base_fees)) {

src/validation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ bool TestLockPointValidity(const LockPoints* lp) EXCLUSIVE_LOCKS_REQUIRED(cs_mai
266266
*
267267
* See consensus/consensus.h for flag definitions.
268268
*/
269-
bool CheckSequenceLocks(const CTxMemPool& pool, const CTransaction& tx, int flags, LockPoints* lp = nullptr, bool useExistingLockPoints = false) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, pool.cs);
269+
bool CheckSequenceLocks(CChainState& active_chainstate, const CTxMemPool& pool, const CTransaction& tx, int flags, LockPoints* lp = nullptr, bool useExistingLockPoints = false) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, pool.cs);
270270

271271
/**
272272
* Closure representing one script verification

0 commit comments

Comments
 (0)