Skip to content

Commit ffe414b

Browse files
committed
Merge bitcoin/bitcoin#23649: circular dependency followups
ddd74ff clean up txmempool includes (glozow) c4efc4d change TestLockPointValidity to take a const reference (glozow) b01784f 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 ddd74ff Tree-SHA512: 0f7f26535b7301e2fb379e676310bdc7cfb2c5e232a6657f41dc6d3bc91583ec452eb2359ad2f2416ea12dd856f7fab3fa507a391ccf80f14de96da989281d96
2 parents 0b30bdd + ddd74ff commit ffe414b

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/txmempool.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <txmempool.h>
77

8+
#include <chain.h>
89
#include <coins.h>
910
#include <consensus/consensus.h>
1011
#include <consensus/tx_verify.h>
@@ -73,16 +74,15 @@ struct update_lock_points
7374
const LockPoints& lp;
7475
};
7576

76-
bool TestLockPointValidity(CChain& active_chain, const LockPoints* lp)
77+
bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp)
7778
{
7879
AssertLockHeld(cs_main);
79-
assert(lp);
8080
// If there are relative lock times then the maxInputBlock will be set
8181
// If there are no relative lock times, the LockPoints don't depend on the chain
82-
if (lp->maxInputBlock) {
82+
if (lp.maxInputBlock) {
8383
// Check whether active_chain is an extension of the block at which the LockPoints
8484
// calculation was valid. If not LockPoints are no longer valid
85-
if (!active_chain.Contains(lp->maxInputBlock)) {
85+
if (!active_chain.Contains(lp.maxInputBlock)) {
8686
return false;
8787
}
8888
}
@@ -649,8 +649,8 @@ void CTxMemPool::removeForReorg(CChain& chain, std::function<bool(txiter)> check
649649
}
650650
RemoveStaged(setAllRemoves, false, MemPoolRemovalReason::REORG);
651651
for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
652-
LockPoints lp = it->GetLockPoints();
653-
if (!TestLockPointValidity(chain, &lp)) {
652+
const LockPoints lp{it->GetLockPoints()};
653+
if (!TestLockPointValidity(chain, lp)) {
654654
mapTx.modify(it, update_lock_points(lp));
655655
}
656656
}

src/txmempool.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <utility>
1515
#include <vector>
1616

17-
#include <chain.h>
1817
#include <coins.h>
1918
#include <consensus/amount.h>
2019
#include <indirectmap.h>
@@ -26,12 +25,13 @@
2625
#include <util/epochguard.h>
2726
#include <util/hasher.h>
2827

29-
#include <boost/multi_index_container.hpp>
3028
#include <boost/multi_index/hashed_index.hpp>
3129
#include <boost/multi_index/ordered_index.hpp>
3230
#include <boost/multi_index/sequenced_index.hpp>
31+
#include <boost/multi_index_container.hpp>
3332

3433
class CBlockIndex;
34+
class CChain;
3535
class CChainState;
3636
extern RecursiveMutex cs_main;
3737

@@ -53,7 +53,7 @@ struct LockPoints {
5353
/**
5454
* Test whether the LockPoints height and time are still valid on the current chain
5555
*/
56-
bool TestLockPointValidity(CChain& active_chain, const LockPoints* lp) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
56+
bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
5757

5858
struct CompareIteratorByHash {
5959
// SFINAE for T where T is either a pointer type (e.g., a txiter) or a reference_wrapper<T>

src/validation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ void CChainState::MaybeUpdateMempoolForReorg(
357357
AssertLockHeld(::cs_main);
358358
const CTransaction& tx = it->GetTx();
359359
LockPoints lp = it->GetLockPoints();
360-
bool validLP = TestLockPointValidity(m_chain, &lp);
360+
const bool validLP{TestLockPointValidity(m_chain, lp)};
361361
CCoinsViewMemPool view_mempool(&CoinsTip(), *m_mempool);
362362
if (!CheckFinalTx(m_chain.Tip(), tx, flags)
363363
|| !CheckSequenceLocks(m_chain.Tip(), view_mempool, tx, flags, &lp, validLP)) {
@@ -371,8 +371,8 @@ void CChainState::MaybeUpdateMempoolForReorg(
371371
continue;
372372
const Coin &coin = CoinsTip().AccessCoin(txin.prevout);
373373
assert(!coin.IsSpent());
374-
unsigned int nMemPoolHeight = m_chain.Tip()->nHeight + 1;
375-
if (coin.IsSpent() || (coin.IsCoinBase() && ((signed long)nMemPoolHeight) - coin.nHeight < COINBASE_MATURITY)) {
374+
const auto mempool_spend_height{m_chain.Tip()->nHeight + 1};
375+
if (coin.IsSpent() || (coin.IsCoinBase() && mempool_spend_height - coin.nHeight < COINBASE_MATURITY)) {
376376
should_remove = true;
377377
break;
378378
}

0 commit comments

Comments
 (0)