-
Notifications
You must be signed in to change notification settings - Fork 37.7k
validation/refactor: refactoring for package submission #23381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest removing the following sentences from the commit logs:
- "It also prevents a bug where we swap a package transaction for a same-txid-different-wtxid mempool transaction and put the wrong virtual size in the RPC result."
- "Not doing this now would cause a bug where every package transaction could increase the descendant limit despite having unrelated conflicts, resulting in an inflated descendant limit."
I don't think writing about what bugs could be introduced in future is very informative. It's enough to say that these values are specific to individual candidate transactions, so should be kept in the Workspace
struct.
In the scripted-diff: clean up MemPoolAccept aliases commit, there are various alias members that are not removed. Was that just because it was too difficult to target them with a scripted diff, or because you think those members are special in some way?
No change in behavior. ATMPArgs can continue to have granular rules like switching BIP125 on/off while we create an interface for the different sets of rules for single transactions vs multiple-testmempoolaccept vs package validation. This is a cleaner interface than manually constructing the args, which makes it easy to mix up ordering, use the wrong default, etc. It also means we don't need to edit ATMP/single transaction validation code every time we update ATMPArgs for package validation.
We want to be able to re-use the precomputed transaction data between PolicyScriptChecks and ConsensusScriptChecks in AcceptMultipleTransactions.
This bool was originally part of Workspace and was removed in bitcoin#22539 when it was no longer needed in Finalize(). Re-introducing it because, once again, multiple functions will need to know whether we're doing an RBF. Member of MemPoolAccept so that we can use this to inform package RBF in the future.
This is not only cleaner but also helps make sure we are always using the virtual size measure that includes the sigop weight heuristic (which is the vsize the mempool would return).
f7d8be9
to
4d262e0
Compare
Thanks for the review @jnewbery, took your suggestions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 4d262e0
One suggestion inline.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall good. See the comment around the newer descendant limits members in Workspace
.
"replacement-adds-unconfirmed", *err_string); | ||
} | ||
const CTransaction& tx = *ws.m_ptx; | ||
const uint256& hash = ws.m_hash; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe good timing to rename m_hash
to m_txid_hash
or anything else to break ambiguity in prevision of wtxid acceptance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, though I would prefer to just remove m_hash
from Workspace
entirely. The hashes are already cached in the CTransaction
object, so we can just call ptx->GetHash()
and ptx->GetWitnessHash()
directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that direction is even better!
4d262e0
to
f185420
Compare
f185420
to
7b8c8bf
Compare
The aliases are leftover from a previous MOVEONLY refactor - they are unnecessary and removing them reduces the diff for splitting out mempool Checks from PreChecks, making RBF variables MemPoolAccept-wide, etc. -BEGIN VERIFY SCRIPT- unalias() { sed -i "s:\<$1\>:$2:g" src/validation.cpp; sed -i "/$2 = $2/d" src/validation.cpp; } unalias nModifiedFees ws.m_modified_fees unalias nConflictingFees ws.m_conflicting_fees unalias nConflictingSize ws.m_conflicting_size unalias setConflicts ws.m_conflicts unalias allConflicting ws.m_all_conflicting unalias setAncestors ws.m_ancestors -END VERIFY SCRIPT-
No change in behavior, because package transactions would not be going through the rbf logic in PreChecks anyway (BIP125 is currently disabled for package acceptance, see ATMPArgs). We draw the line here because each individual transaction in package validation still goes through all PreChecks. For example, checking that one's own conflicts and dependencies are disjoint (a consensus check) and individual transaction mempool ancestor/descendant limits.
Makes the test more minimal. We're just trying to test that our package sanitization logic is correct. Now that this code lives in its own function (rather than inside of AcceptMultipleTransactions), there's no need to call ProcessNewPackage to test this.
7b8c8bf
to
14cd7bf
Compare
Code review ACK 14cd7bf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review ACK 14cd7bf
My ack shouldn't weigh that much given my poor knowledge of the codebase, but the code does look cleaner and the added comments are helpful 👍
Code review ACK 14cd7bf, thanks for adding documentation and clarifying the code |
} | ||
bool MemPoolAccept::ReplacementChecks(Workspace& ws) | ||
{ | ||
AssertLockHeld(cs_main); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to add Assume/Assert(ws.m_rbf);
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, there's no harm in adding one. If safety is a concern, note that this is a no-op if m_iters_conflicting
is empty:PaysMoreThanConflicts
, GetEntriesForConflicts
, HasNoNewUnconfirmed
, and PaysForRBF
should all simply return std::nullopt
if they're called with empty or 0 inputs. So if we accidentally called this function with m_rbf
false or no conflicts, it would be some small wasted effort, but we should be okay.
Summary: > No change in behavior. > ATMPArgs can continue to have granular rules like switching BIP125 > on/off while we create an interface for the different sets of rules for > single transactions vs multiple-testmempoolaccept vs package validation. > This is a cleaner interface than manually constructing the args, which > makes it easy to mix up ordering, use the wrong default, etc. It also > means we don't need to edit ATMP/single transaction validation code > every time we update ATMPArgs for package validation. This is a partial backport of [[bitcoin/bitcoin#23381 | core#23381]] bitcoin/bitcoin@0a79eab Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D12346
Summary: > We want to be able to re-use the precomputed transaction data between > PolicyScriptChecks and ConsensusScriptChecks in > AcceptMultipleTransactions. For Bitcoin ABC, the `PolicyScriptChecks` code is part of `PreChecks`. D8203 duplicated the initialization of the `PrecomputedTransactionData`. This patch changes it to be computed only once, and only if the cheap pre-checks are successful. This is a partial backport of [[bitcoin/bitcoin#23381 | core#23381]] bitcoin/bitcoin@cbb3598 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D12347
Summary: > This is not only cleaner but also helps make sure we are always using > the virtual size measure that includes the sigop weight heuristic (which > is the vsize the mempool would return). This is a b)rtial ackport of [[bitcoin/bitcoin#23381 | core#23381]] bitcoin/bitcoin@36a8441 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D12351
Summary: This is a partial backport of [[bitcoin/bitcoin#23381 | core#23381]] bitcoin/bitcoin@fd92b0c Test Plan: read new documentation Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D12352
Summary: > The aliases are leftover from a previous MOVEONLY refactor - they are > unnecessary and removing them reduces the diff for splitting out mempool > Checks from PreChecks, making RBF variables MemPoolAccept-wide, etc. This is a partial backport of [[bitcoin/bitcoin#23381 | core#23381]] bitcoin/bitcoin@9e910d8 Depends on D12352 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D12359
Summary: > No change in behavior This is a partial backport of [[bitcoin/bitcoin#23381 | core#23381]] bitcoin/bitcoin@c9b1439 Depends in D12359 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D12360
Summary: I also removed all the includes that are now flagged as unused by my IDE in the source file. And a unit test was renamed during the move. Otherwise, there is no change in the code. This is a partial backport of [[bitcoin/bitcoin#23381 | core#23381]] bitcoin/bitcoin@6876378 Depends on D12360 Test Plan: `ninja check` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D12361
Summary: Makes the test more minimal. We're just trying to test that our package sanitization logic is correct. Now that this code lives in its own function (rather than inside of AcceptMultipleTransactions), there's no need to call ProcessNewPackage to test this. This is a partial backport of [[bitcoin/bitcoin#23381 | core#23381]] bitcoin/bitcoin@14cd7bf Depends on D12361 Test Plan: `ninja check` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D12362
This contains the refactors and moves within #22674. There are no behavior changes, so it should be simpler to review.