From b01784f0270dc20f8076ea4e46203c97b40b93ef Mon Sep 17 00:00:00 2001 From: glozow Date: Thu, 2 Dec 2021 11:47:20 +0000 Subject: [PATCH 1/3] remove unnecessary casts and use braced initialization --- src/validation.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/validation.cpp b/src/validation.cpp index 6ed5e7a548c..1a4837839ee 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -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; } From c4efc4db5484910ac33ba41aa76f4e23639d6f33 Mon Sep 17 00:00:00 2001 From: glozow Date: Thu, 2 Dec 2021 11:51:21 +0000 Subject: [PATCH 2/3] change TestLockPointValidity to take a const reference The lockpoints are not changed in this function. There is no reason to pass a pointer. --- src/txmempool.cpp | 11 +++++------ src/txmempool.h | 2 +- src/validation.cpp | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 27fbb8acac7..b4ec9bd6791 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -73,16 +73,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 +648,8 @@ void CTxMemPool::removeForReorg(CChain& chain, std::function 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)); } } diff --git a/src/txmempool.h b/src/txmempool.h index c6e08a3ca57..6ba474e228b 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -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 diff --git a/src/validation.cpp b/src/validation.cpp index 1a4837839ee..b532888f373 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -357,7 +357,7 @@ void CChainState::MaybeUpdateMempoolForReorg( AssertLockHeld(::cs_main); const CTransaction& tx = it->GetTx(); LockPoints lp = it->GetLockPoints(); - const 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)) { From ddd74ff65c471c5c25815ac0643d16ea0d51f58f Mon Sep 17 00:00:00 2001 From: glozow Date: Thu, 2 Dec 2021 14:46:24 +0000 Subject: [PATCH 3/3] clean up txmempool includes --- src/txmempool.cpp | 1 + src/txmempool.h | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index b4ec9bd6791..fcfc27d38ee 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -5,6 +5,7 @@ #include +#include #include #include #include diff --git a/src/txmempool.h b/src/txmempool.h index 6ba474e228b..f87ecc9cd08 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -14,7 +14,6 @@ #include #include -#include #include #include #include @@ -26,12 +25,13 @@ #include #include -#include #include #include #include +#include class CBlockIndex; +class CChain; class CChainState; extern RecursiveMutex cs_main;