Return-Path: Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0B69FC000D for ; Thu, 23 Sep 2021 15:36:21 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id D6FF5606FF for ; Thu, 23 Sep 2021 15:36:20 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org X-Spam-Flag: NO X-Spam-Score: -2.098 X-Spam-Level: X-Spam-Status: No, score=-2.098 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BH8Vo1Kn_72y for ; Thu, 23 Sep 2021 15:36:15 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by smtp3.osuosl.org (Postfix) with ESMTPS id 05A9E606F3 for ; Thu, 23 Sep 2021 15:36:14 +0000 (UTC) Received: by mail-qk1-x732.google.com with SMTP id 138so23066391qko.10 for ; Thu, 23 Sep 2021 08:36:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WaeDr3Qhd6SbBVEAqCx6Ikx13C9Cd4pU27CR6VnJKSg=; b=o3IjJGrY4Mn9fuluG4jQqg4a7vAItMnvfK70lQBBPXZeja+BXvvVHoTwHWUQy3Y00T 0iFUFf5fCi0myhiXCbivsnFusEjMNdGWpvqUTcXcTkzUOKeYM3k7OAsNpO4Ytqy6mFEl YHK3ruDtq7hvHAIvLaOXVuDMy/YGYShy8Xx8qm7qYkx3FWGQt6GjxkA2xdGCNZNoleuJ XL+H7hZyptnZ4bya7zpXU/Rdmke9zx4JdcqdE9gZb9HwnPP8k9+wyAu26FkzdgcCePLk L0S3s7mtLz5hGrzIB95Os5znh2uHHo7a746MISTAYa/OKldRJEuD7Jj7U4S6JCtsgP6G PmtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WaeDr3Qhd6SbBVEAqCx6Ikx13C9Cd4pU27CR6VnJKSg=; b=NUfUn6+NsowtdVsTrEs+/N8hGYtz6+kHwNJbkdiA52Z/a+DVN+fhW1pGCvIPEOmDkG 98P96uLqF+Yxy9DuyP/D1pPICAj8ly5Go27emJXZ2LUKOqAfgiU4HP1Z215rg5rpzn9L zsNzbvS/y/1W4XB5z5iF3/2QLtIfuRleO9bnsQ1u4xzEsWc3BML5DrAM7zzx+/RbYb3l 8OKqhu23rW/N+cMitJ3WVstkBBjb22fl3vlkEiS1hc4nQl6CZHNsL+xaF294KGhuZNZc +4R7UF6EDNc9uI6RghgUbhsFEUS7Pp3iNLJZ+CeqWLX7ayVxxI3SYBdxtk3lPuwu6d4f PNMQ== X-Gm-Message-State: AOAM531ToMr4V1BOrsKzDDVasnWBEjkskZXFSSA47OOpWEuCNRX5KQqd /dNwVHsb05gOtXfFM4diA325uhcZBh66NZDWeCdiYBDNCM8= X-Google-Smtp-Source: ABdhPJxtRrF6zsYkZvRsxLyvGAKxGmMgrIKib8zIgJLm4AlXGksW4YjTz0kUO6RW7NUYgN4+4HN1wY+8YtgSNZ7mSpU= X-Received: by 2002:a25:af10:: with SMTP id a16mr6419870ybh.424.1632411373536; Thu, 23 Sep 2021 08:36:13 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Gloria Zhao Date: Thu, 23 Sep 2021 16:36:02 +0100 Message-ID: To: Antoine Riard Content-Type: multipart/alternative; boundary="0000000000000c080e05ccab6429" X-Mailman-Approved-At: Thu, 23 Sep 2021 16:24:18 +0000 Cc: Bitcoin Protocol Discussion Subject: Re: [bitcoin-dev] Proposal: Package Mempool Accept and Package RBF X-BeenThere: bitcoin-dev@lists.linuxfoundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Bitcoin Protocol Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Sep 2021 15:36:21 -0000 --0000000000000c080e05ccab6429 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Antoine, Thanks as always for your input. I'm glad we agree on so much! In summary, it seems that the decisions that might still need attention/input from devs on this mailing list are: 1. Whether we should start with multiple-parent-1-child or 1-parent-1-child= . 2. Whether it's ok to require that the child not have conflicts with mempool transactions. Responding to your comments... > IIUC, you have package A+B, during the dedup phase early in `AcceptMultipleTransactions` if you observe same-txid-different-wtixd A' and A' is higher feerate than A, you trim A and replace by A' ? > I think this approach is safe, the one who appears unsafe to me is when A' has a _lower_ feerate, even if A' is already accepted by our mempool ? In that case iirc that would be a pinning. Right, the fact that we essentially always choose the first-seen witness is an unfortunate limitation that exists already. Adding package mempool accept doesn't worsen this, but the procedure in the future is to replace the witness when it makes sense economically. We can also add logic to allow package feerate to pay for witness replacements as well. This is pretty far into the future, though. > It sounds uneconomical for an attacker but I think it's not when you consider than you can "batch" attack against multiple honest counterparties. E.g, Mallory broadcast A' + B' + C' + D' where A' conflicts with Alice's honest package P1, B' conflicts with Bob's honest package P2, C' conflicts with Caroll's honest package P3. And D' is a high-fee child of A' + B' + C'. > If D' is higher-fee than P1 or P2 or P3 but inferior to the sum of HTLCs confirmed by P1+P2+P3, I think it's lucrative for the attacker ? I could be misunderstanding, but an attacker wouldn't be able to batch-attack like this. Alice's package only conflicts with A' + D', not A' + B' + C' + D'. She only needs to pay for evicting 2 transactions. > Do we assume that broadcasted packages are "honest" by default and that the parent(s) always need the child to pass the fee checks, that way saving the processing of individual transactions which are expected to fail in 99% of cases or more ad hoc composition of packages at relay ? > I think this point is quite dependent on the p2p packages format/logic we'll end up on and that we should feel free to revisit it later ? I think it's the opposite; there's no way for us to assume that p2p packages will be "honest." I'd like to have two things before we expose on P2P: (1) ensure that the amount of resources potentially allocated for package validation isn't disproportionately higher than that of single transaction validation and (2) only use package validation when we're unsatisifed with the single validation result, e.g. we might get better fees. Yes, let's revisit this later :) > Yes, if you receive A+B, and A is already in-mempoo, I agree you can discard its feerate as B should pay for all fees checked on its own. Where I'm unclear is when you have in-mempool A+B and receive A+B'. Should B' have a fee high enough to cover the bandwidth penalty replacement (`PaysForRBF`, 2nd check) of both A+B' or only B' ? B' only needs to pay for itself in this case. > > Do we want the child to be able to replace mempool transactions as well= ? > If we mean when you have replaceable A+B then A'+B' try to replace with a higher-feerate ? I think that's exactly the case we need for Lightning as A+B is coming from Alice and A'+B' is coming from Bob :/ Let me clarify this because I can see that my wording was ambiguous, and then please let me know if it fits Lightning's needs? In my proposal, I wrote "If a package meets feerate requirements as a package, the parents in the transaction are allowed to replace-by-fee mempool transactions. The child cannot replace mempool transactions." What I meant was: the package can replace mempool transactions if any of the parents conflict with mempool transactions. The child cannot not conflict with any mempool transactions. The Lightning use case this attempts to address is: Alice and Mallory are LN counterparties, and have packages A+B and A'+B', respectively. A and A' are their commitment transactions and conflict with each other; they have shared inputs and different txids. B spends Alice's anchor output from A. B' spends Mallory's anchor output from A'. Thus, B and B' do not conflict with each other. Alice can broadcast her package, A+B, to replace Mallory's package, A'+B', since B doesn't conflict with the mempool. Would this be ok? > The second option, a child of A', In the LN case I think the CPFP is attached on one's anchor output. While it would be nice to have full RBF, malleability of the child won't block RBF here. If we're trying to replace A', we only require that A' signals replaceability, and don't mind if its child doesn't. > > B has an ancestor score of 10sat/vb and D has an > > ancestor score of ~2.9sat/vb. Since D's ancestor score is lower than B's, > > it fails the proposed package RBF Rule #2, so this package would be > > rejected. Does this meet your expectations? > Well what sounds odd to me, in my example, we fail D even if it has a higher-fee than B. Like A+B absolute fees are 2000 sats and A+C+D absolute fees are 4500 sats ? Yes, A+C+D pays 2500sat more in fees, but it is also 1000vB larger. A miner should prefer to utilize their block space more effectively. > Is this compatible with a model where a miner prioritizes absolute fees over ancestor score, in the case that mempools aren't full-enough to fulfill a block ? No, because we don't use that model. Thanks, Gloria On Thu, Sep 23, 2021 at 5:29 AM Antoine Riard wrote: > > Correct, if B+C is too low feerate to be accepted, we will reject it. I > > prefer this because it is incentive compatible: A can be mined by itsel= f, > > so there's no reason to prefer A+B+C instead of A. > > As another way of looking at this, consider the case where we do accept > > A+B+C and it sits at the "bottom" of our mempool. If our mempool reache= s > > capacity, we evict the lowest descendant feerate transactions, which ar= e > > B+C in this case. This gives us the same resulting mempool, with A and > not > > B+C. > > I agree here. Doing otherwise, we might evict other transactions mempool > in `MempoolAccept::Finalize` with a higher-feerate than B+C while those > evicted transactions are the most compelling for block construction. > > I thought at first missing this acceptance requirement would break a > fee-bumping scheme like Parent-Pay-For-Child where a high-fee parent is > attached to a child signed with SIGHASH_ANYONECANPAY but in this case the > child fee is capturing the parent value. I can't think of other fee-bumpi= ng > schemes potentially affected. If they do exist I would say they're wrong = in > their design assumptions. > > > If or when we have witness replacement, the logic is: if the individual > > transaction is enough to replace the mempool one, the replacement will > > happen during the preceding individual transaction acceptance, and > > deduplication logic will work. Otherwise, we will try to deduplicate by > > wtxid, see that we need a package witness replacement, and use the > package > > feerate to evaluate whether this is economically rational. > > IIUC, you have package A+B, during the dedup phase early in > `AcceptMultipleTransactions` if you observe same-txid-different-wtixd A' > and A' is higher feerate than A, you trim A and replace by A' ? > > I think this approach is safe, the one who appears unsafe to me is when A= ' > has a _lower_ feerate, even if A' is already accepted by our mempool ? In > that case iirc that would be a pinning. > > Good to see progress on witness replacement before we see usage of Taproo= t > tree in the context of multi-party, where a malicious counterparty inflat= es > its witness to jam a honest spending. > > (Note, the commit linked currently points nowhere :)) > > > > Please note that A may replace A' even if A' has higher fees than A > > individually, because the proposed package RBF utilizes the fees and si= ze > > of the entire package. This just requires E to pay enough fees, althoug= h > > this can be pretty high if there are also potential B' and C' competing > > commitment transactions that we don't know about. > > Ah right, if the package acceptance waives `PaysMoreThanConflicts` for th= e > individual check on A, the honest package should replace the pinning > attempt. I've not fully parsed the proposed implementation yet. > > Though note, I think it's still unsafe for a Lightning > multi-commitment-broadcast-as-one-package as a malicious A' might have an > absolute fee higher than E. It sounds uneconomical for > an attacker but I think it's not when you consider than you can "batch" > attack against multiple honest counterparties. E.g, Mallory broadcast A' = + > B' + C' + D' where A' conflicts with Alice's honest package P1, B' > conflicts with Bob's honest package P2, C' conflicts with Caroll's honest > package P3. And D' is a high-fee child of A' + B' + C'. > > If D' is higher-fee than P1 or P2 or P3 but inferior to the sum of HTLCs > confirmed by P1+P2+P3, I think it's lucrative for the attacker ? > > > So far, my understanding is that multi-parent-1-child is desired for > > batched fee-bumping ( > > https://github.com/bitcoin/bitcoin/pull/22674#issuecomment-897951289) > and > > I've also seen your response which I have less context on ( > > https://github.com/bitcoin/bitcoin/pull/22674#issuecomment-900352202). > That > > being said, I am happy to create a new proposal for 1 parent + 1 child > > (which would be slightly simpler) and plan for moving to > > multi-parent-1-child later if that is preferred. I am very interested i= n > > hearing feedback on that approach. > > I think batched fee-bumping is okay as long as you don't have > time-sensitive outputs encumbering your commitment transactions. For the > reasons mentioned above, I think that's unsafe. > > What I'm worried about is L2 developers, potentially not aware about all > the mempool subtleties blurring the difference and always batching their > broadcast by default. > > IMO, a good thing by restraining to 1-parent + 1 child, we artificially > constraint L2 design space for now and minimize risks of unsafe usage of > the package API :) > > I think that's a point where it would be relevant to have the opinion of > more L2 devs. > > > I think there is a misunderstanding here - let me describe what I'm > > proposing we'd do in this situation: we'll try individual submission fo= r > A, > > see that it fails due to "insufficient fees." Then, we'll try package > > validation for A+B and use package RBF. If A+B pays enough, it can stil= l > > replace A'. If A fails for a bad signature, we won't look at B or A+B. > Does > > this meet your expectations? > > Yes there was a misunderstanding, I think this approach is correct, it's > more a question of performance. Do we assume that broadcasted packages ar= e > "honest" by default and that the parent(s) always need the child to pass > the fee checks, that way saving the processing of individual transactions > which are expected to fail in 99% of cases or more ad hoc composition of > packages at relay ? > > I think this point is quite dependent on the p2p packages format/logic > we'll end up on and that we should feel free to revisit it later ? > > > > What problem are you trying to solve by the package feerate *after* ded= up > rule ? > > My understanding is that an in-package transaction might be already in > the mempool. Therefore, to compute a correct RBF penalty replacement, the > vsize of this transaction could be discarded lowering the cost of package > RBF. > > > I'm proposing that, when a transaction has already been submitted to > > mempool, we would ignore both its fees and vsize when calculating packa= ge > > feerate. > > Yes, if you receive A+B, and A is already in-mempoo, I agree you can > discard its feerate as B should pay for all fees checked on its own. Wher= e > I'm unclear is when you have in-mempool A+B and receive A+B'. Should B' > have a fee high enough to cover the bandwidth penalty replacement > (`PaysForRBF`, 2nd check) of both A+B' or only B' ? > > If you have a second-layer like current Lightning, you might have a > counterparty commitment to replace and should always expect to have to pa= y > for parent replacement bandwidth. > > Where a potential discount sounds interesting is when you have an univoqu= e > state on the first-stage of transactions. E.g DLC's funding transaction > which might be CPFP by any participant iirc. > > > Note that, if C' conflicts with C, it also conflicts with D, since D is= a > > descendant of C and would thus need to be evicted along with it. > > Ah once again I think it's a misunderstanding without the code under my > eyes! If we do C' `PreChecks`, solve the conflicts provoked by it, i.e ma= rk > for potential eviction D and don't consider it for future conflicts in th= e > rest of the package, I think D' `PreChecks` should be good ? > > > More generally, this example is surprising to me because I didn't think > > packages would be used to fee-bump replaceable transactions. Do we want > the > > child to be able to replace mempool transactions as well? > > If we mean when you have replaceable A+B then A'+B' try to replace with a > higher-feerate ? I think that's exactly the case we need for Lightning as > A+B is coming from Alice and A'+B' is coming from Bob :/ > > > I'm not sure what you mean? Let's say we have a package of parent A + > child > > B, where A is supposed to replace a mempool transaction A'. Are you > saying > > that counterparties are able to malleate the package child B, or a chil= d > of > > A'? > > The second option, a child of A', In the LN case I think the CPFP is > attached on one's anchor output. > > I think it's good if we assume the > solve-conflicts-after-parent's`'PreChecks` mentioned above or fixing > inherited signaling or full-rbf ? > > > Sorry, I don't understand what you mean by "preserve the package > > integrity?" Could you elaborate? > > After thinking the relaxation about the "new" unconfirmed input is not > linked to trimming but I would say more to the multi-parent support. > > Let's say you have A+B trying to replace C+D where B is also spending > already in-mempool E. To succeed, you need to waive the no-new-unconfirme= d > input as D isn't spending E. > > So good, I think we agree on the problem description here. > > > I am in agreement with your calculations but unsure if we disagree on t= he > > expected outcome. Yes, B has an ancestor score of 10sat/vb and D has an > > ancestor score of ~2.9sat/vb. Since D's ancestor score is lower than B'= s, > > it fails the proposed package RBF Rule #2, so this package would be > > rejected. Does this meet your expectations? > > Well what sounds odd to me, in my example, we fail D even if it has a > higher-fee than B. Like A+B absolute fees are 2000 sats and A+C+D absolut= e > fees are 4500 sats ? > > Is this compatible with a model where a miner prioritizes absolute fees > over ancestor score, in the case that mempools aren't full-enough to > fulfill a block ? > > Let me know if I can clarify a point. > > Antoine > > Le lun. 20 sept. 2021 =C3=A0 11:10, Gloria Zhao a > =C3=A9crit : > >> >> Hi Antoine, >> >> First of all, thank you for the thorough review. I appreciate your >> insight on LN requirements. >> >> > IIUC, you have a package A+B+C submitted for acceptance and A is >> already in your mempool. You trim out A from the package and then evalua= te >> B+C. >> >> > I think this might be an issue if A is the higher-fee element of the >> ABC package. B+C package fees might be under the mempool min fee and wil= l >> be rejected, potentially breaking the acceptance expectations of the >> package issuer ? >> >> Correct, if B+C is too low feerate to be accepted, we will reject it. I >> prefer this because it is incentive compatible: A can be mined by itself= , >> so there's no reason to prefer A+B+C instead of A. >> As another way of looking at this, consider the case where we do accept >> A+B+C and it sits at the "bottom" of our mempool. If our mempool reaches >> capacity, we evict the lowest descendant feerate transactions, which are >> B+C in this case. This gives us the same resulting mempool, with A and n= ot >> B+C. >> >> >> > Further, I think the dedup should be done on wtxid, as you might have >> multiple valid witnesses. Though with varying vsizes and as such offerin= g >> different feerates. >> >> I agree that variations of the same package with different witnesses is = a >> case that must be handled. I consider witness replacement to be a projec= t >> that can be done in parallel to package mempool acceptance because being >> able to accept packages does not worsen the problem of a >> same-txid-different-witness "pinning" attack. >> >> If or when we have witness replacement, the logic is: if the individual >> transaction is enough to replace the mempool one, the replacement will >> happen during the preceding individual transaction acceptance, and >> deduplication logic will work. Otherwise, we will try to deduplicate by >> wtxid, see that we need a package witness replacement, and use the packa= ge >> feerate to evaluate whether this is economically rational. >> >> See the #22290 "handle package transactions already in mempool" commit ( >> https://github.com/bitcoin/bitcoin/pull/22290/commits/fea75a2237b46cf761= 45242fecad7e274bfcb5ff), >> which handles the case of same-txid-different-witness by simply using th= e >> transaction in the mempool for now, with TODOs for what I just described= . >> >> >> > I'm not clearly understanding the accepted topologies. By "parent and >> child to share a parent", do you mean the set of transactions A, B, C, >> where B is spending A and C is spending A and B would be correct ? >> >> Yes, that is what I meant. Yes, that would a valid package under these >> rules. >> >> > If yes, is there a width-limit introduced or we fallback on >> MAX_PACKAGE_COUNT=3D25 ? >> >> No, there is no limit on connectivity other than "child with all >> unconfirmed parents." We will enforce MAX_PACKAGE_COUNT=3D25 and child's >> in-mempool + in-package ancestor limits. >> >> >> > Considering the current Core's mempool acceptance rules, I think CPFP >> batching is unsafe for LN time-sensitive closure. A malicious tx-relay >> jamming successful on one channel commitment transaction would contamine >> the remaining commitments sharing the same package. >> >> > E.g, you broadcast the package A+B+C+D+E where A,B,C,D are commitment >> transactions and E a shared CPFP. If a malicious A' transaction has a >> better feerate than A, the whole package acceptance will fail. Even if A= ' >> confirms in the following block, >> the propagation and confirmation of B+C+D have been delayed. This could >> carry on a loss of funds. >> >> Please note that A may replace A' even if A' has higher fees than A >> individually, because the proposed package RBF utilizes the fees and siz= e >> of the entire package. This just requires E to pay enough fees, although >> this can be pretty high if there are also potential B' and C' competing >> commitment transactions that we don't know about. >> >> >> > IMHO, I'm leaning towards deploying during a first phase >> 1-parent/1-child. I think it's the most conservative step still improvin= g >> second-layer safety. >> >> So far, my understanding is that multi-parent-1-child is desired for >> batched fee-bumping ( >> https://github.com/bitcoin/bitcoin/pull/22674#issuecomment-897951289) >> and I've also seen your response which I have less context on ( >> https://github.com/bitcoin/bitcoin/pull/22674#issuecomment-900352202). >> That being said, I am happy to create a new proposal for 1 parent + 1 ch= ild >> (which would be slightly simpler) and plan for moving to >> multi-parent-1-child later if that is preferred. I am very interested in >> hearing feedback on that approach. >> >> >> > If A+B is submitted to replace A', where A pays 0 sats, B pays 200 sat= s >> and A' pays 100 sats. If we apply the individual RBF on A, A+B acceptanc= e >> fails. For this reason I think the individual RBF should be bypassed and >> only the package RBF apply ? >> >> I think there is a misunderstanding here - let me describe what I'm >> proposing we'd do in this situation: we'll try individual submission for= A, >> see that it fails due to "insufficient fees." Then, we'll try package >> validation for A+B and use package RBF. If A+B pays enough, it can still >> replace A'. If A fails for a bad signature, we won't look at B or A+B. D= oes >> this meet your expectations? >> >> >> > What problem are you trying to solve by the package feerate *after* >> dedup rule ? >> > My understanding is that an in-package transaction might be already in >> the mempool. Therefore, to compute a correct RBF penalty replacement, th= e >> vsize of this transaction could be discarded lowering the cost of packag= e >> RBF. >> >> I'm proposing that, when a transaction has already been submitted to >> mempool, we would ignore both its fees and vsize when calculating packag= e >> feerate. In example G2, we shouldn't count M1 fees after its submission = to >> mempool, since M1's fees have already been used to pay for its individua= l >> bandwidth, and it shouldn't be used again to pay for P2 and P3's bandwid= th. >> We also shouldn't count its vsize, since it has already been paid for. >> >> >> > I think this is a footgunish API, as if a package issuer send the >> multiple-parent-one-child package A,B,C,D where D is the child of A,B,C. >> Then try to broadcast the higher-feerate C'+D' package, it should be >> rejected. So it's breaking the naive broadcaster assumption that a >> higher-feerate/higher-fee package always replaces ? >> >> Note that, if C' conflicts with C, it also conflicts with D, since D is = a >> descendant of C and would thus need to be evicted along with it. >> Implicitly, D' would not be in conflict with D. >> More generally, this example is surprising to me because I didn't think >> packages would be used to fee-bump replaceable transactions. Do we want = the >> child to be able to replace mempool transactions as well? This can be >> implemented with a bit of additional logic. >> >> > I think this is unsafe for L2s if counterparties have malleability of >> the child transaction. They can block your package replacement by >> opting-out from RBF signaling. IIRC, LN's "anchor output" presents such = an >> ability. >> >> I'm not sure what you mean? Let's say we have a package of parent A + >> child B, where A is supposed to replace a mempool transaction A'. Are yo= u >> saying that counterparties are able to malleate the package child B, or = a >> child of A'? If they can malleate a child of A', that shouldn't matter a= s >> long as A' is signaling replacement. This would be handled identically w= ith >> full RBF and what Core currently implements. >> >> > I think this is an issue brought by the trimming during the dedup >> phase. If we preserve the package integrity, only re-using the tx-level >> checks results of already in-mempool transactions to gain in CPU time we >> won't have this issue. Package childs can add unconfirmed inputs as long= as >> they're in-package, the bip125 rule2 is only evaluated against parents ? >> >> Sorry, I don't understand what you mean by "preserve the package >> integrity?" Could you elaborate? >> >> > Let's say you have in-mempool A, B where A pays 10 sat/vb for 100 >> vbytes and B pays 10 sat/vb for 100 vbytes. You have the candidate >> replacement D spending both A and C where D pays 15sat/vb for 100 vbytes >> and C pays 1 sat/vb for 1000 vbytes. >> >> > Package A + B ancestor score is 10 sat/vb. >> >> > D has a higher feerate/absolute fee than B. >> >> > Package A + C + D ancestor score is ~ 3 sat/vb ((A's 1000 sats + C's >> 1000 sats + D's 1500 sats) / A's 100 vb + C's 1000 vb + D's 100 vb) >> >> I am in agreement with your calculations but unsure if we disagree on th= e >> expected outcome. Yes, B has an ancestor score of 10sat/vb and D has an >> ancestor score of ~2.9sat/vb. Since D's ancestor score is lower than B's= , >> it fails the proposed package RBF Rule #2, so this package would be >> rejected. Does this meet your expectations? >> >> Thank you for linking to projects that might be interested in package >> relay :) >> >> Thanks, >> Gloria >> >> On Mon, Sep 20, 2021 at 12:16 AM Antoine Riard >> wrote: >> >>> Hi Gloria, >>> >>> > A package may contain transactions that are already in the mempool. W= e >>> > remove >>> > ("deduplicate") those transactions from the package for the purposes = of >>> > package >>> > mempool acceptance. If a package is empty after deduplication, we do >>> > nothing. >>> >>> IIUC, you have a package A+B+C submitted for acceptance and A is alread= y >>> in your mempool. You trim out A from the package and then evaluate B+C. >>> >>> I think this might be an issue if A is the higher-fee element of the AB= C >>> package. B+C package fees might be under the mempool min fee and will b= e >>> rejected, potentially breaking the acceptance expectations of the packa= ge >>> issuer ? >>> >>> Further, I think the dedup should be done on wtxid, as you might have >>> multiple valid witnesses. Though with varying vsizes and as such offeri= ng >>> different feerates. >>> >>> E.g you're going to evaluate the package A+B and A' is already in your >>> mempool with a bigger valid witness. You trim A based on txid, then you >>> evaluate A'+B, which fails the fee checks. However, evaluating A+B woul= d >>> have been a success. >>> >>> AFAICT, the dedup rationale would be to save on CPU time/IO disk, to >>> avoid repeated signatures verification and parent UTXOs fetches ? Can w= e >>> achieve the same goal by bypassing tx-level checks for already-in txn w= hile >>> conserving the package integrity for package-level checks ? >>> >>> > Note that it's possible for the parents to be >>> > indirect >>> > descendants/ancestors of one another, or for parent and child to shar= e >>> a >>> > parent, >>> > so we cannot make any other topology assumptions. >>> >>> I'm not clearly understanding the accepted topologies. By "parent and >>> child to share a parent", do you mean the set of transactions A, B, C, >>> where B is spending A and C is spending A and B would be correct ? >>> >>> If yes, is there a width-limit introduced or we fallback on >>> MAX_PACKAGE_COUNT=3D25 ? >>> >>> IIRC, one rationale to come with this topology limitation was to lower >>> the DoS risks when potentially deploying p2p packages. >>> >>> Considering the current Core's mempool acceptance rules, I think CPFP >>> batching is unsafe for LN time-sensitive closure. A malicious tx-relay >>> jamming successful on one channel commitment transaction would contamin= e >>> the remaining commitments sharing the same package. >>> >>> E.g, you broadcast the package A+B+C+D+E where A,B,C,D are commitment >>> transactions and E a shared CPFP. If a malicious A' transaction has a >>> better feerate than A, the whole package acceptance will fail. Even if = A' >>> confirms in the following block, >>> the propagation and confirmation of B+C+D have been delayed. This could >>> carry on a loss of funds. >>> >>> That said, if you're broadcasting commitment transactions without >>> time-sensitive HTLC outputs, I think the batching is effectively a fee >>> saving as you don't have to duplicate the CPFP. >>> >>> IMHO, I'm leaning towards deploying during a first phase >>> 1-parent/1-child. I think it's the most conservative step still improvi= ng >>> second-layer safety. >>> >>> > *Rationale*: It would be incorrect to use the fees of transactions >>> that are >>> > already in the mempool, as we do not want a transaction's fees to be >>> > double-counted for both its individual RBF and package RBF. >>> >>> I'm unsure about the logical order of the checks proposed. >>> >>> If A+B is submitted to replace A', where A pays 0 sats, B pays 200 sats >>> and A' pays 100 sats. If we apply the individual RBF on A, A+B acceptan= ce >>> fails. For this reason I think the individual RBF should be bypassed an= d >>> only the package RBF apply ? >>> >>> Note this situation is plausible, with current LN design, your >>> counterparty can have a commitment transaction with a better fee just b= y >>> selecting a higher `dust_limit_satoshis` than yours. >>> >>> > Examples F and G [14] show the same package, but P1 is submitted >>> > individually before >>> > the package in example G. In example F, we can see that the 300vB >>> package >>> > pays >>> > an additional 200sat in fees, which is not enough to pay for its own >>> > bandwidth >>> > (BIP125#4). In example G, we can see that P1 pays enough to replace >>> M1, but >>> > using P1's fees again during package submission would make it look >>> like a >>> > 300sat >>> > increase for a 200vB package. Even including its fees and size would >>> not be >>> > sufficient in this example, since the 300sat looks like enough for th= e >>> 300vB >>> > package. The calculcation after deduplication is 100sat increase for = a >>> > package >>> > of size 200vB, which correctly fails BIP125#4. Assume all transaction= s >>> have >>> > a >>> > size of 100vB. >>> >>> What problem are you trying to solve by the package feerate *after* >>> dedup rule ? >>> >>> My understanding is that an in-package transaction might be already in >>> the mempool. Therefore, to compute a correct RBF penalty replacement, t= he >>> vsize of this transaction could be discarded lowering the cost of packa= ge >>> RBF. >>> >>> If we keep a "safe" dedup mechanism (see my point above), I think this >>> discount is justified, as the validation cost of node operators is paid= for >>> ? >>> >>> > The child cannot replace mempool transactions. >>> >>> Let's say you issue package A+B, then package C+B', where B' is a child >>> of both A and C. This rule fails the acceptance of C+B' ? >>> >>> I think this is a footgunish API, as if a package issuer send the >>> multiple-parent-one-child package A,B,C,D where D is the child of A,B,C= . >>> Then try to broadcast the higher-feerate C'+D' package, it should be >>> rejected. So it's breaking the naive broadcaster assumption that a >>> higher-feerate/higher-fee package always replaces ? And it might be uns= afe >>> in protocols where states are symmetric. E.g a malicious counterparty >>> broadcasts first S+A, then you honestly broadcast S+B, where B pays bet= ter >>> fees. >>> >>> > All mempool transactions to be replaced must signal replaceability. >>> >>> I think this is unsafe for L2s if counterparties have malleability of >>> the child transaction. They can block your package replacement by >>> opting-out from RBF signaling. IIRC, LN's "anchor output" presents such= an >>> ability. >>> >>> I think it's better to either fix inherited signaling or move towards >>> full-rbf. >>> >>> > if a package parent has already been submitted, it would >>> > look >>> >like the child is spending a "new" unconfirmed input. >>> >>> I think this is an issue brought by the trimming during the dedup phase= . >>> If we preserve the package integrity, only re-using the tx-level checks >>> results of already in-mempool transactions to gain in CPU time we won't >>> have this issue. Package childs can add unconfirmed inputs as long as >>> they're in-package, the bip125 rule2 is only evaluated against parents = ? >>> >>> > However, we still achieve the same goal of requiring the >>> > replacement >>> > transactions to have a ancestor score at least as high as the origina= l >>> > ones. >>> >>> I'm not sure if this holds... >>> >>> Let's say you have in-mempool A, B where A pays 10 sat/vb for 100 vbyte= s >>> and B pays 10 sat/vb for 100 vbytes. You have the candidate replacement= D >>> spending both A and C where D pays 15sat/vb for 100 vbytes and C pays 1 >>> sat/vb for 1000 vbytes. >>> >>> Package A + B ancestor score is 10 sat/vb. >>> >>> D has a higher feerate/absolute fee than B. >>> >>> Package A + C + D ancestor score is ~ 3 sat/vb ((A's 1000 sats + C's >>> 1000 sats + D's 1500 sats) / >>> A's 100 vb + C's 1000 vb + D's 100 vb) >>> >>> Overall, this is a review through the lenses of LN requirements. I thin= k >>> other L2 protocols/applications >>> could be candidates to using package accept/relay such as: >>> * https://github.com/lightninglabs/pool >>> * https://github.com/discreetlogcontracts/dlcspecs >>> * https://github.com/bitcoin-teleport/teleport-transactions/ >>> * https://github.com/sapio-lang/sapio >>> * >>> https://github.com/commerceblock/mercury/blob/master/doc/statechains.md >>> * https://github.com/revault/practical-revault >>> >>> Thanks for rolling forward the ball on this subject. >>> >>> Antoine >>> >>> Le jeu. 16 sept. 2021 =C3=A0 03:55, Gloria Zhao via bitcoin-dev < >>> bitcoin-dev@lists.linuxfoundation.org> a =C3=A9crit : >>> >>>> Hi there, >>>> >>>> I'm writing to propose a set of mempool policy changes to enable packa= ge >>>> validation (in preparation for package relay) in Bitcoin Core. These >>>> would not >>>> be consensus or P2P protocol changes. However, since mempool policy >>>> significantly affects transaction propagation, I believe this is >>>> relevant for >>>> the mailing list. >>>> >>>> My proposal enables packages consisting of multiple parents and 1 >>>> child. If you >>>> develop software that relies on specific transaction relay assumptions >>>> and/or >>>> are interested in using package relay in the future, I'm very >>>> interested to hear >>>> your feedback on the utility or restrictiveness of these package >>>> policies for >>>> your use cases. >>>> >>>> A draft implementation of this proposal can be found in [Bitcoin Core >>>> PR#22290][1]. >>>> >>>> An illustrated version of this post can be found at >>>> https://gist.github.com/glozow/dc4e9d5c5b14ade7cdfac40f43adb18a. >>>> I have also linked the images below. >>>> >>>> ## Background >>>> >>>> Feel free to skip this section if you are already familiar with mempoo= l >>>> policy >>>> and package relay terminology. >>>> >>>> ### Terminology Clarifications >>>> >>>> * Package =3D an ordered list of related transactions, representable b= y a >>>> Directed >>>> Acyclic Graph. >>>> * Package Feerate =3D the total modified fees divided by the total >>>> virtual size of >>>> all transactions in the package. >>>> - Modified fees =3D a transaction's base fees + fee delta applied = by >>>> the user >>>> with `prioritisetransaction`. As such, we expect this to vary >>>> across >>>> mempools. >>>> - Virtual Size =3D the maximum of virtual sizes calculated using >>>> [BIP141 >>>> virtual size][2] and sigop weight. [Implemented here in Bitcoin >>>> Core][3]. >>>> - Note that feerate is not necessarily based on the base fees and >>>> serialized >>>> size. >>>> >>>> * Fee-Bumping =3D user/wallet actions that take advantage of miner >>>> incentives to >>>> boost a transaction's candidacy for inclusion in a block, including >>>> Child Pays >>>> for Parent (CPFP) and [BIP125][12] Replace-by-Fee (RBF). Our intention >>>> in >>>> mempool policy is to recognize when the new transaction is more >>>> economical to >>>> mine than the original one(s) but not open DoS vectors, so there are >>>> some >>>> limitations. >>>> >>>> ### Policy >>>> >>>> The purpose of the mempool is to store the best (to be most >>>> incentive-compatible >>>> with miners, highest feerate) candidates for inclusion in a block. >>>> Miners use >>>> the mempool to build block templates. The mempool is also useful as a >>>> cache for >>>> boosting block relay and validation performance, aiding transaction >>>> relay, and >>>> generating feerate estimations. >>>> >>>> Ideally, all consensus-valid transactions paying reasonable fees shoul= d >>>> make it >>>> to miners through normal transaction relay, without any special >>>> connectivity or >>>> relationships with miners. On the other hand, nodes do not have >>>> unlimited >>>> resources, and a P2P network designed to let any honest node broadcast >>>> their >>>> transactions also exposes the transaction validation engine to DoS >>>> attacks from >>>> malicious peers. >>>> >>>> As such, for unconfirmed transactions we are considering for our >>>> mempool, we >>>> apply a set of validation rules in addition to consensus, primarily to >>>> protect >>>> us from resource exhaustion and aid our efforts to keep the highest fe= e >>>> transactions. We call this mempool _policy_: a set of (configurable, >>>> node-specific) rules that transactions must abide by in order to be >>>> accepted >>>> into our mempool. Transaction "Standardness" rules and mempool >>>> restrictions such >>>> as "too-long-mempool-chain" are both examples of policy. >>>> >>>> ### Package Relay and Package Mempool Accept >>>> >>>> In transaction relay, we currently consider transactions one at a time >>>> for >>>> submission to the mempool. This creates a limitation in the node's >>>> ability to >>>> determine which transactions have the highest feerates, since we canno= t >>>> take >>>> into account descendants (i.e. cannot use CPFP) until all the >>>> transactions are >>>> in the mempool. Similarly, we cannot use a transaction's descendants >>>> when >>>> considering it for RBF. When an individual transaction does not meet >>>> the mempool >>>> minimum feerate and the user isn't able to create a replacement >>>> transaction >>>> directly, it will not be accepted by mempools. >>>> >>>> This limitation presents a security issue for applications and users >>>> relying on >>>> time-sensitive transactions. For example, Lightning and other protocol= s >>>> create >>>> UTXOs with multiple spending paths, where one counterparty's spending >>>> path opens >>>> up after a timelock, and users are protected from cheating scenarios a= s >>>> long as >>>> they redeem on-chain in time. A key security assumption is that all >>>> parties' >>>> transactions will propagate and confirm in a timely manner. This >>>> assumption can >>>> be broken if fee-bumping does not work as intended. >>>> >>>> The end goal for Package Relay is to consider multiple transactions at >>>> the same >>>> time, e.g. a transaction with its high-fee child. This may help us >>>> better >>>> determine whether transactions should be accepted to our mempool, >>>> especially if >>>> they don't meet fee requirements individually or are better RBF >>>> candidates as a >>>> package. A combination of changes to mempool validation logic, policy, >>>> and >>>> transaction relay allows us to better propagate the transactions with >>>> the >>>> highest package feerates to miners, and makes fee-bumping tools more >>>> powerful >>>> for users. >>>> >>>> The "relay" part of Package Relay suggests P2P messaging changes, but = a >>>> large >>>> part of the changes are in the mempool's package validation logic. We >>>> call this >>>> *Package Mempool Accept*. >>>> >>>> ### Previous Work >>>> >>>> * Given that mempool validation is DoS-sensitive and complex, it would >>>> be >>>> dangerous to haphazardly tack on package validation logic. Many >>>> efforts have >>>> been made to make mempool validation less opaque (see [#16400][4], >>>> [#21062][5], >>>> [#22675][6], [#22796][7]). >>>> * [#20833][8] Added basic capabilities for package validation, test >>>> accepts only >>>> (no submission to mempool). >>>> * [#21800][9] Implemented package ancestor/descendant limit checks for >>>> arbitrary >>>> packages. Still test accepts only. >>>> * Previous package relay proposals (see [#16401][10], [#19621][11]). >>>> >>>> ### Existing Package Rules >>>> >>>> These are in master as introduced in [#20833][8] and [#21800][9]. I'll >>>> consider >>>> them as "given" in the rest of this document, though they can be >>>> changed, since >>>> package validation is test-accept only right now. >>>> >>>> 1. A package cannot exceed `MAX_PACKAGE_COUNT=3D25` count and >>>> `MAX_PACKAGE_SIZE=3D101KvB` total size [8] >>>> >>>> *Rationale*: This is already enforced as mempool ancestor/descendan= t >>>> limits. >>>> Presumably, transactions in a package are all related, so exceeding >>>> this limit >>>> would mean that the package can either be split up or it wouldn't pass >>>> this >>>> mempool policy. >>>> >>>> 2. Packages must be topologically sorted: if any dependencies exist >>>> between >>>> transactions, parents must appear somewhere before children. [8] >>>> >>>> 3. A package cannot have conflicting transactions, i.e. none of them >>>> can spend >>>> the same inputs. This also means there cannot be duplicate >>>> transactions. [8] >>>> >>>> 4. When packages are evaluated against ancestor/descendant limits in a >>>> test >>>> accept, the union of all of their descendants and ancestors is >>>> considered. This >>>> is essentially a "worst case" heuristic where every transaction in the >>>> package >>>> is treated as each other's ancestor and descendant. [8] >>>> Packages for which ancestor/descendant limits are accurately captured >>>> by this >>>> heuristic: [19] >>>> >>>> There are also limitations such as the fact that CPFP carve out is not >>>> applied >>>> to package transactions. #20833 also disables RBF in package >>>> validation; this >>>> proposal overrides that to allow packages to use RBF. >>>> >>>> ## Proposed Changes >>>> >>>> The next step in the Package Mempool Accept project is to implement >>>> submission >>>> to mempool, initially through RPC only. This allows us to test the >>>> submission >>>> logic before exposing it on P2P. >>>> >>>> ### Summary >>>> >>>> - Packages may contain already-in-mempool transactions. >>>> - Packages are 2 generations, Multi-Parent-1-Child. >>>> - Fee-related checks use the package feerate. This means that wallets >>>> can >>>> create a package that utilizes CPFP. >>>> - Parents are allowed to RBF mempool transactions with a set of rules >>>> similar >>>> to BIP125. This enables a combination of CPFP and RBF, where a >>>> transaction's descendant fees pay for replacing mempool conflicts. >>>> >>>> There is a draft implementation in [#22290][1]. It is WIP, but feedbac= k >>>> is >>>> always welcome. >>>> >>>> ### Details >>>> >>>> #### Packages May Contain Already-in-Mempool Transactions >>>> >>>> A package may contain transactions that are already in the mempool. We >>>> remove >>>> ("deduplicate") those transactions from the package for the purposes o= f >>>> package >>>> mempool acceptance. If a package is empty after deduplication, we do >>>> nothing. >>>> >>>> *Rationale*: Mempools vary across the network. It's possible for a >>>> parent to be >>>> accepted to the mempool of a peer on its own due to differences in >>>> policy and >>>> fee market fluctuations. We should not reject or penalize the entire >>>> package for >>>> an individual transaction as that could be a censorship vector. >>>> >>>> #### Packages Are Multi-Parent-1-Child >>>> >>>> Only packages of a specific topology are permitted. Namely, a package >>>> is exactly >>>> 1 child with all of its unconfirmed parents. After deduplication, the >>>> package >>>> may be exactly the same, empty, 1 child, 1 child with just some of its >>>> unconfirmed parents, etc. Note that it's possible for the parents to b= e >>>> indirect >>>> descendants/ancestors of one another, or for parent and child to share >>>> a parent, >>>> so we cannot make any other topology assumptions. >>>> >>>> *Rationale*: This allows for fee-bumping by CPFP. Allowing multiple >>>> parents >>>> makes it possible to fee-bump a batch of transactions. Restricting >>>> packages to a >>>> defined topology is also easier to reason about and simplifies the >>>> validation >>>> logic greatly. Multi-parent-1-child allows us to think of the package >>>> as one big >>>> transaction, where: >>>> >>>> - Inputs =3D all the inputs of parents + inputs of the child that come >>>> from >>>> confirmed UTXOs >>>> - Outputs =3D all the outputs of the child + all outputs of the parent= s >>>> that >>>> aren't spent by other transactions in the package >>>> >>>> Examples of packages that follow this rule (variations of example A >>>> show some >>>> possibilities after deduplication): ![image][15] >>>> >>>> #### Fee-Related Checks Use Package Feerate >>>> >>>> Package Feerate =3D the total modified fees divided by the total virtu= al >>>> size of >>>> all transactions in the package. >>>> >>>> To meet the two feerate requirements of a mempool, i.e., the >>>> pre-configured >>>> minimum relay feerate (`minRelayTxFee`) and dynamic mempool minimum >>>> feerate, the >>>> total package feerate is used instead of the individual feerate. The >>>> individual >>>> transactions are allowed to be below feerate requirements if the >>>> package meets >>>> the feerate requirements. For example, the parent(s) in the package ca= n >>>> have 0 >>>> fees but be paid for by the child. >>>> >>>> *Rationale*: This can be thought of as "CPFP within a package," solvin= g >>>> the >>>> issue of a parent not meeting minimum fees on its own. This allows L2 >>>> applications to adjust their fees at broadcast time instead of >>>> overshooting or >>>> risking getting stuck/pinned. >>>> >>>> We use the package feerate of the package *after deduplication*. >>>> >>>> *Rationale*: It would be incorrect to use the fees of transactions >>>> that are >>>> already in the mempool, as we do not want a transaction's fees to be >>>> double-counted for both its individual RBF and package RBF. >>>> >>>> Examples F and G [14] show the same package, but P1 is submitted >>>> individually before >>>> the package in example G. In example F, we can see that the 300vB >>>> package pays >>>> an additional 200sat in fees, which is not enough to pay for its own >>>> bandwidth >>>> (BIP125#4). In example G, we can see that P1 pays enough to replace M1= , >>>> but >>>> using P1's fees again during package submission would make it look lik= e >>>> a 300sat >>>> increase for a 200vB package. Even including its fees and size would >>>> not be >>>> sufficient in this example, since the 300sat looks like enough for the >>>> 300vB >>>> package. The calculcation after deduplication is 100sat increase for a >>>> package >>>> of size 200vB, which correctly fails BIP125#4. Assume all transactions >>>> have a >>>> size of 100vB. >>>> >>>> #### Package RBF >>>> >>>> If a package meets feerate requirements as a package, the parents in t= he >>>> transaction are allowed to replace-by-fee mempool transactions. The >>>> child cannot >>>> replace mempool transactions. Multiple transactions can replace the sa= me >>>> transaction, but in order to be valid, none of the transactions can tr= y >>>> to >>>> replace an ancestor of another transaction in the same package (which >>>> would thus >>>> make its inputs unavailable). >>>> >>>> *Rationale*: Even if we are using package feerate, a package will not >>>> propagate >>>> as intended if RBF still requires each individual transaction to meet >>>> the >>>> feerate requirements. >>>> >>>> We use a set of rules slightly modified from BIP125 as follows: >>>> >>>> ##### Signaling (Rule #1) >>>> >>>> All mempool transactions to be replaced must signal replaceability. >>>> >>>> *Rationale*: Package RBF signaling logic should be the same for packag= e >>>> RBF and >>>> single transaction acceptance. This would be updated if single >>>> transaction >>>> validation moves to full RBF. >>>> >>>> ##### New Unconfirmed Inputs (Rule #2) >>>> >>>> A package may include new unconfirmed inputs, but the ancestor feerate >>>> of the >>>> child must be at least as high as the ancestor feerates of every >>>> transaction >>>> being replaced. This is contrary to BIP125#2, which states "The >>>> replacement >>>> transaction may only include an unconfirmed input if that input was >>>> included in >>>> one of the original transactions. (An unconfirmed input spends an >>>> output from a >>>> currently-unconfirmed transaction.)" >>>> >>>> *Rationale*: The purpose of BIP125#2 is to ensure that the replacement >>>> transaction has a higher ancestor score than the original >>>> transaction(s) (see >>>> [comment][13]). Example H [16] shows how adding a new unconfirmed inpu= t >>>> can lower the >>>> ancestor score of the replacement transaction. P1 is trying to replace >>>> M1, and >>>> spends an unconfirmed output of M2. P1 pays 800sat, M1 pays 600sat, an= d >>>> M2 pays >>>> 100sat. Assume all transactions have a size of 100vB. While, in >>>> isolation, P1 >>>> looks like a better mining candidate than M1, it must be mined with M2= , >>>> so its >>>> ancestor feerate is actually 4.5sat/vB. This is lower than M1's >>>> ancestor >>>> feerate, which is 6sat/vB. >>>> >>>> In package RBF, the rule analogous to BIP125#2 would be "none of the >>>> transactions in the package can spend new unconfirmed inputs." Example >>>> J [17] shows >>>> why, if any of the package transactions have ancestors, package feerat= e >>>> is no >>>> longer accurate. Even though M2 and M3 are not ancestors of P1 (which >>>> is the >>>> replacement transaction in an RBF), we're actually interested in the >>>> entire >>>> package. A miner should mine M1 which is 5sat/vB instead of M2, M3, P1= , >>>> P2, and >>>> P3, which is only 4sat/vB. The Package RBF rule cannot be loosened to >>>> only allow >>>> the child to have new unconfirmed inputs, either, because it can still >>>> cause us >>>> to overestimate the package's ancestor score. >>>> >>>> However, enforcing a rule analogous to BIP125#2 would not only make >>>> Package RBF >>>> less useful, but would also break Package RBF for packages with parent= s >>>> already >>>> in the mempool: if a package parent has already been submitted, it >>>> would look >>>> like the child is spending a "new" unconfirmed input. In example K >>>> [18], we're >>>> looking to replace M1 with the entire package including P1, P2, and P3= . >>>> We must >>>> consider the case where one of the parents is already in the mempool >>>> (in this >>>> case, P2), which means we must allow P3 to have new unconfirmed inputs= . >>>> However, >>>> M2 lowers the ancestor score of P3 to 4.3sat/vB, so we should not >>>> replace M1 >>>> with this package. >>>> >>>> Thus, the package RBF rule regarding new unconfirmed inputs is less >>>> strict than >>>> BIP125#2. However, we still achieve the same goal of requiring the >>>> replacement >>>> transactions to have a ancestor score at least as high as the original >>>> ones. As >>>> a result, the entire package is required to be a higher feerate mining >>>> candidate >>>> than each of the replaced transactions. >>>> >>>> Another note: the [comment][13] above the BIP125#2 code in the origina= l >>>> RBF >>>> implementation suggests that the rule was intended to be temporary. >>>> >>>> ##### Absolute Fee (Rule #3) >>>> >>>> The package must increase the absolute fee of the mempool, i.e. the >>>> total fees >>>> of the package must be higher than the absolute fees of the mempool >>>> transactions >>>> it replaces. Combined with the CPFP rule above, this differs from >>>> BIP125 Rule #3 >>>> - an individual transaction in the package may have lower fees than th= e >>>> transaction(s) it is replacing. In fact, it may have 0 fees, and the >>>> child >>>> pays for RBF. >>>> >>>> ##### Feerate (Rule #4) >>>> >>>> The package must pay for its own bandwidth; the package feerate must b= e >>>> higher >>>> than the replaced transactions by at least minimum relay feerate >>>> (`incrementalRelayFee`). Combined with the CPFP rule above, this >>>> differs from >>>> BIP125 Rule #4 - an individual transaction in the package can have a >>>> lower >>>> feerate than the transaction(s) it is replacing. In fact, it may have = 0 >>>> fees, >>>> and the child pays for RBF. >>>> >>>> ##### Total Number of Replaced Transactions (Rule #5) >>>> >>>> The package cannot replace more than 100 mempool transactions. This is >>>> identical >>>> to BIP125 Rule #5. >>>> >>>> ### Expected FAQs >>>> >>>> 1. Is it possible for only some of the package to make it into the >>>> mempool? >>>> >>>> Yes, it is. However, since we evict transactions from the mempool b= y >>>> descendant score and the package child is supposed to be sponsoring th= e >>>> fees of >>>> its parents, the most common scenario would be all-or-nothing. This is >>>> incentive-compatible. In fact, to be conservative, package validation >>>> should >>>> begin by trying to submit all of the transactions individually, and >>>> only use the >>>> package mempool acceptance logic if the parents fail due to low feerat= e. >>>> >>>> 2. Should we allow packages to contain already-confirmed transactions? >>>> >>>> No, for practical reasons. In mempool validation, we actually >>>> aren't able to >>>> tell with 100% confidence if we are looking at a transaction that has >>>> already >>>> confirmed, because we look up inputs using a UTXO set. If we have >>>> historical >>>> block data, it's possible to look for it, but this is inefficient, not >>>> always >>>> possible for pruning nodes, and unnecessary because we're not going to >>>> do >>>> anything with the transaction anyway. As such, we already have the >>>> expectation >>>> that transaction relay is somewhat "stateful" i.e. nobody should be >>>> relaying >>>> transactions that have already been confirmed. Similarly, we shouldn't >>>> be >>>> relaying packages that contain already-confirmed transactions. >>>> >>>> [1]: https://github.com/bitcoin/bitcoin/pull/22290 >>>> [2]: >>>> https://github.com/bitcoin/bips/blob/1f0b563738199ca60d32b4ba779797fc9= 7d040fe/bip-0141.mediawiki#transaction-size-calculations >>>> [3]: >>>> https://github.com/bitcoin/bitcoin/blob/94f83534e4b771944af7d9ed0f4074= 6f392eb75e/src/policy/policy.cpp#L282 >>>> [4]: https://github.com/bitcoin/bitcoin/pull/16400 >>>> [5]: https://github.com/bitcoin/bitcoin/pull/21062 >>>> [6]: https://github.com/bitcoin/bitcoin/pull/22675 >>>> [7]: https://github.com/bitcoin/bitcoin/pull/22796 >>>> [8]: https://github.com/bitcoin/bitcoin/pull/20833 >>>> [9]: https://github.com/bitcoin/bitcoin/pull/21800 >>>> [10]: https://github.com/bitcoin/bitcoin/pull/16401 >>>> [11]: https://github.com/bitcoin/bitcoin/pull/19621 >>>> [12]: https://github.com/bitcoin/bips/blob/master/bip-0125.mediawiki >>>> [13]: >>>> https://github.com/bitcoin/bitcoin/pull/6871/files#diff-34d21af3c614ea= 3cee120df276c9c4ae95053830d7f1d3deaf009a4625409ad2R1101-R1104 >>>> [14]: >>>> https://user-images.githubusercontent.com/25183001/133567078-075a971c-= 0619-4339-9168-b41fd2b90c28.png >>>> [15]: >>>> https://user-images.githubusercontent.com/25183001/132856734-fc17da75-= f875-44bb-b954-cb7a1725cc0d.png >>>> [16]: >>>> https://user-images.githubusercontent.com/25183001/133567347-a3e2e4a8-= ae9c-49f8-abb9-81e8e0aba224.png >>>> [17]: >>>> https://user-images.githubusercontent.com/25183001/133567370-21566d0e-= 36c8-4831-b1a8-706634540af3.png >>>> [18]: >>>> https://user-images.githubusercontent.com/25183001/133567444-bfff1142-= 439f-4547-800a-2ba2b0242bcb.png >>>> [19]: >>>> https://user-images.githubusercontent.com/25183001/133456219-0bb447cb-= dcb4-4a31-b9c1-7d86205b68bc.png >>>> [20]: >>>> https://user-images.githubusercontent.com/25183001/132857787-7b7c6f56-= af96-44c8-8d78-983719888c19.png >>>> _______________________________________________ >>>> bitcoin-dev mailing list >>>> bitcoin-dev@lists.linuxfoundation.org >>>> https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev >>>> >>> --0000000000000c080e05ccab6429 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Antoine,

Thanks as always for your input. I= 'm glad we agree on so much!

In summary, it se= ems that the decisions that might still need attention/input from devs on t= his mailing list are:
1. Whether we should start with multiple-parent-= 1-child or 1-parent-1-child.
2. Whether it's ok to require that the = child not have conflicts with mempool transactions.

Responding = to your comments...

> IIUC, you have package A+B, du= ring the dedup phase early in `AcceptMultipleTransactions` if you observe s= ame-txid-different-wtixd A' and A' is higher feerate than A, you tr= im A and replace by A' ?

> I think this approach is safe, the= one who appears unsafe to me is when A' has a _lower_ feerate, even if= A' is already accepted by our mempool ? In that case iirc that would b= e a pinning.

Right, the fact that we essentially always choose the f= irst-seen witness is an unfortunate limitation that exists already. Adding = package mempool accept doesn't worsen this, but the procedure in the fu= ture is to replace the witness when it makes sense economically. We can als= o add logic to allow package feerate to pay for witness replacements as wel= l. This is pretty far into the future, though.

> It sounds unecon= omical for an attacker but I think it's not when you consider than you = can "batch" attack against multiple honest counterparties. E.g, M= allory broadcast A' + B' + C' + D' where A' conflicts w= ith Alice's honest package P1, B' conflicts with Bob's honest p= ackage P2, C' conflicts with Caroll's honest package P3. And D'= is a high-fee child of A' + B' + C'.

> If D' is = higher-fee than P1 or P2 or P3 but inferior to the sum of HTLCs confirmed b= y P1+P2+P3, I think it's lucrative for the attacker ?

I could be= misunderstanding, but an attacker wouldn't be able to batch-attack lik= e this. Alice's package only conflicts with A' + D', not A'= + B' + C' + D'. She only needs to pay for evicting 2 transacti= ons.

> Do we assume that broadcasted packages are "honest&qu= ot; by default and that the parent(s) always need the child to pass the fee= checks, that way saving the processing of individual transactions which ar= e expected to fail in 99% of cases or more ad hoc composition of packages a= t relay ?
> I think this point is quite dependent on the p2p packages= format/logic we'll end up on and that we should feel free to revisit i= t later ?

I think it's the opposite; there's no way for us t= o assume that p2p packages will be "honest." I'd like to have= two things before we expose on P2P: (1) ensure that the amount of resource= s potentially allocated for package validation isn't disproportionately= higher than that of single transaction validation and (2) only use package= validation when we're unsatisifed with the single validation result, e= .g. we might get better fees.
Yes, let's revisit this later :)
= =C2=A0
=C2=A0> Yes, if you receive A+B, and A is already in-mempoo, I= agree you can discard its feerate as B should pay for all fees checked on = its own. Where I'm unclear is when you have in-mempool A+B and receive = A+B'. Should B' have a fee high enough to cover the bandwidth penal= ty replacement (`PaysForRBF`, 2nd check) of both A+B' or only B' ?<= br>=C2=A0
=C2=A0B' only needs to pay for itself in this case.
=C2= =A0
> > Do we want the child to be able to replace mempool transac= tions as well?

