Skip to content
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 leaf_version parameter to taproot_tree_helper() #29371

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Christewart
Copy link
Contributor

@Christewart Christewart commented Feb 2, 2024

This PR adds a leaf_version parameter to taproot_tree_helper(). Previously the leaf version was hard coded, because we only currently support 1 leaf version.

Proposed soft forks such as #29221 require new leaf versions to be allocated. This PR allows the test framework to accomodate new leaf versions. This commit is also included in #29221, but in the policy of trying to avoid mega-PRs, I carved this out into a separate PR that can be merged.

This PR does not alter any test functionality, just adds a parameter and uses it across the codebase rather than hard coding the value inside of taproot_tree_helper().

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 2, 2024

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK theStack, scgbckbone
Stale ACK edilmedeiros, itornaza

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #29939 (test: add MiniWallet tagging support to avoid UTXO mixing, use in fill_mempool by theStack)

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.

@DrahtBot DrahtBot added the Tests label Feb 2, 2024
@Christewart Christewart marked this pull request as ready for review February 2, 2024 18:54
@edilmedeiros
Copy link
Contributor

edilmedeiros commented Feb 5, 2024

Tested ACK fe53feb

I've run test/functional/feature_taproot.py and test/functional/wallet_taproot.py.

The changes make sense in preparation for future expansions, as said.
They don't alter current test logic.

assert isinstance(script, tuple)
version = LEAF_VERSION_TAPSCRIPT
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is where the previous hard coded value was that the parameter is replacing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you don't change the hardcoded value 0xc0, just pass it with function calls.
It does make sense to generalize taproot_tree_helper and taproot_construct.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with taproot, but do you think it does make sense to add a test to check if someone is passing the correct version constants to the functions (maybe in a new PR, since this one is more like refactoring code)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you probably need to understand Taproot at least a bit to understand why we aren't changing the hard coded constant 0xc0 for now. I would recommend taking a look at #29221 to understand what a new using a new leaf version looks like.

https://github.com/bitcoin/bitcoin/pull/29221/files#diff-0d2e316fe5f2581b35d1703cfebba67e58b06d12edcea7262eb98f41e50410efR64

Copy link

@scgbckbone scgbckbone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

test/functional/test_framework/script.py Outdated Show resolved Hide resolved
@Christewart
Copy link
Contributor Author

Christewart commented Feb 6, 2024

I believe this CI failure is spurious: https://github.com/bitcoin/bitcoin/pull/29371/checks?check_run_id=21277712706

Could someone restart the job ( 🙏 ) or I can push an empty commit to restart everything.

@theStack
Copy link
Contributor

Concept ACK

In order to avoid changes in functional tests and keep the patch small and simple, it probably would makes sense to set LEAF_VERSION_TAPSCRIPT as default value for parameter leaf_version for taproot_construct()?

@Christewart
Copy link
Contributor Author

Christewart commented Mar 12, 2024

In order to avoid changes in functional tests and keep the patch small and simple, it probably would makes sense to set LEAF_VERSION_TAPSCRIPT as default value for parameter leaf_version for taproot_construct()?

This is more philsophical, but I really prefer not to provide default parameters to critical test code like this. It is SO easy to just forget to pass a parameter and have your test cases not test all possible branches of code! In this case, when dealing with consensus critical test cases, I think it should be required that the developer of the unit test pass in the tapscript version they are intending to test rather than us just assuming they want to test LEAF_VERSION_TAPSCRIPT.

Please see #29221 for examples of this. For instance if I forgot to pass LEAF_VERSION_TAPSCRIPT_64BIT in a specific spot I believe my tests would trivially pass because it is a soft fork!

Reasonable minds can differ of course, for future readers of the PR leave a comment or give me a 👎 if you disagree and would like to see the default parameter used in this case. If it is clear that I'm in the minority, I will change it.

@itornaza
Copy link

itornaza commented Apr 10, 2024

tested ACK 1ccd751

  • Did a code review and everything lgtm
  • Built the PR with --with-incompatible-bdb and --enable-surpress-external-warnings
  • Run unit tests with make check and alll tests pass
  • Run functional tests with no extra flags and all tests pass
  • Run extended functional tests with --extended all tests pass

Reasonable minds can differ of course, for future readers of the PR leave a comment or give me a 👎 if you disagree and would like to see the default parameter used in this case. If it is clear that I'm in the minority, I will change it.

Who am I to say, but I philosophically agree with your reasoning on not passing default parameters in critical test code.

Copy link

@scgbckbone scgbckbone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-ACK (I'm pro default function parameter)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants