Skip to content

Commit bedf246

Browse files
committed
[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.
1 parent 1b3a11e commit bedf246

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/txmempool.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ void CTxMemPool::removeForReorg(CChainState& active_chainstate, int flags)
642642
for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
643643
const CTransaction& tx = it->GetTx();
644644
LockPoints lp = it->GetLockPoints();
645-
bool validLP = TestLockPointValidity(active_chainstate.m_chain, &lp);
645+
const bool validLP = TestLockPointValidity(active_chainstate.m_chain, &lp);
646646
CCoinsViewMemPool view_mempool(&active_chainstate.CoinsTip(), *this);
647647
if (!CheckFinalTx(active_chainstate.m_chain.Tip(), tx, flags)
648648
|| !CheckSequenceLocks(active_chainstate.m_chain.Tip(), view_mempool, tx, flags, &lp, validLP)) {
@@ -663,15 +663,19 @@ void CTxMemPool::removeForReorg(CChainState& active_chainstate, int flags)
663663
}
664664
}
665665
}
666-
if (!validLP) {
667-
mapTx.modify(it, update_lock_points(lp));
668-
}
669666
}
670667
setEntries setAllRemoves;
671668
for (txiter it : txToRemove) {
672669
CalculateDescendants(it, setAllRemoves);
673670
}
674671
RemoveStaged(setAllRemoves, false, MemPoolRemovalReason::REORG);
672+
auto chain = active_chainstate.m_chain;
673+
for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
674+
LockPoints lp = it->GetLockPoints();
675+
if (!TestLockPointValidity(chain, &lp)) {
676+
mapTx.modify(it, update_lock_points(lp));
677+
}
678+
}
675679
}
676680

677681
void CTxMemPool::removeConflicts(const CTransaction &tx)

0 commit comments

Comments
 (0)