merge bitcoin#23649: circular dependency followups

This commit is contained in:
Kittywhiskers Van Gogh 2021-12-02 11:47:20 +00:00
parent 8ab99290f9
commit e85862ba11
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
3 changed files with 12 additions and 12 deletions

View File

@ -5,6 +5,7 @@
#include <txmempool.h> #include <txmempool.h>
#include <chain.h>
#include <coins.h> #include <coins.h>
#include <consensus/consensus.h> #include <consensus/consensus.h>
#include <consensus/tx_verify.h> #include <consensus/tx_verify.h>
@ -81,16 +82,15 @@ private:
const LockPoints& lp; const LockPoints& lp;
}; };
bool TestLockPointValidity(CChain& active_chain, const LockPoints* lp) bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp)
{ {
AssertLockHeld(cs_main); AssertLockHeld(cs_main);
assert(lp);
// If there are relative lock times then the maxInputBlock will be set // 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 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 // Check whether active_chain 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 (!active_chain.Contains(lp->maxInputBlock)) { if (!active_chain.Contains(lp.maxInputBlock)) {
return false; return false;
} }
} }
@ -892,8 +892,8 @@ void CTxMemPool::removeForReorg(CChain& chain, std::function<bool(txiter)> check
} }
RemoveStaged(setAllRemoves, false, MemPoolRemovalReason::REORG); RemoveStaged(setAllRemoves, false, MemPoolRemovalReason::REORG);
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++) {
LockPoints lp = it->GetLockPoints(); const LockPoints lp{it->GetLockPoints()};
if (!TestLockPointValidity(chain, &lp)) { if (!TestLockPointValidity(chain, lp)) {
mapTx.modify(it, update_lock_points(lp)); mapTx.modify(it, update_lock_points(lp));
} }
} }

View File

@ -17,7 +17,6 @@
#include <addressindex.h> #include <addressindex.h>
#include <spentindex.h> #include <spentindex.h>
#include <amount.h> #include <amount.h>
#include <chain.h>
#include <coins.h> #include <coins.h>
#include <gsl/pointers.h> #include <gsl/pointers.h>
#include <indirectmap.h> #include <indirectmap.h>
@ -31,12 +30,13 @@
#include <util/epochguard.h> #include <util/epochguard.h>
#include <util/hasher.h> #include <util/hasher.h>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp> #include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/sequenced_index.hpp> #include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index_container.hpp>
class CBlockIndex; class CBlockIndex;
class CChain;
class CChainState; class CChainState;
extern RecursiveMutex cs_main; extern RecursiveMutex cs_main;
@ -63,7 +63,7 @@ struct LockPoints {
/** /**
* 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(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 { struct CompareIteratorByHash {
// SFINAE for T where T is either a pointer type (e.g., a txiter) or a reference_wrapper<T> // SFINAE for T where T is either a pointer type (e.g., a txiter) or a reference_wrapper<T>

View File

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