Skip to content

Commit 3d3e459

Browse files
committed
[validation] cache iterators to mempool conflicts
1 parent 36a8441 commit 3d3e459

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/validation.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ class MemPoolAccept
498498
struct Workspace {
499499
explicit Workspace(const CTransactionRef& ptx) : m_ptx(ptx), m_hash(ptx->GetHash()) {}
500500
std::set<uint256> m_conflicts;
501+
CTxMemPool::setEntries m_iters_conflicting;
501502
CTxMemPool::setEntries m_all_conflicting;
502503
CTxMemPool::setEntries m_ancestors;
503504
std::unique_ptr<CTxMemPoolEntry> m_entry;
@@ -745,7 +746,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
745746
// blocks
746747
if (!bypass_limits && !CheckFeeRate(ws.m_vsize, nModifiedFees, state)) return false;
747748

748-
const CTxMemPool::setEntries setIterConflicting = m_pool.GetIterSet(setConflicts);
749+
ws.m_iters_conflicting = m_pool.GetIterSet(setConflicts);
749750
// Calculate in-mempool ancestors, up to a limit.
750751
if (setConflicts.size() == 1) {
751752
// In general, when we receive an RBF transaction with mempool conflicts, we want to know whether we
@@ -775,8 +776,8 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
775776
// the ancestor limits should be the same for both our new transaction and any conflicts).
776777
// We don't bother incrementing m_limit_descendants by the full removal count as that limit never comes
777778
// into force here (as we're only adding a single transaction).
778-
assert(setIterConflicting.size() == 1);
779-
CTxMemPool::txiter conflict = *setIterConflicting.begin();
779+
assert(ws.m_iters_conflicting.size() == 1);
780+
CTxMemPool::txiter conflict = *ws.m_iters_conflicting.begin();
780781

781782
m_limit_descendants += 1;
782783
m_limit_descendant_size += conflict->GetSizeWithDescendants();
@@ -823,17 +824,17 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
823824
// more economically rational to mine. Before we go digging through the mempool for all
824825
// transactions that would need to be removed (direct conflicts and all descendants), check
825826
// that the replacement transaction pays more than its direct conflicts.
826-
if (const auto err_string{PaysMoreThanConflicts(setIterConflicting, newFeeRate, hash)}) {
827+
if (const auto err_string{PaysMoreThanConflicts(ws.m_iters_conflicting, newFeeRate, hash)}) {
827828
return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, "insufficient fee", *err_string);
828829
}
829830

830831
// Calculate all conflicting entries and enforce BIP125 Rule #5.
831-
if (const auto err_string{GetEntriesForConflicts(tx, m_pool, setIterConflicting, allConflicting)}) {
832+
if (const auto err_string{GetEntriesForConflicts(tx, m_pool, ws.m_iters_conflicting, allConflicting)}) {
832833
return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY,
833834
"too many potential replacements", *err_string);
834835
}
835836
// Enforce BIP125 Rule #2.
836-
if (const auto err_string{HasNoNewUnconfirmed(tx, m_pool, setIterConflicting)}) {
837+
if (const auto err_string{HasNoNewUnconfirmed(tx, m_pool, ws.m_iters_conflicting)}) {
837838
return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY,
838839
"replacement-adds-unconfirmed", *err_string);
839840
}

0 commit comments

Comments
 (0)