Skip to content

Conversation

@theStack
Copy link
Contributor

@theStack theStack commented Aug 18, 2021

On single-core machines, executing the test feature_nulldummy.py results in the following assertion error:

    ...
    2021-08-18T15:37:58.805000Z TestFramework (INFO): Test 4: Non-NULLDUMMY base multisig transaction is invalid after activation
    2021-08-18T15:37:58.814000Z TestFramework (ERROR): Assertion failed
    Traceback (most recent call last):
      File "[...]/test/functional/test_framework/test_framework.py", line 131, in main
        self.run_test()
      File "[...]/test/functional/feature_nulldummy.py", line 107, in run_test
        self.block_submit(self.nodes[0], [test4tx], accept=False)
      File "[...]/test/functional/feature_nulldummy.py", line 134, in block_submit
        assert_equal(None if accept else 'block-validation-failed', node.submitblock(block.serialize().hex()))
      File "[...]/test/functional/test_framework/util.py", line 49, in assert_equal
        raise AssertionError("not(%s)" % " == ".join(str(arg) for arg in (thing1, thing2) + args))
    AssertionError: not(block-validation-failed == non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero))
    2021-08-18T15:37:58.866000Z TestFramework (INFO): Stopping nodes
    ...

There are hardly any single-core machines around anymore, but the behaviour can be reproduced on a multi-core machine by patching the function GetNumCores() to return 1 on the master branch and running feature_nulldummy.py:

diff --git a/src/util/system.cpp b/src/util/system.cpp
index 30d410381..149b512fc 100644
--- a/src/util/system.cpp
+++ b/src/util/system.cpp
@@ -1338,7 +1338,7 @@ bool SetupNetworking()

 int GetNumCores()
 {
-    return std::thread::hardware_concurrency();
+    return 1;
 }

As solution, parallel script verification is disabled (-par=1) and the exact reject reason is checked, which also increases the precision of the test (the possibility that the block is rejected because of another unintended reason is ruled out). See also related PR #22711 which applies the same approach for the p2p segwit test. The PR also includes a refactoring commit which changes the calls to self.block_submit() to use named arguments and removes the default value for parameter accept (i.e. explicitely passing accept=... is mandatory), with the aim to increase the test readability.

@DrahtBot DrahtBot added the Tests label Aug 18, 2021
@DrahtBot
Copy link
Contributor

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #20892 (tests: Run both descriptor and legacy tests within a single test invocation by achow101)

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

@josibake josibake left a comment

Choose a reason for hiding this comment

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

Concept ACK

all for improving test precision by using specific error messages. i was unable, however, to reproduce the issue. i re-compiled with the change suggested in the description (return 1) and ran the test with and without -par=1. it passed both times, but maybe im not doing something right?

id also suggest renaming the first commit as a refactor and updating the description to note you are fixing the test and doing a small refactor. without that context, its a little confusing as to why the arguments are changing

Comment on lines +27 to +30
Copy link
Member

Choose a reason for hiding this comment

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

nit: style only change, not a big deal since this is a very small pr

@josibake
Copy link
Member

i was unable, however, to reproduce the issue

sorry, i misunderstood the instructions. i was able to reproduce by doing the following: re-compile with the suggested change AND use the old error message block-validation-failed. i then re-compiled normally, changed the error message to the new message and ran without -par=1 to confirm i also got a failure.

using the more precise error message + par=1 definitely makes sense 👍

On single-core machines, executing the test feature_nulldummy.py results in
the following assertion error:

...
2021-08-18T15:37:58.805000Z TestFramework (INFO): Test 4: Non-NULLDUMMY base multisig transaction is invalid after activation
2021-08-18T15:37:58.814000Z TestFramework (ERROR): Assertion failed
Traceback (most recent call last):
  File "[...]/test/functional/test_framework/test_framework.py", line 131, in main
    self.run_test()
  File "[...]/test/functional/feature_nulldummy.py", line 107, in run_test
    self.block_submit(self.nodes[0], [test4tx], accept=False)
  File "[...]/test/functional/feature_nulldummy.py", line 134, in block_submit
    assert_equal(None if accept else 'block-validation-failed', node.submitblock(block.serialize().hex()))
  File "[...]/test/functional/test_framework/util.py", line 49, in assert_equal
    raise AssertionError("not(%s)" % " == ".join(str(arg) for arg in (thing1, thing2) + args))
AssertionError: not(block-validation-failed == non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero))
2021-08-18T15:37:58.866000Z TestFramework (INFO): Stopping nodes
...

The behaviour can be reproduced on a multi-core machine by simply changing the
function GetNumCores() (in src/util/system.cpp) to return 1:

int GetNumCores()
{
    return 1;
}
@theStack theStack force-pushed the 202108-test-fix_nulldummy_test_on_singlecore branch from f9fa8e1 to 7720d4f Compare August 23, 2021 16:24
@theStack
Copy link
Contributor Author

@josibake: Thanks a lot for your review! I agree that the description was a bit sloppy/confusing w.r.t. how to reproduce the issue and not mentioning the refactoring commit. I updated the PR description and force-pushed with the following changes:

@josibake
Copy link
Member

ACK 7720d4f

compiled with the PR suggestion and ensured i can reproduce the issue. re-compiled normally and verified test passes. great work on using a more specific error and improving the readability!

@Saviour1001
Copy link

Tested ACK 7720d4f

@maflcko maflcko merged commit 0492b56 into bitcoin:master Aug 26, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 28, 2021
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 26, 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.

5 participants