From 71734c65dc491a4bb654ccbb7a1dd0e12131cee4 Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Wed, 16 Sep 2020 17:40:00 -0400 Subject: [PATCH] validation: Pass in chain to ::TestLockPointValidity --- src/txmempool.cpp | 2 +- src/validation.cpp | 5 +++-- src/validation.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 197cd6cd4bd..031077fa757 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -511,7 +511,7 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) { const CTransaction& tx = it->GetTx(); LockPoints lp = it->GetLockPoints(); - bool validLP = TestLockPointValidity(&lp); + bool validLP = TestLockPointValidity(::ChainActive(), &lp); if (!CheckFinalTx(::ChainActive().Tip(), tx, flags) || !CheckSequenceLocks(::ChainstateActive(), *this, tx, flags, &lp, validLP)) { // Note if CheckSequenceLocks fails the LockPoints may still be invalid // So it's critical that we remove the tx and not depend on the LockPoints. diff --git a/src/validation.cpp b/src/validation.cpp index 0b4f0dbb4ce..870f41a16ff 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -237,7 +237,7 @@ bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction &tx, i return IsFinalTx(tx, nBlockHeight, nBlockTime); } -bool TestLockPointValidity(const LockPoints* lp) +bool TestLockPointValidity(CChain& active_chain, const LockPoints* lp) { AssertLockHeld(cs_main); assert(lp); @@ -246,7 +246,8 @@ bool TestLockPointValidity(const LockPoints* lp) if (lp->maxInputBlock) { // Check whether ::ChainActive() is an extension of the block at which the LockPoints // calculation was valid. If not LockPoints are no longer valid - if (!::ChainActive().Contains(lp->maxInputBlock)) { + assert(std::addressof(::ChainActive()) == std::addressof(active_chain)); + if (!active_chain.Contains(lp->maxInputBlock)) { return false; } } diff --git a/src/validation.h b/src/validation.h index 739f4f1d996..7fc0d31c702 100644 --- a/src/validation.h +++ b/src/validation.h @@ -253,7 +253,7 @@ bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction &tx, i /** * Test whether the LockPoints height and time are still valid on the current chain */ -bool TestLockPointValidity(const LockPoints* lp) EXCLUSIVE_LOCKS_REQUIRED(cs_main); +bool TestLockPointValidity(CChain& active_chain, const LockPoints* lp) EXCLUSIVE_LOCKS_REQUIRED(cs_main); /** * Check if transaction will be BIP 68 final in the next block to be created.