> If we mean when you have replaceable A+B then A&= #39;+B' try to replace with a higher-feerate ? I think that's exact= ly the case we need for Lightning as A+B is coming from Alice and A'+B&= #39; is coming from Bob :/

Let me clarify this because I can se= e that my wording was ambiguous, and then please let me know if it fits Lig= htning's needs?

In my proposal, I wrote "If a = package meets feerate requirements as a package, the parents in the transac= tion are allowed to replace-by-fee mempool transactions. The child cannot r= eplace mempool transactions." What I meant was: the package can replac= e mempool transactions if any of the parents conflict with mempool transact= ions. The child cannot not conflict with any mempool transactions.
The L= ightning use case this attempts to address is: Alice and Mallory are LN cou= nterparties, and have packages A+B and A'+B', respectively. A and A= ' are their commitment transactions and conflict with each other; they = have shared inputs and different txids.
B spends Alice's anchor outp= ut from A. B' spends Mallory's anchor output from A'. Thus, B a= nd B' do not conflict with each other.
Alice can broadcast her packa= ge, A+B, to replace Mallory's package, A'+B', since B doesn'= ;t conflict with the mempool.

Would this be ok?

> The seco= nd option, a child of A', In the LN case I think the CPFP is attached o= n one's anchor output.

While it would be nice to have full RBF, = malleability of the child won't block RBF here. If we're trying to = replace A', we only require that A' signals replaceability, and don= 't mind if its child doesn't.

