From bd99a74d3edc6ddcdf8d1d4883b60223883a6c26 Mon Sep 17 00:00:00 2001 From: glozow Date: Tue, 30 Nov 2021 11:21:02 +0000 Subject: [PATCH] TestLockPointValidity to txmempool Summary: This is a partial backport of [[https://github.com/bitcoin/bitcoin/pull/22677 | core#22677]] and [[https://github.com/bitcoin/bitcoin/pull/23649 | core#23649]] https://github.com/bitcoin/bitcoin/pull/22677/commits/1b3a11e126b258fba975ed7c452221608f2c5472 https://github.com/bitcoin/bitcoin/pull/23649/commits/ddd74ff65c471c5c25815ac0643d16ea0d51f58f Depends on D12442 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D12440 --- src/txmempool.cpp | 19 +++++++++++++++++++ src/txmempool.h | 8 ++++++++ src/validation.cpp | 19 ------------------- src/validation.h | 7 ------- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 3e01c0d3dd..1202418f37 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -82,6 +82,25 @@ struct update_lock_points { const LockPoints &lp; }; +bool TestLockPointValidity(const CChain &active_chain, const LockPoints *lp) { + AssertLockHeld(cs_main); + assert(lp); + // If there are relative lock times then the maxInputBlock will be set + // If there are no relative lock times, the LockPoints don't depend on the + // chain + if (lp->maxInputBlock) { + // Check whether active_chain is an extension of the block at which the + // LockPoints calculation was valid. If not LockPoints are no longer + // valid + if (!active_chain.Contains(lp->maxInputBlock)) { + return false; + } + } + + // LockPoints still valid + return true; +} + CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef &_tx, const Amount fee, int64_t time, unsigned int entry_height, bool spends_coinbase, int64_t sigops_count, diff --git a/src/txmempool.h b/src/txmempool.h index bb8b4cd065..e2d9258458 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -30,6 +30,7 @@ #include class CBlockIndex; +class CChain; class CChainState; class Config; @@ -53,6 +54,13 @@ struct LockPoints { CBlockIndex *maxInputBlock{nullptr}; }; +/** + * Test whether the LockPoints height and time are still valid on the current + * chain. + */ +bool TestLockPointValidity(const CChain &active_chain, const LockPoints *lp) + EXCLUSIVE_LOCKS_REQUIRED(cs_main); + struct CompareIteratorById { // SFINAE for T where T is either a pointer type (e.g., a txiter) or a // reference_wrapper (e.g. a wrapped CTxMemPoolEntry&) diff --git a/src/validation.cpp b/src/validation.cpp index 9ef6ebf40e..969284e334 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -156,25 +156,6 @@ CBlockIndex *BlockManager::FindForkInGlobalIndex(const CChain &chain, static uint32_t GetNextBlockScriptFlags(const Consensus::Params ¶ms, const CBlockIndex *pindex); -bool TestLockPointValidity(const CChain &active_chain, const LockPoints *lp) { - AssertLockHeld(cs_main); - assert(lp); - // If there are relative lock times then the maxInputBlock will be set - // If there are no relative lock times, the LockPoints don't depend on the - // chain - if (lp->maxInputBlock) { - // Check whether active_chain is an extension of the block at which - // the LockPoints calculation was valid. If not LockPoints are no longer - // valid. - if (!active_chain.Contains(lp->maxInputBlock)) { - return false; - } - } - - // LockPoints still valid - return true; -} - bool CheckSequenceLocks(CBlockIndex *tip, const CCoinsView &coins_view, const CTransaction &tx, int flags, LockPoints *lp, bool useExistingLockPoints) { diff --git a/src/validation.h b/src/validation.h index 7fc4080c28..f8b3e9d712 100644 --- a/src/validation.h +++ b/src/validation.h @@ -470,13 +470,6 @@ void SpendCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo, void UpdateCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo, int nHeight); -/** - * Test whether the LockPoints height and time are still valid on the current - * chain. - */ -bool TestLockPointValidity(const CChain &active_chain, const LockPoints *lp) - EXCLUSIVE_LOCKS_REQUIRED(cs_main); - /** * Check if transaction will be BIP68 final in the next block to be created on * top of tip.