@@ -821,6 +821,11 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
821
821
return state.Invalid (TxValidationResult::TX_MEMPOOL_POLICY,
822
822
" too many potential replacements" , *err_string);
823
823
}
824
+ // Enforce Rule #2.
825
+ if (const auto err_string{HasNoNewUnconfirmed (tx, m_pool, setIterConflicting)}) {
826
+ return state.Invalid (TxValidationResult::TX_MEMPOOL_POLICY,
827
+ " replacement-adds-unconfirmed" , *err_string);
828
+ }
824
829
825
830
// Check if it's economically rational to mine this transaction rather
826
831
// than the ones it replaces.
@@ -829,38 +834,6 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
829
834
nConflictingSize += it->GetTxSize ();
830
835
}
831
836
832
- std::set<uint256> setConflictsParents;
833
- for (const auto & mi : setIterConflicting) {
834
- for (const CTxIn &txin : mi->GetTx ().vin )
835
- {
836
- setConflictsParents.insert (txin.prevout .hash );
837
- }
838
- }
839
-
840
- for (unsigned int j = 0 ; j < tx.vin .size (); j++)
841
- {
842
- // We don't want to accept replacements that require low
843
- // feerate junk to be mined first. Ideally we'd keep track of
844
- // the ancestor feerates and make the decision based on that,
845
- // but for now requiring all new inputs to be confirmed works.
846
- //
847
- // Note that if you relax this to make RBF a little more useful,
848
- // this may break the CalculateMempoolAncestors RBF relaxation,
849
- // above. See the comment above the first CalculateMempoolAncestors
850
- // call for more info.
851
- if (!setConflictsParents.count (tx.vin [j].prevout .hash ))
852
- {
853
- // Rather than check the UTXO set - potentially expensive -
854
- // it's cheaper to just check if the new input refers to a
855
- // tx that's in the mempool.
856
- if (m_pool.exists (tx.vin [j].prevout .hash )) {
857
- return state.Invalid (TxValidationResult::TX_MEMPOOL_POLICY, " replacement-adds-unconfirmed" ,
858
- strprintf (" replacement %s adds unconfirmed input, idx %d" ,
859
- hash.ToString (), j));
860
- }
861
- }
862
- }
863
-
864
837
// The replacement must pay greater fees than the transactions it
865
838
// replaces - if we did the bandwidth used by those conflicting
866
839
// transactions would not be paid for.
0 commit comments