Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Jul 31, 2024

Unlike other function calls in default arguments, CScript should not cause any issues in the tests, because they are const.

However, this change allows to enable the "function-call-in-default-argument (B008)" lint rule, which will help to catch severe test bugs, such as #30543 (comment) .

The lint rule will be enabled in a follow-up, when all violations are fixed.

…natureMsg

This removes the default value, because there should not be a use-case
to fall back to a an empty leaf_script by default. (If there was, it
could trivially be added back)
@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 31, 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
ACK instagibbs, theStack, ismaelsadeeq

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

@DrahtBot DrahtBot changed the title test: Avoid CScript() as default function argument test: Avoid CScript() as default function argument Jul 31, 2024
@DrahtBot DrahtBot added the Tests label Jul 31, 2024
@maflcko maflcko force-pushed the 2407-test-cscript branch 2 times, most recently from faf81f0 to fa33f64 Compare July 31, 2024 08:50
This does not cause any issues, because CScript in the tests are const.
However, this change allows to enable the
"function-call-in-default-argument (B008)" lint rule.
@maflcko maflcko force-pushed the 2407-test-cscript branch from fa33f64 to fa46a1b Compare July 31, 2024 13:19
Copy link
Member

@instagibbs instagibbs left a comment

Choose a reason for hiding this comment

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

utACK fa46a1b

(didn't run the linter check)

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

lgtm ACK fa46a1b

@Thoragh
Copy link
Contributor

Thoragh commented Aug 2, 2024

Have you investigated using https://docs.astral.sh/ruff/settings/#lint_flake8-bugbear_extend-immutable-calls instead of changing the python code?

@maflcko
Copy link
Member Author

maflcko commented Aug 2, 2024

Have you investigated using https://docs.astral.sh/ruff/settings/#lint_flake8-bugbear_extend-immutable-calls instead of changing the python code?

Yes, but there is nothing that enforces that CScript remains immutable in the future. It just seems too fragile to allow it. A +18-10 test-only diff seems preferable in any case.

Copy link
Member

@ismaelsadeeq ismaelsadeeq left a comment

Choose a reason for hiding this comment

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

Tested ACK fa46a1b

Just a single question and a nit.

self.sign_tx(tx, spend_tx)
tx.rehash()
return tx

def next_block(self, number, spend=None, additional_coinbase_value=0, script=CScript([OP_TRUE]), *, version=4):
def next_block(self, number, spend=None, additional_coinbase_value=0, *, script=None, version=4):
Copy link
Member

@ismaelsadeeq ismaelsadeeq Aug 2, 2024

Choose a reason for hiding this comment

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

non-blocking nit:
since you are changed script_pub_key to output_script will be nice to be explicit here also

Suggested change
def next_block(self, number, spend=None, additional_coinbase_value=0, *, script=None, version=4):
def next_block(self, number, spend=None, additional_coinbase_value=0, *, coinbase_output_script=None, version=4):

Copy link
Member Author

Choose a reason for hiding this comment

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

Happy to push a commit, if someone creates one. Also, I am happy to review a follow-up doing this, if someone creates one, but I'll leave it as-is for now.

Comment on lines +1344 to +1345
if output_script is None:
output_script = CScript([OP_TRUE])
Copy link
Member

Choose a reason for hiding this comment

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

We are doing the same check for a None output_script in create_tx,
should we instead delete this and rely on the check in create_tx?

Suggested change
if output_script is None:
output_script = CScript([OP_TRUE])

After removing the check here and next_block the tests still passes

Copy link
Member Author

Choose a reason for hiding this comment

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

same check

No? They are different scripts.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but both are anyone-can-spend scripts. Is there a reason to prefer CScript([OP_TRUE]) for create_and_sign_transaction and next_block? We can rely on the check in create_tx to avoid redundancy ?

Copy link
Member Author

@maflcko maflcko Aug 2, 2024

Choose a reason for hiding this comment

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

Yeah, sounds good.

The reason was to avoid too small transaction sizes (See 364bae5)

Padding the others isn't needed, but it can't hurt, I guess.

Copy link
Member Author

Choose a reason for hiding this comment

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

(MIN_STANDARD_TX_NONWITNESS_SIZE was dropped in the meantime from 82 to 64, so the padding may or may not be needed)

Currently I don't have the time to check it, and it seems unrelated anyway? If you want to change the padding to make it larger or smaller, it would be a larger pull request, than just a default argument change.

@fanquake fanquake merged commit df24197 into bitcoin:master Aug 2, 2024
16 checks passed
@maflcko maflcko deleted the 2407-test-cscript branch August 2, 2024 13:03
@bitcoin bitcoin locked and limited conversation to collaborators Aug 2, 2025
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.

7 participants