Skip to content

Conversation

@theStack
Copy link
Contributor

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:

  • 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 test: Reduce number of blocks generated in rpc_signrawtransaction #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); 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

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()`.
@DrahtBot DrahtBot added the Tests label Jul 26, 2021
@laanwj
Copy link
Member

laanwj commented Jul 26, 2021

Concept and tested ACK. All tests pass now. Fixes #22542.

Copy link
Contributor

@rajarshimaitra rajarshimaitra left a 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.

@theStack theStack force-pushed the 202107-test-improve_test_signing_with_csv_cltv_subtests branch from 4f62060 to 125e83f Compare July 26, 2021 13:19
@theStack
Copy link
Contributor Author

Force-pushed with the following changes:

  • fixed a logical flaw in the generate_to_height: instead of calling generate with at most 200 blocks, it was called with a minimum of 200 blocks (changed max(...) to min(...) now)
  • using the test-framework generate helper instead of generatetoaddress RPC, also add an assert after, as suggested by MarcoFalke
  • put the CSV/CLTV soft-fork activation height constants into blocktools.py as suggested by rajarshimaitra and laanwj

theStack added 2 commits July 27, 2021 00:14
…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.
@theStack theStack force-pushed the 202107-test-improve_test_signing_with_csv_cltv_subtests branch from 125e83f to 12f094e Compare July 26, 2021 22:16
@theStack
Copy link
Contributor Author

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 current_height variable, and another time at the end for the assertion that checks that we really reached the desired block height.

Copy link
Contributor

@rajarshimaitra rajarshimaitra left a 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))
Copy link
Member

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.

@laanwj
Copy link
Member

laanwj commented Jul 27, 2021

Code review and tested ACK 12f094e

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 27, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

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.

Copy link
Member

@jonatack jonatack left a 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
Copy link
Member

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.

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 28, 2021
…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
@theStack theStack deleted the 202107-test-improve_test_signing_with_csv_cltv_subtests branch July 31, 2021 20:03
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants