Merge bitcoin/bitcoin#23649: circular dependency followups

ddd74ff65c clean up txmempool includes (glozow)
c4efc4db54 change TestLockPointValidity to take a const reference (glozow)
b01784f027 remove unnecessary casts and use braced initialization (glozow)

Pull request description:

  Followups from #22677 + clean up `TestLockPointValidity`

ACKs for top commit:
  theStack:
    Code-review ACK ddd74ff65c

Tree-SHA512: 0f7f26535b7301e2fb379e676310bdc7cfb2c5e232a6657f41dc6d3bc91583ec452eb2359ad2f2416ea12dd856f7fab3fa507a391ccf80f14de96da989281d96
This commit is contained in:
fanquake 2021-12-03 12:07:57 +08:00
commit ffe414bd9a
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1
3 changed files with 12 additions and 12 deletions

View File

@ -5,6 +5,7 @@
#include <txmempool.h>
#include <chain.h>
#include <coins.h>
#include <consensus/consensus.h>
#include <consensus/tx_verify.h>
@ -73,16 +74,15 @@ private:
const LockPoints& lp;
};
bool TestLockPointValidity(CChain& active_chain, const LockPoints* lp)
bool TestLockPointValidity(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) {
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)) {
if (!active_chain.Contains(lp.maxInputBlock)) {
return false;
}
}
@ -649,8 +649,8 @@ void CTxMemPool::removeForReorg(CChain& chain, std::function<bool(txiter)> check
}
RemoveStaged(setAllRemoves, false, MemPoolRemovalReason::REORG);
for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
LockPoints lp = it->GetLockPoints();
if (!TestLockPointValidity(chain, &lp)) {
const LockPoints lp{it->GetLockPoints()};
if (!TestLockPointValidity(chain, lp)) {
mapTx.modify(it, update_lock_points(lp));
}
}

View File

@ -14,7 +14,6 @@
#include <utility>
#include <vector>
#include <chain.h>
#include <coins.h>
#include <consensus/amount.h>
#include <indirectmap.h>
@ -26,12 +25,13 @@
#include <util/epochguard.h>
#include <util/hasher.h>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index_container.hpp>
class CBlockIndex;
class CChain;
class CChainState;
extern RecursiveMutex cs_main;
@ -53,7 +53,7 @@ struct LockPoints {
/**
* Test whether the LockPoints height and time are still valid on the current chain
*/
bool TestLockPointValidity(CChain& active_chain, const LockPoints* lp) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
struct CompareIteratorByHash {
// SFINAE for T where T is either a pointer type (e.g., a txiter) or a reference_wrapper<T>

View File

@ -357,7 +357,7 @@ void CChainState::MaybeUpdateMempoolForReorg(
AssertLockHeld(::cs_main);
const CTransaction& tx = it->GetTx();
LockPoints lp = it->GetLockPoints();
bool validLP = TestLockPointValidity(m_chain, &lp);
const bool validLP{TestLockPointValidity(m_chain, lp)};
CCoinsViewMemPool view_mempool(&CoinsTip(), *m_mempool);
if (!CheckFinalTx(m_chain.Tip(), tx, flags)
|| !CheckSequenceLocks(m_chain.Tip(), view_mempool, tx, flags, &lp, validLP)) {
@ -371,8 +371,8 @@ void CChainState::MaybeUpdateMempoolForReorg(
continue;
const Coin &coin = CoinsTip().AccessCoin(txin.prevout);
assert(!coin.IsSpent());
unsigned int nMemPoolHeight = m_chain.Tip()->nHeight + 1;
if (coin.IsSpent() || (coin.IsCoinBase() && ((signed long)nMemPoolHeight) - coin.nHeight < COINBASE_MATURITY)) {
const auto mempool_spend_height{m_chain.Tip()->nHeight + 1};
if (coin.IsSpent() || (coin.IsCoinBase() && mempool_spend_height - coin.nHeight < COINBASE_MATURITY)) {
should_remove = true;
break;
}