-
Notifications
You must be signed in to change notification settings - Fork 37.7k
test: add check that too large txs aren't put into orphanage #30784
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
test: add check that too large txs aren't put into orphanage #30784
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. 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.
ACK 30aab71
Nice test addition. Worked well.
The ignore path is checked by asserting the debug log, which is ugly, but as far as I know there is currently no way to access the orphanage entries from the outside. As an alternative to adding test coverage, one might consider removing this check altogether (or replacing it with an Assume), as it's redundant as explained above.
RPC already has a way to get mempool transactions (e.g. getrawmempool
and getmempoolentry
), but as far as I can tell, not orphans. Unless I'm overlooking something (or there's a history I'm not aware of), might be nice to have a getorphantxs
(returning orphan txids, etc.) and getorphan "txid"
(details for an orphan). Orphans do expire relatively quickly, so results from these RPC would be pretty ephemeral, but it might still be worth knowing. I'm taking a look at implementation options.
An added bonus would be that p2p_orphan_handling
could call getorphantxs
directly (rather than search the debug log). If others agree that these new RPCs are worthwhile, then the RPCs should be implemented in a separate/followup PR, and in my opinion shouldn't impact this PR getting merged (an adjustment of the test could be done later).
# we have to explicitly allow non-standard txs to reach this code path, as otherwise | ||
# the tx is already rejected earlier with "tx-size" (see `IsStandardTx` check) | ||
self.restart_node(0, extra_args=['-acceptnonstdtxn=1']) | ||
oversize_weight = MAX_STANDARD_TX_WEIGHT + 1 |
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.
Locally modified this (to 1000) to see the assert_debug_log
check fail (missing larg_orphan_logmsg
). The assert failed as expected.
Draft PR opened #30793 |
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.
tACK 30aab71
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.
Concept ACK, but this should be a unit test, not a functional test looking for logs. We could accidentally delete the return false;
line but keep the LogPrint
line, and this test would pass.
so this is only relevant if tx standardness rules are disabled via -acceptnonstdtxns=1.
Similarly, it's a bit icky to have to disable standardness checks to test this.
A unit test in orphanage_tests.cpp could directly create a large tx and call AddTx
. With #30110, we can also test by calling MempoolRejectedTx
with a large transaction and TX_MISSING_INPUTS
.
The harder part there is adding a utility function to bulk transactions in our unit testing framework, but I think that would be quite helpful in the long run, so I'd gladly review that.
The padding method used matches the one used in MiniWallet, `MiniWallet._bulk_tx`.
30aab71
to
66d13c8
Compare
Agree! For some reason I haven't even considered doing this as a unit test, but it makes much more sense indeed.
Done as suggested. (For reference, the functional test branch is still available at https://github.com/theStack/bitcoin/tree/202409-test-orphanage_large_tx_rejection-functional)
Added a new helper |
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.
ACK 66d13c8
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.
re-ACK 66d13c8
Nice unit test addition.
review ACK 66d13c8 |
This PR adds test coverage for the following check in
TxOrphanage::AddTx
, where large orphan txs are ignored in order to avoid memory exhaustion attacks:bitcoin/src/txorphanage.cpp
Lines 22 to 34 in 5abb9b1
Note that this code-path isn't reachable under normal circumstances, as txs larger than
MAX_STANDARD_TX_WEIGHT
are already rejected earlier in the course of doing the mempool standardness checks (seeMemPoolAccept::PreChecks
->IsStandardTx
->reason = "tx-size";
), so this is only relevant if tx standardness rules are disabled via-acceptnonstdtxns=1
. The ignore path is checkedby asserting the debug log, which is ugly, but as far as I know there is currently no way to access the orphanage entries from the outsidevia unit test that checks the return value ofAddTx
. As an alternative to adding test coverage, one might consider removing this check altogether (or replacing it with anAssume
), as it's redundant as explained above.