Skip to content

Commit efaf2d8

Browse files
author
MarcoFalke
committed
Merge #13783: validation: Pass tx pool reference into CheckSequenceLocks
fa511e8 Pass tx pool reference into CheckSequenceLocks (MarcoFalke) Pull request description: `CheckSequenceLocks` is called from ATMP and the member function `CTxMemPool::removeForReorg` without passing in the tx pool object that is used in those function's scope and instead using the global `::mempool` instance. This fix should be refactoring only, since currently there is only one (global) tx pool in normal operation. Though, it fixes hard to track down issues in future settings where more than one mempool exists at a time. (E.g. for tests, rpc or p2p tx relay purposes) Tree-SHA512: f0804588c7d29bb6ff05ec14f22a16422b89ab31ae714f38cd07f811d7dc7907bfd14e799c4c1c3121144ff22711019bbe9212b39e2fd4531936a4119950fa49
2 parents c70f9c0 + fa511e8 commit efaf2d8

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/test/miner_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ static CBlockIndex CreateBlockIndex(int nHeight)
9292

9393
static bool TestSequenceLocks(const CTransaction &tx, int flags) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
9494
{
95-
LOCK(mempool.cs);
96-
return CheckSequenceLocks(tx, flags);
95+
LOCK(::mempool.cs);
96+
return CheckSequenceLocks(::mempool, tx, flags);
9797
}
9898

9999
// Test suite for ancestor feerate transaction selection.

src/txmempool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem
498498
const CTransaction& tx = it->GetTx();
499499
LockPoints lp = it->GetLockPoints();
500500
bool validLP = TestLockPointValidity(&lp);
501-
if (!CheckFinalTx(tx, flags) || !CheckSequenceLocks(tx, flags, &lp, validLP)) {
501+
if (!CheckFinalTx(tx, flags) || !CheckSequenceLocks(*this, tx, flags, &lp, validLP)) {
502502
// Note if CheckSequenceLocks fails the LockPoints may still be invalid
503503
// So it's critical that we remove the tx and not depend on the LockPoints.
504504
txToRemove.insert(it);

src/validation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,10 @@ bool TestLockPointValidity(const LockPoints* lp)
361361
return true;
362362
}
363363

364-
bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp, bool useExistingLockPoints)
364+
bool CheckSequenceLocks(const CTxMemPool& pool, const CTransaction& tx, int flags, LockPoints* lp, bool useExistingLockPoints)
365365
{
366366
AssertLockHeld(cs_main);
367-
AssertLockHeld(mempool.cs);
367+
AssertLockHeld(pool.cs);
368368

369369
CBlockIndex* tip = chainActive.Tip();
370370
assert(tip != nullptr);
@@ -387,7 +387,7 @@ bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp, bool
387387
}
388388
else {
389389
// pcoinsTip contains the UTXO set for chainActive.Tip()
390-
CCoinsViewMemPool viewMemPool(pcoinsTip.get(), mempool);
390+
CCoinsViewMemPool viewMemPool(pcoinsTip.get(), pool);
391391
std::vector<int> prevheights;
392392
prevheights.resize(tx.vin.size());
393393
for (size_t txinIndex = 0; txinIndex < tx.vin.size(); txinIndex++) {
@@ -679,7 +679,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
679679
// be mined yet.
680680
// Must keep pool.cs for this unless we change CheckSequenceLocks to take a
681681
// CoinsViewCache instead of create its own
682-
if (!CheckSequenceLocks(tx, STANDARD_LOCKTIME_VERIFY_FLAGS, &lp))
682+
if (!CheckSequenceLocks(pool, tx, STANDARD_LOCKTIME_VERIFY_FLAGS, &lp))
683683
return state.DoS(0, false, REJECT_NONSTANDARD, "non-BIP68-final");
684684

685685
CAmount nFees = 0;

src/validation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ bool TestLockPointValidity(const LockPoints* lp) EXCLUSIVE_LOCKS_REQUIRED(cs_mai
347347
*
348348
* See consensus/consensus.h for flag definitions.
349349
*/
350-
bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp = nullptr, bool useExistingLockPoints = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
350+
bool CheckSequenceLocks(const CTxMemPool& pool, const CTransaction& tx, int flags, LockPoints* lp = nullptr, bool useExistingLockPoints = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
351351

352352
/**
353353
* Closure representing one script verification

0 commit comments

Comments
 (0)