> > B has an ancestor sc= ore of 10sat/vb and D has an
> > ancestor score of ~2.9sat/vb. Sin= ce D's ancestor score is lower than B's,
> > it fails the = proposed package RBF Rule #2, so this package would be
> > rejecte= d. Does this meet your expectations?

> Well what sounds odd to me= , in my example, we fail D even if it has a higher-fee than B. Like A+B abs= olute fees are 2000 sats and A+C+D absolute fees are 4500 sats ?

Yes= , A+C+D pays 2500sat more in fees, but it is also 1000vB larger. A miner sh= ould prefer to utilize their block space more effectively.

> Is t= his compatible with a model where a miner prioritizes absolute fees over an= cestor score, in the case that mempools aren't full-enough to fulfill a= block ?

No, because we don't use that model.

Thanks,
= Gloria

On Thu, Sep 23, 2021 at 5:29 AM Antoine Riard <antoine.riard@gmail.com> wrote:
> Correc= t, if B+C is too low feerate to be accepted, we will reject it. I
> p= refer this because it is incentive compatible: A can be mined by itself,> so there's no reason to prefer A+B+C instead of A.
> As ano= ther way of looking at this, consider the case where we do accept
> A= +B+C and it sits at the "bottom" of our mempool. If our mempool r= eaches
> capacity, we evict the lowest descendant feerate transaction= s, which are
> B+C in this case. This gives us the same resulting mem= pool, with A and not
> B+C.

I agree here. Doing otherwise, we = might evict other transactions mempool in `MempoolAccept::Finalize` with a = higher-feerate than B+C while those evicted transactions are the most compe= lling for block construction.

I thought at first missing this accept= ance requirement would break a fee-bumping scheme like Parent-Pay-For-Child= where a high-fee parent is attached to a child signed with SIGHASH_ANYONEC= ANPAY but in this case the child fee is capturing the parent value. I can&#= 39;t think of other fee-bumping schemes potentially affected. If they do ex= ist I would say they're wrong in their design assumptions.

> = If or when we have witness replacement, the logic is: if the individual
= > transaction is enough to replace the mempool one, the replacement will=
> happen during the preceding individual transaction acceptance, and=
> deduplication logic will work. Otherwise, we will try to deduplica= te by
> wtxid, see that we need a package witness replacement, and us= e the package
> feerate to evaluate whether this is economically rati= onal.

IIUC, you have package A+B, during the dedup phase early in `A= cceptMultipleTransactions` if you observe same-txid-different-wtixd A' = and A' is higher feerate than A, you trim A and replace by A' ?
=
I think this approach is safe, the one who appears unsafe to me is when= A' has a _lower_ feerate, even if A' is already accepted by our me= mpool ? In that case iirc that would be a pinning.

Good to see progr= ess on witness replacement before we see usage of Taproot tree in the conte= xt of multi-party, where a malicious counterparty inflates its witness to j= am a honest spending.

(Note, the commit linked currently points nowh= ere :))


> Please note that A may replace A' even if A'= ; has higher fees than A
> individually, because the proposed package= RBF utilizes the fees and size
> of the entire package. This just re= quires E to pay enough fees, although
> this can be pretty high if th= ere are also potential B' and C' competing
> commitment trans= actions that we don't know about.

Ah right, if the package accep= tance waives `PaysMoreThanConflicts` for the individual check on A, the hon= est package should replace the pinning attempt. I've not fully parsed t= he proposed implementation yet.

Though note, I think it's still = unsafe for a Lightning multi-commitment-broadcast-as-one-package as a malic= ious A' might have an absolute fee higher than E. It sounds uneconomica= l for
an attacker but I think it's not when you consider than you ca= n "batch" attack against multiple honest counterparties. E.g, Mal= lory broadcast A' + B' + C' + D' where A' conflicts wit= h Alice's honest package P1, B' conflicts with Bob's honest pac= kage P2, C' conflicts with Caroll's honest package P3. And D' i= s a high-fee child of A' + B' + C'.

If D' is higher-= fee than P1 or P2 or P3 but inferior to the sum of HTLCs confirmed by P1+P2= +P3, I think it's lucrative for the attacker ?

> So far, my u= nderstanding is that multi-parent-1-child is desired for
> batched fe= e-bumping (
> https://github.com/bitcoin/bitc= oin/pull/22674#issuecomment-897951289) and
> I've also seen y= our response which I have less context on (
> https://github.com/bitcoin/bitcoin/pull/22674#issuecomment-900352202).= That
> being said, I am happy to create a new proposal for 1 parent = + 1 child
> (which would be slightly simpler) and plan for moving to<= br>> multi-parent-1-child later if that is preferred. I am very interest= ed in
> hearing feedback on that approach.

I think batched fee= -bumping is okay as long as you don't have time-sensitive outputs encum= bering your commitment transactions. For the reasons mentioned above, I thi= nk that's unsafe.

What I'm worried about is=C2=A0 L2 develop= ers, potentially not aware about all the mempool subtleties blurring the di= fference and always batching their broadcast by default.

IMO, a good= thing by restraining to 1-parent + 1 child, =C2=A0we artificially constrai= nt L2 design space for now and minimize risks of unsafe usage of the packag= e API :)

