@@ -789,6 +789,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
789789 fReplacementTransaction = setConflicts.size ();
790790 if (fReplacementTransaction )
791791 {
792+ std::string err_string;
792793 CFeeRate newFeeRate (nModifiedFees, nSize);
793794 for (const auto & mi : setIterConflicting) {
794795 // Don't allow the replacement to reduce the feerate of the
@@ -816,25 +817,11 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
816817 }
817818 }
818819
819- uint64_t nConflictingCount = 0 ;
820- for (const auto & mi : setIterConflicting) {
821- nConflictingCount += mi->GetCountWithDescendants ();
822- // This potentially overestimates the number of actual descendants
823- // but we just want to be conservative to avoid doing too much
824- // work.
825- if (nConflictingCount > MAX_BIP125_REPLACEMENT_CANDIDATES ) {
826- return state.Invalid (TxValidationResult::TX_MEMPOOL_POLICY , " too many potential replacements" ,
827- strprintf (" rejecting replacement %s; too many potential replacements (%d > %d)\n " ,
828- hash.ToString (),
829- nConflictingCount,
830- MAX_BIP125_REPLACEMENT_CANDIDATES ));
831- }
832- }
833- // If not too many to replace, then calculate the set of
834- // transactions that would have to be evicted
835- for (CTxMemPool::txiter it : setIterConflicting) {
836- m_pool.CalculateDescendants (it, allConflicting);
820+ // Calculate all conflicting entries and enforce Rule #5.
821+ if (!GetEntriesForConflicts (tx, m_pool, setIterConflicting, allConflicting, err_string)) {
822+ return state.Invalid (TxValidationResult::TX_MEMPOOL_POLICY , " too many potential replacements" , err_string);
837823 }
824+
838825 // Check if it's economically rational to mine this transaction rather
839826 // than the ones it replaces.
840827 for (CTxMemPool::txiter it : allConflicting) {
0 commit comments