This PR adds coverage for this line https://github.com/bitcoin/bitcoin/blob/master/src/rpc/mempool.cpp#L996
If you run the following you will get no results for submitpackage
grep -nri "TX decode failed" ./test/functional
This PR adds coverage for this line https://github.com/bitcoin/bitcoin/blob/master/src/rpc/mempool.cpp#L996
If you run the following you will get no results for submitpackage
grep -nri "TX decode failed" ./test/functional
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--006a51241073e994b41acfe9ec718e94-->
For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31139.
<!--021abf342d371248e50ceaed478a90ca-->
See the guideline for information on the review process.
| Type | Reviewers |
|---|---|
| ACK | instagibbs, tdb3, rkrux, achow101 |
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
<!--174a7506f384e20aa4161008e828411d-->
Reviewers, 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.
376 | @@ -377,6 +377,10 @@ def test_submitpackage(self): 377 | self.log.info("Submitpackage only allows packages of 1 child with its parents") 378 | # Chain of 3 transactions has too many generations 379 | legacy_pool = node.getrawmempool() 380 | + 381 | + chain_hex_decode_failure = [t["hex"][:-1] + 'X' for t in self.wallet.create_self_transfer_chain(chain_length=2)]
two empty string might be simpler?
thanks! fair point updated in 4bdb78c
376 | @@ -377,6 +377,9 @@ def test_submitpackage(self): 377 | self.log.info("Submitpackage only allows packages of 1 child with its parents") 378 | # Chain of 3 transactions has too many generations 379 | legacy_pool = node.getrawmempool() 380 | + 381 | + assert_raises_rpc_error(-22, "TX decode failed:", node.submitpackage, ["", ""]) 382 | +
While I was going through this test after I checked out the branch in local, I realised that this assertion seems a bit out of context because of the comment on line 378. How about adding this assertion before line 378?
Thanks! I moved it more towards the start of the function in 34c6643
tACK 4bdb78cfe76414227b749674ed660f4972fb6eda
Make, functional tests successful. Left a small suggestion.
376 | @@ -377,6 +377,9 @@ def test_submitpackage(self): 377 | self.log.info("Submitpackage only allows packages of 1 child with its parents") 378 | # Chain of 3 transactions has too many generations 379 | legacy_pool = node.getrawmempool() 380 | + 381 | + assert_raises_rpc_error(-22, "TX decode failed:", node.submitpackage, ["", ""])
I don't think just passing two empty strings is the right way of testing it because:
Ya that makes sense!
What I did in 34c6643
Is I used a proper hex value and then had the second value malformed so that we can cover more bases
let me know if that looks good to you I can modify it other ways aswell!
it only plays with non-hex values and do not exercise the hex parsing.
an empty string is valid hex, it's just an invalid tx, no? If you want to test invalid hex that's another thing.
if the first tx is invalid, the second one has no effect.
You need two transactions currently for it to get far enough to try and deserialize. I don't really care which one(s) are valid except for ease of reading.
let me know if that looks good to you I can modify it other ways aswell!
imo having valid hex is a more realistic scenario, but coverage is coverage
would be good to double-check that the first tx doesn't make it into the mempool even if it otherwise would
Agree, having this assertion would be good because the valid tx would still not make to mempool in this case.
ok I added an assert to check for txid in getrawmempool in 1fab1d6
let me know if that looks good to you!
380 | 381 | + 382 | self.log.info("Submitpackage only allows packages of 1 child with its parents") 383 | # Chain of 3 transactions has too many generations 384 | legacy_pool = node.getrawmempool() 385 | +
Are these blank lines intentional?
I removed them in 1fab1d6
LGTM, will ACK again once @instagibbs's suggestion is also added.
<!--85328a0da195eb286784d51f73fa0af9-->
🚧 At least one of the CI tasks failed. <sub>Debug: https://github.com/bitcoin/bitcoin/runs/32095511448</sub>
<details><summary>Hints</summary>
Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
</details>
ACK 1fab1d601e40edc7296cf3d60a7e917b0e6493b3
Thanks for incorporating the changes.
368 | @@ -369,6 +369,13 @@ def test_submit_child_with_parents(self, num_parents, partial_submit): 369 | def test_submitpackage(self): 370 | node = self.nodes[0] 371 | 372 | + self.log.info("Submitpackage only allows valid hex inputs") 373 | + valid_tx_list = self.wallet.create_self_transfer_chain(chain_length=2) 374 | + hex_list = [valid_tx_list[0]["hex"][:-1] + 'X', valid_tx_list[1]["hex"]] 375 | + txid_list = [valid_tx_list[0]["txid"], valid_tx_list[1]["txid"]] 376 | + assert_raises_rpc_error(-22, "TX decode failed:", node.submitpackage, hex_list) 377 | + assert txid_list[0] not in node.getrawmempool()
assert txid_list[0] not in node.getrawmempool()
assert txid_list[1] not in node.getrawmempool()
Thanks!
Updated in d7fd766feb2f579bdba0e778bacdeb13103e8282
ACK 1fab1d601e40edc7296cf3d60a7e917b0e6493b3
with minor suggestion
368 | @@ -369,6 +369,14 @@ def test_submit_child_with_parents(self, num_parents, partial_submit): 369 | def test_submitpackage(self): 370 | node = self.nodes[0] 371 | 372 | + self.log.info("Submitpackage only allows valid hex inputs") 373 | + valid_tx_list = self.wallet.create_self_transfer_chain(chain_length=2) 374 | + hex_list = [valid_tx_list[0]["hex"][:-1] + 'X', valid_tx_list[1]["hex"]] 375 | + txid_list = [valid_tx_list[0]["txid"], valid_tx_list[1]["txid"]] 376 | + assert_raises_rpc_error(-22, "TX decode failed:", node.submitpackage, hex_list)
Induced failure with:
- hex_list = [valid_tx_list[0]["hex"][:-1] + 'X', valid_tx_list[1]["hex"]]
+ hex_list = [valid_tx_list[0]["hex"], valid_tx_list[1]["hex"]]
Also verified that the not in node.getrawmempool() asserts also fail, e.g.
self.log.info("Submitpackage only allows valid hex inputs")
valid_tx_list = self.wallet.create_self_transfer_chain(chain_length=2)
- hex_list = [valid_tx_list[0]["hex"][:-1] + 'X', valid_tx_list[1]["hex"]]
+ hex_list = [valid_tx_list[0]["hex"], valid_tx_list[1]["hex"]]
txid_list = [valid_tx_list[0]["txid"], valid_tx_list[1]["txid"]]
- assert_raises_rpc_error(-22, "TX decode failed:", node.submitpackage, hex_list)
- assert txid_list[0] not in node.getrawmempool()
+ node.submitpackage(hex_list)
+ #assert_raises_rpc_error(-22, "TX decode failed:", node.submitpackage, hex_list)
+ #assert txid_list[0] not in node.getrawmempool()
assert txid_list[1] not in node.getrawmempool()
ACK d7fd766feb2f579bdba0e778bacdeb13103e8282
Looks good, thanks. corecheck.dev shows the added coverage for mempool.cpp. Ran a few quick sanity checks.
reACK d7fd766feb2f579bdba0e778bacdeb13103e8282
ACK d7fd766feb2f579bdba0e778bacdeb13103e8282
Looks kinda sus...