I think that's a point where it would be relevant to ha= ve the opinion of more L2 devs.

> I think there is a misunderstan= ding here - let me describe what I'm
> proposing we'd do in t= his situation: we'll try individual submission for A,
> see that = it fails due to "insufficient fees." Then, we'll try package<= br>> validation for A+B and use package RBF. If A+B pays enough, it can = still
> replace A'. If A fails for a bad signature, we won't = look at B or A+B. Does
> this meet your expectations?

Yes ther= e was a misunderstanding, I think this approach is correct, it's more a= question of performance. Do we assume that broadcasted packages are "= honest" by default and that the parent(s) always need the child to pas= s the fee checks, that way saving the processing of individual transactions= which are expected to fail in 99% of cases or more ad hoc composition of p= ackages at relay ?

I think this point is quite dependent on the p2p = packages format/logic we'll end up on and that we should feel free to r= evisit it later ?


> What problem are you trying to solve by t= he package feerate *after* dedup
rule ?
> My understanding is that= an in-package transaction might be already in
the mempool. Therefore, t= o compute a correct RBF penalty replacement, the
vsize of this transacti= on could be discarded lowering the cost of package
RBF.

> I= 9;m proposing that, when a transaction has already been submitted to
>= ; mempool, we would ignore both its fees and vsize when calculating package=
> feerate.

Yes, if you receive A+B, and A is already in-memp= oo, I agree you can discard its feerate as B should pay for all fees checke= d on its own. Where I'm unclear is when you have in-mempool A+B and rec= eive A+B'. Should B' have a fee high enough to cover the bandwidth = penalty replacement (`PaysForRBF`, 2nd check) of both A+B' or only B= 9; ?

If you have a second-layer like current Lightning, you might ha= ve a counterparty commitment to replace and should always expect to have to= pay for parent replacement bandwidth.

Where a potential discount so= unds interesting is when you have an univoque state on the first-stage of t= ransactions. E.g DLC's funding transaction which might be CPFP by any p= articipant iirc.

> Note that, if C' conflicts with C, it also= conflicts with D, since D is a
> descendant of C and would thus need= to be evicted along with it.

Ah once again I think it's a misun= derstanding without the code under my eyes! If we do C' `PreChecks`, so= lve the conflicts provoked by it, i.e mark for potential eviction D and don= 't consider it for future conflicts in the rest of the package, I think= D' `PreChecks` should be good ?

> More generally, this examp= le is surprising to me because I didn't think
> packages would be= used to fee-bump replaceable transactions. Do we want the
> child to= be able to replace mempool transactions as well?

If we mean when yo= u have replaceable A+B then A'+B' try to replace with a higher-feer= ate ? I think that's exactly the case we need for Lightning as A+B is c= oming from Alice and A'+B' is coming from Bob :/

> I'= m not sure what you mean? Let's say we have a package of parent A + chi= ld
> B, where A is supposed to replace a mempool transaction A'. = Are you saying
> that counterparties are able to malleate the package= child B, or a child of
> A'?

The second option, a child = of A', In the LN case I think the CPFP is attached on one's anchor = output.

I think it's good if we assume the solve-conflicts-after= -parent's`'PreChecks` mentioned above or fixing inherited signaling= or full-rbf ?

> Sorry, I don't understand what you mean by &= quot;preserve the package
> integrity?" Could you elaborate?
=
After thinking the relaxation about the "new" unconfirmed inp= ut is not linked to trimming but I would say more to the multi-parent suppo= rt.

Let's say you have A+B trying to replace C+D where B is also= spending already in-mempool E. To succeed, you need to waive the no-new-un= confirmed input as D isn't spending E.

So good, I think we agree= on the problem description here.

> I am in agreement with your c= alculations but unsure if we disagree on the
> expected outcome. Yes,= B has an ancestor score of 10sat/vb and D has an
> ancestor score of= ~2.9sat/vb. Since D's ancestor score is lower than B's,
> it= fails the proposed package RBF Rule #2, so this package would be
> r= ejected. Does this meet your expectations?

Well what sounds odd to m= e, in my example, we fail D even if it has a higher-fee than B. Like A+B ab= solute fees are 2000 sats and A+C+D absolute fees are 4500 sats ?

Is= this compatible with a model where a miner prioritizes absolute fees over = ancestor score, in the case that mempools aren't full-enough to fulfill= a block ?

Let me know if I can clarify a point.

Antoine
<= /div>
L= e=C2=A0lun. 20 sept. 2021 =C3=A0=C2=A011:10, Gloria Zhao <gloriajzhao@gmail.com> = a =C3=A9crit=C2=A0:

Hi Antoine,

First of all, thank you for the= thorough review. I appreciate your insight on LN requirements.

>= IIUC, you have a package A+B+C submitted for acceptance and A is already i= n your mempool. You trim out A from the package and then evaluate B+C.
<= br>> I think this might be an issue if A is the higher-fee element of th= e ABC package. B+C package fees might be under the mempool min fee and will= be rejected, potentially breaking the acceptance expectations of the packa= ge issuer ?

Correct, if B+C is too low feerate to be accepted, we wi= ll reject it. I prefer this because it is incentive compatible: A can be mi= ned by itself, so there's no reason to prefer A+B+C instead of A.
As= another way of looking at this, consider the case where we do accept A+B+C= and it sits at the "bottom" of our mempool. If our mempool reach= es capacity, we evict the lowest descendant feerate transactions, which are= B+C in this case. This gives us the same resulting mempool, with A and not= B+C.


> Further, I think the dedup shou= ld be done on wtxid, as you might have multiple valid witnesses. Though wit= h varying vsizes and as such offering different feerates.

I agree th= at variations of the same package with different witnesses is a case that m= ust be handled. I consider witness replacement to be a project that can be = done in parallel to package mempool acceptance because being able to accept= packages does not worsen the problem of a same-txid-different-witness &quo= t;pinning" attack.

If or when we have witness replacement, the = logic is: if the individual transaction is enough to replace the mempool on= e, the replacement will happen during the preceding individual transaction = acceptance, and deduplication logic will work. Otherwise, we will try to de= duplicate by wtxid, see that we need a package witness replacement, and use= the package feerate to evaluate whether this is economically rational.
=
See the #22290 "handle package transactions already in mempool&quo= t; commit (https://github= .com/bitcoin/bitcoin/pull/22290/commits/fea75a2237b46cf76145242fecad7e274bf= cb5ff), which handles the case of same-txid-different-witness by simply= using the transaction in the mempool for now, with TODOs for what I just d= escribed.


> I'm not clearly understanding the accepted to= pologies. By "parent and child to share a parent", do you mean th= e set of transactions A, B, C, where B is spending A and C is spending A an= d B would be correct ?

Yes, that is what I meant. Yes, that would a = valid package under these rules.

> If yes, is there a width-limit= introduced or we fallback on MAX_PACKAGE_COUNT=3D25 ?

No, there is = no limit on connectivity other than "child with all unconfirmed parent= s." We will enforce MAX_PACKAGE_COUNT=3D25 and child's in-mempool = + in-package ancestor limits.


> Considering the current Core&= #39;s mempool acceptance rules, I think CPFP batching is unsafe for LN time= -sensitive closure. A malicious tx-relay jamming successful on one channel = commitment transaction would contamine the remaining commitments sharing th= e same package.

> E.g, you broadcast the package A+B+C+D+E where = A,B,C,D are commitment transactions and E a shared CPFP. If a malicious A&#= 39; transaction has a better feerate than A, the whole package acceptance w= ill fail. Even if A' confirms in the following block,
the propagatio= n and confirmation of B+C+D have been delayed. This could carry on a loss o= f funds.

Please note that A may replace A' even if A' has hi= gher fees than A individually, because the proposed package RBF utilizes th= e fees and size of the entire package. This just requires E to pay enough f= ees, although this can be pretty high if there are also potential B' an= d C' competing commitment transactions that we don't know about.

> IMHO, I'm leaning towards deploying during a first phase = 1-parent/1-child. I think it's the most conservative step still improvi= ng second-layer safety.

