From bedf246f1e2497a3641093c6e8fa11fb34dddac4 Mon Sep 17 00:00:00 2001 From: glozow Date: Tue, 30 Nov 2021 11:15:58 +0000 Subject: [mempool] only update lockpoints for non-removed entries Each entry's lockpoints are independent of one another, so there isn't any reason to update lockpoints for entries that will be removed. Separating the loops also allows us to move validation logic out and leave lockpoints in txmempool. --- src/txmempool.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 05b22bb39b..4cde0993a8 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -642,7 +642,7 @@ void CTxMemPool::removeForReorg(CChainState& active_chainstate, int flags) for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) { const CTransaction& tx = it->GetTx(); LockPoints lp = it->GetLockPoints(); - bool validLP = TestLockPointValidity(active_chainstate.m_chain, &lp); + const bool validLP = TestLockPointValidity(active_chainstate.m_chain, &lp); CCoinsViewMemPool view_mempool(&active_chainstate.CoinsTip(), *this); if (!CheckFinalTx(active_chainstate.m_chain.Tip(), tx, flags) || !CheckSequenceLocks(active_chainstate.m_chain.Tip(), view_mempool, tx, flags, &lp, validLP)) { @@ -663,15 +663,19 @@ void CTxMemPool::removeForReorg(CChainState& active_chainstate, int flags) } } } - if (!validLP) { - mapTx.modify(it, update_lock_points(lp)); - } } setEntries setAllRemoves; for (txiter it : txToRemove) { CalculateDescendants(it, setAllRemoves); } RemoveStaged(setAllRemoves, false, MemPoolRemovalReason::REORG); + auto chain = active_chainstate.m_chain; + for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) { + LockPoints lp = it->GetLockPoints(); + if (!TestLockPointValidity(chain, &lp)) { + mapTx.modify(it, update_lock_points(lp)); + } + } } void CTxMemPool::removeConflicts(const CTransaction &tx) -- cgit v1.2.3