@@ -609,17 +609,55 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
609
609
REJECT_HIGHFEE, " absurdly-high-fee" ,
610
610
strprintf (" %d > %d" , nFees, nAbsurdFee));
611
611
612
+ const CTxMemPool::setEntries setIterConflicting = pool.GetIterSet (setConflicts);
612
613
// Calculate in-mempool ancestors, up to a limit.
613
614
CTxMemPool::setEntries setAncestors;
614
615
size_t nLimitAncestors = gArgs .GetArg (" -limitancestorcount" , DEFAULT_ANCESTOR_LIMIT);
615
616
size_t nLimitAncestorSize = gArgs .GetArg (" -limitancestorsize" , DEFAULT_ANCESTOR_SIZE_LIMIT)*1000 ;
616
617
size_t nLimitDescendants = gArgs .GetArg (" -limitdescendantcount" , DEFAULT_DESCENDANT_LIMIT);
617
618
size_t nLimitDescendantSize = gArgs .GetArg (" -limitdescendantsize" , DEFAULT_DESCENDANT_SIZE_LIMIT)*1000 ;
619
+
620
+ if (setConflicts.size () == 1 ) {
621
+ // In general, when we receive an RBF transaction with mempool conflicts, we want to know whether we
622
+ // would meet the chain limits after the conflicts have been removed. However, there isn't a practical
623
+ // way to do this short of calculating the ancestor and descendant sets with an overlay cache of
624
+ // changed mempool entries. Due to both implementation and runtime complexity concerns, this isn't
625
+ // very realistic, thus we only ensure a limited set of transactions are RBF'able despite mempool
626
+ // conflicts here. Importantly, we need to ensure that some transactions which were accepted using
627
+ // the below carve-out are able to be RBF'ed, without impacting the security the carve-out provides
628
+ // for off-chain contract systems (see link in the comment below).
629
+ //
630
+ // Specifically, the subset of RBF transactions which we allow despite chain limits are those which
631
+ // conflict directly with exactly one other transaction (but may evict children of said transaction),
632
+ // and which are not adding any new mempool dependencies. Note that the "no new mempool dependencies"
633
+ // check is accomplished later, so we don't bother doing anything about it here, but if BIP 125 is
634
+ // amended, we may need to move that check to here instead of removing it wholesale.
635
+ //
636
+ // Such transactions are clearly not merging any existing packages, so we are only concerned with
637
+ // ensuring that (a) no package is growing past the package size (not count) limits and (b) we are
638
+ // not allowing something to effectively use the (below) carve-out spot when it shouldn't be allowed
639
+ // to.
640
+ //
641
+ // To check these we first check if we meet the RBF criteria, above, and increment the descendant
642
+ // limits by the direct conflict and its descendants (as these are recalculated in
643
+ // CalculateMempoolAncestors by assuming the new transaction being added is a new descendant, with no
644
+ // removals, of each parent's existing dependant set). The ancestor count limits are unmodified (as
645
+ // the ancestor limits should be the same for both our new transaction and any conflicts).
646
+ // We don't bother incrementing nLimitDescendants by the full removal count as that limit never comes
647
+ // into force here (as we're only adding a single transaction).
648
+ assert (setIterConflicting.size () == 1 );
649
+ CTxMemPool::txiter conflict = *setIterConflicting.begin ();
650
+
651
+ nLimitDescendants += 1 ;
652
+ nLimitDescendantSize += conflict->GetSizeWithDescendants ();
653
+ }
654
+
618
655
std::string errString;
619
656
if (!pool.CalculateMemPoolAncestors (entry, setAncestors, nLimitAncestors, nLimitAncestorSize, nLimitDescendants, nLimitDescendantSize, errString)) {
620
657
setAncestors.clear ();
621
658
// If CalculateMemPoolAncestors fails second time, we want the original error string.
622
659
std::string dummy_err_string;
660
+ // Contracting/payment channels CPFP carve-out:
623
661
// If the new transaction is relatively small (up to 40k weight)
624
662
// and has at most one ancestor (ie ancestor limit of 2, including
625
663
// the new transaction), allow it if its parent has exactly the
@@ -668,7 +706,6 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
668
706
CFeeRate newFeeRate (nModifiedFees, nSize);
669
707
std::set<uint256> setConflictsParents;
670
708
const int maxDescendantsToVisit = 100 ;
671
- const CTxMemPool::setEntries setIterConflicting = pool.GetIterSet (setConflicts);
672
709
for (const auto & mi : setIterConflicting) {
673
710
// Don't allow the replacement to reduce the feerate of the
674
711
// mempool.
@@ -728,6 +765,11 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
728
765
// feerate junk to be mined first. Ideally we'd keep track of
729
766
// the ancestor feerates and make the decision based on that,
730
767
// but for now requiring all new inputs to be confirmed works.
768
+ //
769
+ // Note that if you relax this to make RBF a little more useful,
770
+ // this may break the CalculateMempoolAncestors RBF relaxation,
771
+ // above. See the comment above the first CalculateMempoolAncestors
772
+ // call for more info.
731
773
if (!setConflictsParents.count (tx.vin [j].prevout .hash ))
732
774
{
733
775
// Rather than check the UTXO set - potentially expensive -
0 commit comments