@@ -782,9 +782,6 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
782
782
}
783
783
}
784
784
785
- // Check if it's economically rational to mine this transaction rather
786
- // than the ones it replaces.
787
- uint64_t nConflictingCount = 0 ;
788
785
789
786
// If we don't hold the lock allConflicting might be incomplete; the
790
787
// subsequent RemoveStaged() and addUnchecked() calls don't guarantee
@@ -793,7 +790,6 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
793
790
if (fReplacementTransaction )
794
791
{
795
792
CFeeRate newFeeRate (nModifiedFees, nSize);
796
- std::set<uint256> setConflictsParents;
797
793
for (const auto & mi : setIterConflicting) {
798
794
// Don't allow the replacement to reduce the feerate of the
799
795
// mempool.
@@ -818,33 +814,40 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
818
814
newFeeRate.ToString (),
819
815
oldFeeRate.ToString ()));
820
816
}
817
+ }
818
+
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);
837
+ }
838
+ // Check if it's economically rational to mine this transaction rather
839
+ // than the ones it replaces.
840
+ for (CTxMemPool::txiter it : allConflicting) {
841
+ nConflictingFees += it->GetModifiedFee ();
842
+ nConflictingSize += it->GetTxSize ();
843
+ }
821
844
845
+ std::set<uint256> setConflictsParents;
846
+ for (const auto & mi : setIterConflicting) {
822
847
for (const CTxIn &txin : mi->GetTx ().vin )
823
848
{
824
849
setConflictsParents.insert (txin.prevout .hash );
825
850
}
826
-
827
- nConflictingCount += mi->GetCountWithDescendants ();
828
- }
829
- // This potentially overestimates the number of actual descendants
830
- // but we just want to be conservative to avoid doing too much
831
- // work.
832
- if (nConflictingCount <= MAX_BIP125_REPLACEMENT_CANDIDATES) {
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);
837
- }
838
- for (CTxMemPool::txiter it : allConflicting) {
839
- nConflictingFees += it->GetModifiedFee ();
840
- nConflictingSize += it->GetTxSize ();
841
- }
842
- } else {
843
- return state.Invalid (TxValidationResult::TX_MEMPOOL_POLICY, " too many potential replacements" ,
844
- strprintf (" rejecting replacement %s; too many potential replacements (%d > %d)\n " ,
845
- hash.ToString (),
846
- nConflictingCount,
847
- MAX_BIP125_REPLACEMENT_CANDIDATES));
848
851
}
849
852
850
853
for (unsigned int j = 0 ; j < tx.vin .size (); j++)
0 commit comments