0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

validation: Pass in chain to ::TestLockPointValidity

This commit is contained in:
Carl Dong 2020-09-16 17:40:00 -04:00
parent 120aaba9ac
commit 71734c65dc
3 changed files with 5 additions and 4 deletions

View file

@ -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++) { for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
const CTransaction& tx = it->GetTx(); const CTransaction& tx = it->GetTx();
LockPoints lp = it->GetLockPoints(); 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)) { if (!CheckFinalTx(::ChainActive().Tip(), tx, flags) || !CheckSequenceLocks(::ChainstateActive(), *this, tx, flags, &lp, validLP)) {
// Note if CheckSequenceLocks fails the LockPoints may still be invalid // 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. // So it's critical that we remove the tx and not depend on the LockPoints.

View file

@ -237,7 +237,7 @@ bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction &tx, i
return IsFinalTx(tx, nBlockHeight, nBlockTime); return IsFinalTx(tx, nBlockHeight, nBlockTime);
} }
bool TestLockPointValidity(const LockPoints* lp) bool TestLockPointValidity(CChain& active_chain, const LockPoints* lp)
{ {
AssertLockHeld(cs_main); AssertLockHeld(cs_main);
assert(lp); assert(lp);
@ -246,7 +246,8 @@ bool TestLockPointValidity(const LockPoints* lp)
if (lp->maxInputBlock) { if (lp->maxInputBlock) {
// Check whether ::ChainActive() is an extension of the block at which the LockPoints // Check whether ::ChainActive() is an extension of the block at which the LockPoints
// calculation was valid. If not LockPoints are no longer valid // 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; return false;
} }
} }

View file

@ -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 * 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. * Check if transaction will be BIP 68 final in the next block to be created.