So far, my understanding is that multi-paren= t-1-child is desired for batched fee-bumping (https= ://github.com/bitcoin/bitcoin/pull/22674#issuecomment-897951289) and I&= #39;ve also seen your response which I have less context on (https://github.com/bitcoin/bitcoin/pull/22674#issuecomment-9003= 52202). That being said, I am happy to create a new proposal for 1 pare= nt + 1 child (which would be slightly simpler) and plan for moving to multi= -parent-1-child later if that is preferred. I am very interested in hearing= feedback on that approach.


> If A+B is submitted to replace = A', where A pays 0 sats, B pays 200 sats and A' pays 100 sats. If w= e apply the individual RBF on A, A+B acceptance fails. For this reason I th= ink the individual RBF should be bypassed and only the package RBF apply ?<= br>
I think there is a misunderstanding here - let me describe what I= 9;m proposing we'd do in this situation: we'll try individual submi= ssion for A, see that it fails due to "insufficient fees." Then, = we'll try package validation for A+B and use package RBF. If A+B pays e= nough, it can still replace A'. If A fails for a bad signature, we won&= #39;t look at B or A+B. Does this meet your expectations?


> W= hat problem are you trying to solve by the package feerate *after* dedup ru= le ?
> My understanding is that an in-package transaction might be al= ready in the mempool. Therefore, to compute a correct RBF penalty replaceme= nt, the vsize of this transaction could be discarded lowering the cost of p= ackage RBF.

I'm proposing that, when a transaction has already b= een submitted to mempool, we would ignore both its fees and vsize when calc= ulating package feerate. In example G2, we shouldn't count M1 fees afte= r its submission to mempool, since M1's fees have already been used to = pay for its individual bandwidth, and it shouldn't be used again to pay= for P2 and P3's bandwidth. We also shouldn't count its vsize, sinc= e it has already been paid for.


> I think this is a footgunis= h API, as if a package issuer send the multiple-parent-one-child package A,= B,C,D where D is the child of A,B,C. Then try to broadcast the higher-feera= te C'+D' package, it should be rejected. So it's breaking the n= aive broadcaster assumption that a higher-feerate/higher-fee package always= replaces ?

Note that, if C' conflicts with C, it also conf= licts with D, since D is a descendant of C and would thus need to be evicte= d along with it. Implicitly, D' would not be in conflict with D.
More generally, this example is surprising to me because I didn'= ;t think packages would be used to fee-bump replaceable transactions. Do we= want the child to be able to replace mempool transactions as well? This ca= n be implemented with a bit of additional logic.

> I think this= is unsafe for L2s if counterparties have malleability of the child transac= tion. They can block your package replacement by opting-out from RBF signal= ing. IIRC, LN's "anchor output" presents such an ability.
=
I'm not sure what you mean? Let's say we have a package of pare= nt A + child B, where A is supposed to replace a mempool transaction A'= . Are you saying that counterparties are able to malleate the package child= B, or a child of A'? If they can malleate a child of A', that shou= ldn't matter as long as A' is signaling replacement. This would be = handled identically with full RBF and what Core currently implements.
> I think this is an issue brought by the trimming during the dedup ph= ase. If we preserve the package integrity, only re-using the tx-level check= s results of already in-mempool transactions to gain in CPU time we won'= ;t have this issue. Package childs can add unconfirmed inputs as long as th= ey're in-package, the bip125 rule2 is only evaluated against parents ?<= br>
Sorry, I don't understand what you mean by "preserve the pa= ckage integrity?" Could you elaborate?

> Let's say you h= ave in-mempool A, B where A pays 10 sat/vb for 100 vbytes and B pays 10 sat= /vb for 100 vbytes. You have the candidate replacement D spending both A an= d C where D pays 15sat/vb for 100 vbytes and C pays 1 sat/vb for 1000 vbyte= s.

> Package A + B ancestor score is 10 sat/vb.

> D has= a higher feerate/absolute fee than B.

> Package A + C + D ancest= or score is ~ 3 sat/vb ((A's 1000 sats + C's 1000 sats + D's 15= 00 sats) / A's 100 vb + C's 1000 vb + D's 100 vb)

I= am in agreement with your calculations but unsure if we disagree on the ex= pected outcome. Yes, B has an ancestor score of 10sat/vb and D has an ances= tor score of ~2.9sat/vb. Since D's ancestor score is lower than B's= , it fails the proposed package RBF Rule #2, so this package would be rejec= ted. Does this meet your expectations?

Thank you f= or linking to projects that might be interested in package relay :)

Thanks,
Gloria

On Mon, Sep 20, 2021 at 12:16 AM Antoine Riard &= lt;antoine.ria= rd@gmail.com> wrote:
Hi Gloria,

> A package may contain t= ransactions that are already in the mempool. We
> remove
> (&qu= ot;deduplicate") those transactions from the package for the purposes = of
> package
> mempool acceptance. If a package is empty after = deduplication, we do
> nothing.

IIUC, you have a package A+B+C= submitted for acceptance and A is already in your mempool. You trim out A = from the package and then evaluate B+C.

I think this might be an iss= ue if A is the higher-fee element of the ABC package. B+C package fees migh= t be under the mempool min fee and will be rejected, potentially breaking t= he acceptance expectations of the package issuer ?

Further, I think = the dedup should be done on wtxid, as you might have multiple valid witness= es. Though with varying vsizes and as such offering different feerates.
=
E.g you're going to evaluate the package A+B and A' is already = in your mempool with a bigger valid witness. You trim A based on txid, then= you evaluate A'+B, which fails the fee checks. However, evaluating A+B= would have been a success.

AFAICT, the dedup rationale would be to = save on CPU time/IO disk, to avoid repeated signatures verification and par= ent UTXOs fetches ? Can we achieve the same goal by bypassing tx-level chec= ks for already-in txn while conserving the package integrity for package-le= vel checks ?

> Note that it's possible for the parents to be<= br>> indirect
> descendants/ancestors of one another, or for paren= t and child to share a
> parent,
> so we cannot make any other = topology assumptions.

I'm not clearly understanding the accepted= topologies. By "parent and child to share a parent", do you mean= the set of transactions A, B, C, where B is spending A and C is spending A= and B would be correct ?

If yes, is there a width-limit introduced = or we fallback on MAX_PACKAGE_COUNT=3D25 ?

IIRC, one rationale to co= me with this topology limitation was to lower the DoS risks when potentiall= y deploying p2p packages.

Considering the current Core's mempool= acceptance rules, I think CPFP batching is unsafe for LN time-sensitive cl= osure. A malicious tx-relay jamming successful on one channel commitment tr= ansaction would contamine the remaining commitments sharing the same packag= e.

E.g, you broadcast the package A+B+C+D+E where A,B,C,D are commit= ment transactions and E a shared CPFP. If a malicious A' transaction ha= s a better feerate than A, the whole package acceptance will fail. Even if = A' confirms in the following block,
the propagation and confirmatio= n of B+C+D have been delayed. This could carry on a loss of funds.

T= hat said, if you're broadcasting commitment transactions without time-s= ensitive HTLC outputs, I think the batching is effectively a fee saving as = you don't have to duplicate the CPFP.

IMHO, I'm leaning towa= rds deploying during a first phase 1-parent/1-child. I think it's the m= ost conservative step still improving second-layer safety.

> *Rat= ionale*: =C2=A0It would be incorrect to use the fees of transactions that a= re
> already in the mempool, as we do not want a transaction's fe= es to be
> double-counted for both its individual RBF and package RBF= .

I'm unsure about the logical order of the checks proposed.
=
If A+B is submitted to replace A', where A pays 0 sats, B pays 200 = sats and A' pays 100 sats. If we apply the individual RBF on A, A+B acc= eptance fails. For this reason I think the individual RBF should be bypasse= d and only the package RBF apply ?

Note this situation is plausible= , with current LN design, your counterparty can have a commitment transacti= on with a better fee just by selecting a higher `dust_limit_satoshis` than = yours.

> Examples F and G [14] show the same package, but P1 is s= ubmitted
> individually before
> the package in example G. In e= xample F, we can see that the 300vB package
> pays
> an additio= nal 200sat in fees, which is not enough to pay for its own
> bandwidt= h
> (BIP125#4). In example G, we can see that P1 pays enough to repla= ce M1, but
> using P1's fees again during package submission woul= d make it look like a
> 300sat
> increase for a 200vB package. = Even including its fees and size would not be
> sufficient in this ex= ample, since the 300sat looks like enough for the 300vB
> package. Th= e calculcation after deduplication is 100sat increase for a
> package=
> of size 200vB, which correctly fails BIP125#4. Assume all transact= ions have
> a
> size of 100vB.

What problem are you tryi= ng to solve by the package feerate *after* dedup rule ?

My understan= ding is that an in-package transaction might be already in the mempool. The= refore, to compute a correct RBF penalty replacement, the vsize of this tra= nsaction could be discarded lowering the cost of package RBF.

If we = keep a "safe" dedup mechanism (see my point above), I think this = discount is justified, as the validation cost of node operators is paid for= ?

> The child cannot replace mempool transactions.

Let= 9;s say you issue package A+B, then package C+B', where B' is a chi= ld of both A and C. This rule fails the acceptance of C+B' ?

I t= hink this is a footgunish API, as if a package issuer send the multiple-par= ent-one-child package A,B,C,D where D is the child of A,B,C. Then try to br= oadcast the higher-feerate C'+D' package, it should be rejected. So= it's breaking the naive broadcaster assumption that a higher-feerate/h= igher-fee package always replaces ? And it might be unsafe in protocols whe= re states are symmetric. E.g a malicious counterparty broadcasts first S+A,= then you honestly broadcast S+B, where B pays better fees.

> All= mempool transactions to be replaced must signal replaceability.

I t= hink this is unsafe for L2s if counterparties have malleability of the chil= d transaction. They can block your package replacement by opting-out from R= BF signaling. IIRC, LN's "anchor output" presents such an abi= lity.

I think it's better to either fix inherited signaling or m= ove towards full-rbf.

> if a package parent has already been subm= itted, it would
> look
>like the child is spending a "new&= quot; unconfirmed input.

I think this is an issue brought by the tri= mming during the dedup phase. If we preserve the package integrity, only re= -using the tx-level checks results of already in-mempool transactions to ga= in in CPU time we won't have this issue. Package childs can add unconfi= rmed inputs as long as they're in-package, the bip125 rule2 is only eva= luated against parents ?

> However, we still achieve the same goa= l of requiring the
> replacement
> transactions to have a ances= tor score at least as high as the original
> ones.

I'm not= sure if this holds...

Let's say you have in-mempool A, B where = A pays 10 sat/vb for 100 vbytes and B pays 10 sat/vb for 100 vbytes. You ha= ve the candidate replacement D spending both A and C where D pays 15sat/vb = for 100 vbytes and C pays 1 sat/vb for 1000 vbytes.

Package A + B an= cestor score is 10 sat/vb.

D has a higher feerate/absolute fee than = B.

Package A + C + D ancestor score is ~ 3 sat/vb ((A's 1000 sat= s + C's 1000 sats + D's 1500 sats) /
A's 100 vb + C's 1= 000 vb + D's 100 vb)

Overall, this is a review through the lense= s of LN requirements. I think other L2 protocols/applications
could be c= andidates to using package accept/relay such as:
* https://github.com/lightning= labs/pool
* https://github.com/discreetlogcontracts/dlcspecs=
* https://github.com/bitcoin-teleport/teleport-transactio= ns/
* https://github.com/sapio-lang/sapio
* https://github.com/commerceblock/mercury/blob/master/doc/statechains.md
*
https://github.com/revault/practical-revault

Thanks for r= olling forward the ball on this subject.

Antoine

Le=C2=A0jeu. 16 = sept. 2021 =C3=A0=C2=A003:55, Gloria Zhao via bitcoin-dev <bitcoin-dev@l= ists.linuxfoundation.org> a =C3=A9crit=C2=A0:
Hi there,

I= 9;m writing to propose a set of mempool policy changes to enable packagevalidation (in preparation for package relay) in Bitcoin Core. These would= not
be consensus or P2P protocol changes. However, since mempool policy=
significantly affects transaction propagation, I believe this is releva= nt for
the mailing list.

My proposal enables packages consisting = of multiple parents and 1 child. If you
develop software that relies on = specific transaction relay assumptions and/or
are interested in using pa= ckage relay in the future, I'm very interested to hear
your feedback= on the utility or restrictiveness of these package policies for
your us= e cases.

A draft implementation of this proposal can be found in [Bi= tcoin Core
PR#22290][1].

An illustrated version of this post can = be found at
I have also linked the images be= low.

## Background

Feel free to skip this section if you ar= e already familiar with mempool policy
and package relay terminology.
### Terminology Clarifications

* Package =3D an ordered list of= related transactions, representable by a Directed
=C2=A0 Acyclic Graph.=
* Package Feerate =3D the total modified fees divided by the total virt= ual size of
=C2=A0 all transactions in the package.
=C2=A0 =C2=A0 - M= odified fees =3D a transaction's base fees + fee delta applied by the u= ser
=C2=A0 =C2=A0 =C2=A0 with `prioritisetransaction`. As such, we expec= t this to vary across
mempools.
=C2=A0 =C2=A0 - Virtual Size =3D the = maximum of virtual sizes calculated using [BIP141
=C2=A0 =C2=A0 =C2=A0 v= irtual size][2] and sigop weight. [Implemented here in Bitcoin Core][3].=C2=A0 =C2=A0 - Note that feerate is not necessarily based on the base fee= s and serialized
=C2=A0 =C2=A0 =C2=A0 size.

* Fee-Bumping =3D use= r/wallet actions that take advantage of miner incentives to
=C2=A0 boost= a transaction's candidacy for inclusion in a block, including Child Pa= ys
for Parent (CPFP) and [BIP125][12] Replace-by-Fee (RBF). Our intentio= n in
mempool policy is to recognize when the new transaction is more eco= nomical to
mine than the original one(s) but not open DoS vectors, so th= ere are some
limitations.

### Policy

The purpose of the me= mpool is to store the best (to be most incentive-compatible
with miners,= highest feerate) candidates for inclusion in a block. Miners use
the me= mpool to build block templates. The mempool is also useful as a cache forboosting block relay and validation performance, aiding transaction relay= , and
generating feerate estimations.

Ideally, all consensus-vali= d transactions paying reasonable fees should make it
to miners through n= ormal transaction relay, without any special connectivity or
relationshi= ps with miners. On the other hand, nodes do not have unlimited
resources= , and a P2P network designed to let any honest node broadcast their
tran= sactions also exposes the transaction validation engine to DoS attacks from=
malicious peers.

As such, for unconfirmed transactions we are co= nsidering for our mempool, we
apply a set of validation rules in additio= n to consensus, primarily to protect
us from resource exhaustion and aid= our efforts to keep the highest fee
transactions. We call this mempool = _policy_: a set of (configurable,
node-specific) rules that transactions= must abide by in order to be accepted
into our mempool. Transaction &qu= ot;Standardness" rules and mempool restrictions such
as "too-l= ong-mempool-chain" are both examples of policy.

### Package Rel= ay and Package Mempool Accept

In transaction relay, we currently con= sider transactions one at a time for
submission to the mempool. This cre= ates a limitation in the node's ability to
determine which transacti= ons have the highest feerates, since we cannot take
into account descend= ants (i.e. cannot use CPFP) until all the transactions are
in the mempoo= l. Similarly, we cannot use a transaction's descendants when
conside= ring it for RBF. When an individual transaction does not meet the mempoolminimum feerate and the user isn't able to create a replacement trans= action
directly, it will not be accepted by mempools.

This limita= tion presents a security issue for applications and users relying on
tim= e-sensitive transactions. For example, Lightning and other protocols create=
UTXOs with multiple spending paths, where one counterparty's spendi= ng path opens
up after a timelock, and users are protected from cheating= scenarios as long as
they redeem on-chain in time. A key security assum= ption is that all parties'
transactions will propagate and confirm i= n a timely manner. This assumption can
be broken if fee-bumping does not= work as intended.

The end goal for Package Relay is to consider mul= tiple transactions at the same
time, e.g. a transaction with its high-fe= e child. This may help us better
determine whether transactions should b= e accepted to our mempool, especially if
they don't meet fee require= ments individually or are better RBF candidates as a
package. A combinat= ion of changes to mempool validation logic, policy, and
transaction rela= y allows us to better propagate the transactions with the
highest packag= e feerates to miners, and makes fee-bumping tools more powerful
for user= s.

The "relay" part of Package Relay suggests P2P messagin= g changes, but a large
part of the changes are in the mempool's pack= age validation logic. We call this
*Package Mempool Accept*.

### = Previous Work

* Given that mempool validation is DoS-sensitive and c= omplex, it would be
=C2=A0 dangerous to haphazardly tack on package vali= dation logic. Many efforts have
been made to make mempool validation les= s opaque (see [#16400][4], [#21062][5],
[#22675][6], [#22796][7]).
* = [#20833][8] Added basic capabilities for package validation, test accepts o= nly
=C2=A0 (no submission to mempool).
* [#21800][9] Implemented pack= age ancestor/descendant limit checks for arbitrary
=C2=A0 packages. Stil= l test accepts only.
* Previous package relay proposals (see [#16401][10= ], [#19621][11]).

### Existing Package Rules

These are in mas= ter as introduced in [#20833][8] and [#21800][9]. I'll consider
them= as "given" in the rest of this document, though they can be chan= ged, since
package validation is test-accept only right now.

1. A= package cannot exceed `MAX_PACKAGE_COUNT=3D25` count and
`MAX_PACKAGE_S= IZE=3D101KvB` total size [8]

=C2=A0 =C2=A0*Rationale*: This is alrea= dy enforced as mempool ancestor/descendant limits.
Presumably, transacti= ons in a package are all related, so exceeding this limit
would mean tha= t the package can either be split up or it wouldn't pass this
mempoo= l policy.

2. Packages must be topologically sorted: if any dependenc= ies exist between
transactions, parents must appear somewhere before chi= ldren. [8]

3. A package cannot have conflicting transactions, i.e. n= one of them can spend
the same inputs. This also means there cannot= be duplicate transactions. [8]

4. When packages are ev= aluated against ancestor/descendant limits in a test
accept, the union o= f all of their descendants and ancestors is considered. This
is essentia= lly a "worst case" heuristic where every transaction in the packa= ge
is treated as each other's ancestor and descendant. [8]
Packa= ges for which ancestor/descendant limits are accurately captured by this
heuristic: [19]

There are also limitations such as the fact = that CPFP carve out is not applied
to package transactions. #20833 also = disables RBF in package validation; this
proposal overrides that to allo= w packages to use RBF.

## Proposed Changes

The next step in t= he Package Mempool Accept project is to implement submission
to mempool,= initially through RPC only. This allows us to test the submission
logic= before exposing it on P2P.

### Summary

- Packages may contai= n already-in-mempool transactions.
- Packages are 2 generations, Multi-P= arent-1-Child.
- Fee-related checks use the package feerate. This means = that wallets can
create a package that utilizes CPFP.
- Parents are a= llowed to RBF mempool transactions with a set of rules similar
=C2=A0 to= BIP125. This enables a combination of CPFP and RBF, where a
transaction= 's descendant fees pay for replacing mempool conflicts.

There is= a draft implementation in [#22290][1]. It is WIP, but feedback is
alway= s welcome.

### Details

#### Packages May Contain Already-in-M= empool Transactions

A package may contain transactions that are alre= ady in the mempool. We remove
("deduplicate") those transactio= ns from the package for the purposes of package
mempool acceptance. If a= package is empty after deduplication, we do nothing.

*Rationale*: M= empools vary across the network. It's possible for a parent to be
ac= cepted to the mempool of a peer on its own due to differences in policy and=
fee market fluctuations. We should not reject or penalize the entire pa= ckage for
an individual transaction as that could be a censorship vector= .

#### Packages Are Multi-Parent-1-Child

Only packages of a s= pecific topology are permitted. Namely, a package is exactly
1 child wit= h all of its unconfirmed parents. After deduplication, the package
may b= e exactly the same, empty, 1 child, 1 child with just some of its
unconf= irmed parents, etc. Note that it's possible for the parents to be indir= ect
descendants/ancestors of one another, or for parent and child to sha= re a parent,
so we cannot make any other topology assumptions.

*R= ationale*: This allows for fee-bumping by CPFP. Allowing multiple parentsmakes it possible to fee-bump a batch of transactions. Restricting packag= es to a
defined topology is also easier to reason about and simplifies t= he validation
logic greatly. Multi-parent-1-child allows us to think of = the package as one big
transaction, where:

- Inputs =3D all the i= nputs of parents + inputs of the child that come from
=C2=A0 confirmed U= TXOs
- Outputs =3D all the outputs of the child + all outputs of the par= ents that
=C2=A0 aren't spent by other transactions in the package
Examples of packages that follow this rule (variations of example A s= how some
possibilities after deduplication): ![image][15]

#### Fe= e-Related Checks Use Package Feerate

Package Feerate =3D the total m= odified fees divided by the total virtual size of
all transactions in th= e package.

To meet the two feerate requirements of a mempool, i.e., = the pre-configured
minimum relay feerate (`minRelayTxFee`) and dynamic m= empool minimum feerate, the
total package feerate is used instead of the= individual feerate. The individual
transactions are allowed to be below= feerate requirements if the package meets
the feerate requirements. For= example, the parent(s) in the package can have 0
fees but be paid for b= y the child.

*Rationale*: This can be thought of as "CPFP withi= n a package," solving the
issue of a parent not meeting minimum fee= s on its own. This allows L2
applications to adjust their fees at broadc= ast time instead of overshooting or
risking getting stuck/pinned.
We use the package feerate of the package *after deduplication*.

*R= ationale*: =C2=A0It would be incorrect to use the fees of transactions that= are
already in the mempool, as we do not want a transaction's fees = to be
double-counted for both its individual RBF and package RBF.
Examples F and G [14] show the same package, but P1 is submitted individua= lly before
the package in example G. In example F, we can see that the 3= 00vB package pays
an additional 200sat in fees, which is not enough to p= ay for its own bandwidth
(BIP125#4). In example G, we can see that P1 pa= ys enough to replace M1, but
using P1's fees again during package su= bmission would make it look like a 300sat
increase for a 200vB package. = Even including its fees and size would not be
sufficient in this example= , since the 300sat looks like enough for the 300vB
package. The calculca= tion after deduplication is 100sat increase for a package
of size 200vB,= which correctly fails BIP125#4. Assume all transactions have a
size of = 100vB.

#### Package RBF

If a package meets feerate requiremen= ts as a package, the parents in the
transaction are allowed to replace-b= y-fee mempool transactions. The child cannot
replace mempool transaction= s. Multiple transactions can replace the same
transaction, but in order = to be valid, none of the transactions can try to
replace an ancestor of = another transaction in the same package (which would thus
make its input= s unavailable).

*Rationale*: Even if we are using package feerate, a= package will not propagate
as intended if RBF still requires each indiv= idual transaction to meet the
feerate requirements.

We use a set = of rules slightly modified from BIP125 as follows:

##### Signaling (= Rule #1)

All mempool transactions to be replaced must signal replace= ability.

*Rationale*: Package RBF signaling logic should be the same= for package RBF and
single transaction acceptance. This would be update= d if single transaction
validation moves to full RBF.

##### New U= nconfirmed Inputs (Rule #2)

A package may include new unconfirmed in= puts, but the ancestor feerate of the
child must be at least as high as = the ancestor feerates of every transaction
being replaced. This is contr= ary to BIP125#2, which states "The replacement
transaction may only= include an unconfirmed input if that input was included in
one of the o= riginal transactions. (An unconfirmed input spends an output from a
curr= ently-unconfirmed transaction.)"

*Rationale*: The purpose of BI= P125#2 is to ensure that the replacement
transaction has a higher ancest= or score than the original transaction(s) (see
[comment][13]). Example H= [16] shows how adding a new unconfirmed input can lower the
ancestor sc= ore of the replacement transaction. P1 is trying to replace M1, and
spen= ds an unconfirmed output of M2. P1 pays 800sat, M1 pays 600sat, and M2 pays=
100sat. Assume all transactions have a size of 100vB. While, in isolati= on, P1
looks like a better mining candidate than M1, it must be mined wi= th M2, so its
ancestor feerate is actually 4.5sat/vB.=C2=A0 This is lowe= r than M1's ancestor
feerate, which is 6sat/vB.

In package RB= F, the rule analogous to BIP125#2 would be "none of the
transaction= s in the package can spend new unconfirmed inputs." Example J [17] sho= ws
why, if any of the package transactions have ancestors, package feera= te is no
longer accurate. Even though M2 and M3 are not ancestors of P1 = (which is the
replacement transaction in an RBF), we're actually int= erested in the entire
package. A miner should mine M1 which is 5sat/vB i= nstead of M2, M3, P1, P2, and
P3, which is only 4sat/vB. The Package RBF= rule cannot be loosened to only allow
the child to have new unconfirmed= inputs, either, because it can still cause us
to overestimate the packa= ge's ancestor score.

However, enforcing a rule analogous to BIP1= 25#2 would not only make Package RBF
less useful, but would also break P= ackage RBF for packages with parents already
in the mempool: if a packag= e parent has already been submitted, it would look
like the child is spe= nding a "new" unconfirmed input. In example K [18], we're
= looking to replace M1 with the entire package including P1, P2, and P3. We = must
consider the case where one of the parents is already in the mempoo= l (in this
case, P2), which means we must allow P3 to have new unconfirm= ed inputs. However,
M2 lowers the ancestor score of P3 to 4.3sat/vB, so = we should not replace M1
with this package.

Thus, the package RBF= rule regarding new unconfirmed inputs is less strict than
BIP125#2. How= ever, we still achieve the same goal of requiring the replacement
transa= ctions to have a ancestor score at least as high as the original ones. Asa result, the entire package is required to be a higher feerate mining ca= ndidate
than each of the replaced transactions.

Another note: the= [comment][13] above the BIP125#2 code in the original RBF
implementatio= n suggests that the rule was intended to be temporary.

##### Absolut= e Fee (Rule #3)

The package must increase the absolute fee of the me= mpool, i.e. the total fees
of the package must be higher than the absolu= te fees of the mempool transactions
it replaces. Combined with the CPFP = rule above, this differs from BIP125 Rule #3
- an individual transaction= in the package may have lower fees than the
=C2=A0 transaction(s) it is= replacing. In fact, it may have 0 fees, and the child
pays for RBF.
=
##### Feerate (Rule #4)

The package must pay for its own bandwid= th; the package feerate must be higher
than the replaced transactions by= at least minimum relay feerate
(`incrementalRelayFee`). Combined with t= he CPFP rule above, this differs from
BIP125 Rule #4 - an individual tra= nsaction in the package can have a lower
feerate than the transaction(s)= it is replacing. In fact, it may have 0 fees,
and the child pays for RB= F.

##### Total Number of Replaced Transactions (Rule #5)

The = package cannot replace more than 100 mempool transactions. This is identica= l
to BIP125 Rule #5.

### Expected FAQs

1. Is it possible f= or only some of the package to make it into the mempool?

=C2=A0 =C2= =A0Yes, it is. However, since we evict transactions from the mempool by
= descendant score and the package child is supposed to be sponsoring the fee= s of
its parents, the most common scenario would be all-or-nothing. This= is
incentive-compatible. In fact, to be conservative, package validatio= n should
begin by trying to submit all of the transactions individually,= and only use the
package mempool acceptance logic if the parents fail d= ue to low feerate.

2. Should we allow packages to contain already-co= nfirmed transactions?

=C2=A0 =C2=A0 No, for practical reasons. In me= mpool validation, we actually aren't able to
tell with 100% confiden= ce if we are looking at a transaction that has already
confirmed, becaus= e we look up inputs using a UTXO set. If we have historical
block data, = it's possible to look for it, but this is inefficient, not always
po= ssible for pruning nodes, and unnecessary because we're not going to do=
anything with the transaction anyway. As such, we already have the expe= ctation
that transaction relay is somewhat "stateful" i.e. nob= ody should be relaying
transactions that have already been confirmed. Si= milarly, we shouldn't be
relaying packages that contain already-conf= irmed transactions.

[1]: https://github.com/bitcoin/bitcoin/pull/22= 290
[2]: https://github.com/bitcoin/bips/blob/1f0b563738199ca= 60d32b4ba779797fc97d040fe/bip-0141.mediawiki#transaction-size-calculations<= /a>
[3]:
= https://github.com/bitcoin/bitcoin/blob/94f83534e4b771944af7d9ed0f40746f392= eb75e/src/policy/policy.cpp#L282
[4]: https://github.com/bitcoin/bi= tcoin/pull/16400
[5]: https://github.com/bitcoin/bitcoin/pull/21062=
[6]: https://github.com/bitcoin/bitcoin/pull/22675
[7]: ht= tps://github.com/bitcoin/bitcoin/pull/22796
[8]: https://github.com= /bitcoin/bitcoin/pull/20833
[9]: https://github.com/bitcoin/bitcoin= /pull/21800
[10]: https://github.com/bitcoin/bitcoin/pull/16401=
[11]: https://github.com/bitcoin/bitcoin/pull/19621
[12]: https://github.com/bitcoin/bips/blob/master/bip-0125.mediawik= i
[13]: https://github.com/bitcoin/bitcoin/pull/6871/fil= es#diff-34d21af3c614ea3cee120df276c9c4ae95053830d7f1d3deaf009a4625409ad2R11= 01-R1104
[14]: https://user-images.githubusercontent.com/25183001/133567078-075a971c-0= 619-4339-9168-b41fd2b90c28.png
[15]: https://user-images.githubusercontent.com/2518300= 1/132856734-fc17da75-f875-44bb-b954-cb7a1725cc0d.png
[16]: https://user-images.githu= busercontent.com/25183001/133567347-a3e2e4a8-ae9c-49f8-abb9-81e8e0aba224.pn= g
[17]: htt= ps://user-images.githubusercontent.com/25183001/133567370-21566d0e-36c8-483= 1-b1a8-706634540af3.png
[18]: https://user-images.githubusercontent.com/25183001/13356= 7444-bfff1142-439f-4547-800a-2ba2b0242bcb.png
[19]: https://user-images.githubusercont= ent.com/25183001/133456219-0bb447cb-dcb4-4a31-b9c1-7d86205b68bc.png
= [20]: https://user= -images.githubusercontent.com/25183001/132857787-7b7c6f56-af96-44c8-8d78-98= 3719888c19.png
_______________________________________________
bitcoin-dev mailing list
= bitcoin-dev@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mail= man/listinfo/bitcoin-dev
--0000000000000c080e05ccab6429--