-
Notifications
You must be signed in to change notification settings - Fork 38.7k
test: improve test_signing_with_{csv,cltv} subtests (speed, prevent timeout)
#22550
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: improve test_signing_with_{csv,cltv} subtests (speed, prevent timeout)
#22550
Conversation
Without this check, the tests would also pass if the CSV and CLTV activation heights are not reached yet (e.g. if the .generate() calls before are removed), as the operations OP_CSV and OP_CLTV simply behave as NOPs. Also fixes a comment in the sub-test `test_signing_with_cltv()`.
|
Concept and tested ACK. All tests pass now. Fixes #22542. |
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 4f62060
Code change looks clear.
generate_to_height seems like a reasonable name to me. Maybe another one can be generate_blocks_upto.
Maybe a better place to have the activation height constants is in test_frameowrk/blocktools.py? It seems that the module already contains some constants regarding block height, so could be a natural place for them.
4f62060 to
125e83f
Compare
|
Force-pushed with the following changes:
|
…ction This will speed up the test a bit and avoid potential .generate() RPC timeouts (in sub-test `test_signing_with_cltv()`) on slower machines.
125e83f to
12f094e
Compare
|
Force-pushed again, taking laanwj's suggestion of not calling the getblockcount() RPC in the generation loop into account -- I don't think this approach has any drawbacks. The block height is now only fetched twice: once at the start of the function to initialize the |
rajarshimaitra
left a comment
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.
reACK 12f094e
| current_height = node.getblockcount() | ||
| while current_height < target_height: | ||
| nblocks = min(200, target_height - current_height) | ||
| current_height += len(node.generate(nblocks)) |
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.
Clever idea. An additional sanity assertion could be that length(result) == nblocks, as it could get in an infinite loop if generate is broken and returns nothing.
|
Code review and tested ACK 12f094e |
|
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. |
jonatack
left a comment
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.
Posthumous ACK 12f094e
|
|
||
| # Soft-fork activation heights | ||
| CLTV_HEIGHT = 1351 | ||
| CSV_ACTIVATION_HEIGHT = 432 |
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.
It may have been nice to mention the related BIP numbers (65 OP_CHECKLOCKTIMEVERIFY, 112 CHECKSEQUENCEVERIFY) here.
…tests (speed, prevent timeout) 12f094e test: use constants for CSV/CLTV activation heights in rpc_signrawtransaction (Sebastian Falbesoner) 746f203 test: introduce `generate_to_height` helper, use in rpc_signrawtransaction (Sebastian Falbesoner) e3237b1 test: check that CSV/CLTV are active in rpc_signrawtransaction (Sebastian Falbesoner) Pull request description: This PR primarily aims to solve the current RPC timeout problem for test rpc_signrawtransaction.py, as described in bitcoin#22542. In the course of that the test is also improved in other ways (see bitcoin#22542 (review)). Reviewers guideline: * In `test_signing_with_cltv()`, a comment is fixed -- it wrongly referred to CSV, it should be CLTV. * As preparation, assertions are added that ensure that CSV and CLTV have been really activated after generating blocks by checking the 'softforks' output of the getblockchaininfo() RPC. Right now in master, one could remove (or decrease, like in bitcoin#22542) the generate calls and the test would still pass, when it shouldn't. * A helper `generate_to_height()` is introduced which improves the previous way of reaching a block height in two ways: - instead of blindly generating TH blocks to reach target block height >= TH, the current block height CH is taken into account, and only (TH - CH) are generated in total - to avoid potential RPC timeouts, the block generation is split up into multiple generatetoaddress RPC calls ([as suggested by laanwj](bitcoin#22542 (comment))); here chunks of 200 blocks have been chosen * The helper is used in the affected sub-tests, which should both speed-up the test (from ~18s to ~12s on my machine) and avoid potential timeouts * Finally, the activation constants for CSV and CLTV are used instead of using magic numbers 500 and 1500 Open questions: * Any good naming alternatives for `generate_to_height()`? Not really happy with the name, happy to hear suggestions * Where to put the CSV and CLTV activation height constants in the test_framewor folder? I guess importing constants from other tests isn't really the desired way to go ACKs for top commit: laanwj: Code review and tested ACK 12f094e rajarshimaitra: reACK bitcoin@12f094e Tree-SHA512: 14509f6d3e5a5a05d6a30a3145bb82cd96a29d9d8a589abf1944a8bf34291cde78ce711195f52e9426588dc822b3618ec9b455e057360021ae46152bb7613516
This PR primarily aims to solve the current RPC timeout problem for test rpc_signrawtransaction.py, as described in #22542. In the course of that the test is also improved in other ways (see #22542 (review)).
Reviewers guideline:
test_signing_with_cltv(), a comment is fixed -- it wrongly referred to CSV, it should be CLTV.generate_to_height()is introduced which improves the previous way of reaching a block height in two ways:Open questions:
generate_to_height()? Not really happy with the name, happy to hear suggestions