Skip to content

test: Make existing functional tests compatible with --v2transport #28805

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

Merged
merged 5 commits into from
Nov 28, 2023

Conversation

mzumsande
Copy link
Contributor

@mzumsande mzumsande commented Nov 6, 2023

This makes the functional test suite compatible with BIP324, so that
python3 test_runner.py --v2transport
should succeed (currently, 12 tests fail for me on master).
Includes two commits by TheStack I found in an old discussion #28331 (comment)

Note that even though all tests should pass, the python p2p.py module will do v2 connections only after the merge of #24748, so that for now only connections between two full nodes will actually run v2.
Some of the fixed tests were added with --v2transport to the test runner. Though after #24748 we might also want to consider running the entire suite with --v2transport in some CI.

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 6, 2023

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 theStack, stratospher, sipa, achow101
Stale ACK kashifs

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:

  • #28521 (net: additional disconnect logging by Sjors)

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 Nov 6, 2023
@mzumsande
Copy link
Contributor Author

FYI @stratospher @theStack

@theStack
Copy link
Contributor

theStack commented Nov 7, 2023

Concept ACK

@maflcko
Copy link
Member

maflcko commented Nov 7, 2023

Though after #24748 we might also want to consider running the entire suite with --v2transport in some CI.

I presume this will fix itself, once and if v2 is enabled by default?

@kashifs
Copy link
Contributor

kashifs commented Nov 7, 2023

tACK 6b77f9

Read through all updated code, pulled branch, compiled from source, ran:

python3 wallet_multiwallet.py --usecli --v2transport

@DrahtBot DrahtBot requested a review from theStack November 7, 2023 14:05
@mzumsande
Copy link
Contributor Author

I presume this will fix itself, once and if v2 is enabled by default?

After enabling v2 by default for the functional tests, we'd probably still want to run some or all of the tests with -v2transport=0 to avoid regressions - so I don't think that would change much.

@maflcko
Copy link
Member

maflcko commented Nov 7, 2023

Ok, feel free to add it to any task, for example ci/test/00_setup_env_native_qt5.sh.

@mzumsande
Copy link
Contributor Author

mzumsande commented Nov 7, 2023

Ok, feel free to add it to any task, for example ci/test/00_setup_env_native_qt5.sh.

Thanks, though I won't add it to this PR.
I'm open to suggestions, but in my opinion the best way to proceed might be to first get #24748 in to upgrade the python p2p framework. I expect we will then need a similar PR to this one to fix some minor issues with the existing tests before turning it on for all tests (something I started working on), and maybe only after we should make a --v2transport task.

@stratospher
Copy link
Contributor

Nice! Concept ACK.

"Before, a global -v2transport provided to the test would be dropped when restarting the node within a test."

@mzumsande, wanted to confirm which scenario you're talking about. i tried it out in this file.

  1. when test is run with --v2transport option and TestNode (with no extra_args passed in the test) is restarted? TestNode restarted as a v2 node on both master and PR.
  2. when test is run with --v2transport option and TestNode (initially no extra_args passed) is restarted with extra_args "v2transport=0"? TestNode restarted as v1 node on master(with 2 lines modified) and restarted as v1 node on PR. is this the scenario which the PR fixes?
  3. when test is run with --v2transport option and TestNode(initially extra_args "v2transport=0") is restarted? TestNode restarted as a v2 node on both master and PR. so both master and PR doesn't seem to fix it.

@mzumsande
Copy link
Contributor Author

@mzumsande, wanted to confirm which scenario you're talking about.

I was observing that multiple following tests fail on master with --v2transport e.g. interface_zmq.pyp2p_permissions.py, feature_assumeutxo.py and some wallet tests.
These tests have in common that they use self.restart_node() with changing some unrelated extra_args, which would then cause --v2transport to be dropped.

I think the problem is as follows:

  • On first startup of a node, self.extra_args is set in __init__ (this inserts --v2transport into self.extra_args on master, but not in my branch, which puts the global option into self.args)
  • If --v2transport=1 in args, and also --v2transport=0 in extra_args, extra_args takes precedence (this can happen with my branch) => this is fine in my opinion.
  • When we call restart_node without specifying any extra_args, self.extra_args will be used. This is also fine.
  • When we call restart_node and do specify extra_args, self.extra_args will be ignored, and the passed extra_args will be used, together with the args. That causes the above tests on master to fail.
  • However, self.extra_args is not updated in restart_node (so another restart_node will use the original self.extra_args), and other tests rely on this behavior! So the passed extra_args are transitory and not saved, so referring to self.extra_args here is not correct when the transitory extra_args are used (this causes your CASE 2 on my branch to fail).

Does this make sense? I'll try to come up with a fix for this.

mzumsande and others added 5 commits November 8, 2023 17:30
Before, a global -v2transport provided to the test would be dropped
when restarting the node within a test and specifying any extra_args.

Fix this by adding "v2transport=1" to args (not extra_args) based
on the global parameter, and deciding for each (re)start of the node
based on this default and test-specific extra_args
(which take precedence over args) whether v2 should be used.
By renaming the "command" send_cli arg. The old name was unsuitable
because the "addnode" RPC has its own "command" arg, leading to
ambiguity when included in kwargs.
Can be tested with
"python3 wallet_multiwallet.py --usecli --v2transport"
which fails on master because of this (python throws a TypeError).
- "transport_protocol_type" of inbound peer before version handshake
  is "detecting" on p2p v2 nodes (as opposed to "v1" for p2p v1)
- size of a ping/pong message is 29 bytes (as opposed to 32 for p2p v1)
- for the sendmsgtopeer RPC sub-test, enforce p2p v1 connection to
  have a peer id of zero
by skipping the part where we send a non-version message
before the version - this message would be interpreted as
part of the v2 handshake.
@mzumsande mzumsande force-pushed the 202311_test_v2transport4all branch from 6b77f9f to 35fb993 Compare November 8, 2023 22:38
@mzumsande
Copy link
Contributor Author

I changed the first commit to save the default behavior (global --v2transport) in the TestNode init and add an entry to args, and then deciding in TestNode::start() (which is called for both the initial startup and for restarts) based on this and possible extra_args whether to actually use v2 or not.

Copy link
Contributor

@stratospher stratospher left a comment

Choose a reason for hiding this comment

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

These tests have in common that they use self.restart_node() with changing some unrelated extra_args, which would then cause --v2transport to be dropped.

thanks for the detailed explanation! so the problem was test failures happening when unrelated extra_args were passed during TestNode restart!

i was also initially confused about whether we really need an extra v2transport argument in TestNode::__init()__ but #28805 (comment) makes it clear why we need to extract that information from args for persisting global v2transport option during restarts. this information would get lost if it's passed on to extra_args like it's done in master.

@@ -198,6 +204,8 @@ def start(self, extra_args=None, *, cwd=None, stdout=None, stderr=None, env=None
if extra_args is None:
extra_args = self.extra_args

self.use_v2transport = "-v2transport=1" in extra_args or (self.default_to_v2 and "-v2transport=0" not in extra_args)
Copy link
Contributor

@stratospher stratospher Nov 10, 2023

Choose a reason for hiding this comment

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

68a9001: there's a behaviour difference when test is run with --v2transport option and TestNode(initially "v2transport=0") is restarted with:

  • extra_args supplied => TestNode restarts as v2 node
  • extra_args not supplied => TestNode restarts as v1 node

maybe when extra_args is None, we could remove "v2transport" stuff it gets from the old self.extra_args using something like extra_args = list(filter(lambda s: not s.startswith("-v2transport="), extra_args))?

EDIT: realised this won't work because during TestNode initialisation, extra_args is None and not just during restarts.

Copy link
Contributor

Choose a reason for hiding this comment

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

One small drawback of the current way of inspecting extra_args for the v2transport option is that it doesn't work if the argument is specified in a slightly different format with same meaning. For example, -v2transport=0/-v2transport=1 could also be passed as -nov2transport/-v2transport, -nov2transport=1/-nov2transport=0 (admittedly, no sane person would use the last one though). It might be worth it to consider that in a follow-up, e.g. by enforcing with an assertion that arguments that contain the string "v2transport" must be prefixed by "-" and suffixed by either "=0" or "=1". As far as I can see, that's the first time that the test framework needs to inspect bitcoind arguments, so that's a new problem.

@stratospher: I agree that this is a bit counter-intuitive, but it's in line with the current behavior of restart_node (that apparently many tests rely on), i.e. "if no extra_args are passed, restart with the ones that were initially specified (self.extra_args)", in your example -v2transport=0.

Copy link
Contributor

Choose a reason for hiding this comment

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

"if no extra_args are passed, restart with the ones that were initially specified (self.extra_args)"

oh interesting! so #28805 (comment) is out of scope for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One small drawback of the current way of inspecting extra_args for the v2transport option is that it doesn't work if the argument is specified in a slightly different format with same meaning.

Good point - I agree that it makes sense to leave this for a possible follow-up. I'm not sur if we want to port all of the argsmanager logic into python, but having something a bit more general so that it could be reused by other args than just -v2transport in the future would be nice.

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.

ACK 35fb993

@DrahtBot DrahtBot requested a review from stratospher November 11, 2023 02:56
Copy link
Contributor

@stratospher stratospher left a comment

Choose a reason for hiding this comment

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

ACK 35fb993.

@sipa
Copy link
Member

sipa commented Nov 11, 2023

utACK 35fb993. Thanks for taking care of this.

@achow101
Copy link
Member

ACK 35fb993

@achow101 achow101 merged commit 30a0557 into bitcoin:master Nov 28, 2023
@mzumsande mzumsande deleted the 202311_test_v2transport4all branch November 28, 2023 22:28
luke-jr added a commit to bitcoinknots/bitcoin that referenced this pull request Mar 5, 2024
Before, a global -v2transport provided to the test would be dropped
when restarting the node within a test and specifying any extra_args.

Fix this by adding "v2transport=1" to args (not extra_args) based
on the global parameter, and deciding for each (re)start of the node
based on this default and test-specific extra_args
(which take precedence over args) whether v2 should be used.

Github-Pull: bitcoin#28805
Rebased-From: 68a9001
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Mar 5, 2024
By renaming the "command" send_cli arg. The old name was unsuitable
because the "addnode" RPC has its own "command" arg, leading to
ambiguity when included in kwargs.
Can be tested with
"python3 wallet_multiwallet.py --usecli --v2transport"
which fails on master because of this (python throws a TypeError).

Github-Pull: bitcoin#28805
Rebased-From: 3598a1b
luke-jr added a commit to bitcoinknots/bitcoin that referenced this pull request Mar 5, 2024
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Mar 5, 2024
- "transport_protocol_type" of inbound peer before version handshake
  is "detecting" on p2p v2 nodes (as opposed to "v1" for p2p v1)
- size of a ping/pong message is 29 bytes (as opposed to 32 for p2p v1)
- for the sendmsgtopeer RPC sub-test, enforce p2p v1 connection to
  have a peer id of zero

Github-Pull: bitcoin#28805
Rebased-From: 2c1669c
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Mar 5, 2024
by skipping the part where we send a non-version message
before the version - this message would be interpreted as
part of the v2 handshake.

Github-Pull: bitcoin#28805
Rebased-From: 35fb993
kwvg added a commit to kwvg/dash that referenced this pull request Sep 17, 2024
kwvg added a commit to kwvg/dash that referenced this pull request Sep 17, 2024
kwvg added a commit to kwvg/dash that referenced this pull request Sep 17, 2024
kwvg added a commit to kwvg/dash that referenced this pull request Oct 2, 2024
kwvg added a commit to kwvg/dash that referenced this pull request Oct 9, 2024
…-v2transport

Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
kwvg added a commit to kwvg/dash that referenced this pull request Oct 14, 2024
…-v2transport

Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
kwvg added a commit to kwvg/dash that referenced this pull request Oct 15, 2024
…-v2transport

Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
kwvg added a commit to kwvg/dash that referenced this pull request Oct 15, 2024
…-v2transport

Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
PastaPastaPasta added a commit to dashpay/dash that referenced this pull request Oct 16, 2024
, bitcoin#28849, bitcoin#28805, bitcoin#28951, bitcoin#29058, bitcoin#29239, partial bitcoin#28331, bitcoin#28452 (BIP324 backports: part 2)

5dd60c4 merge bitcoin#29239: Make v2transport default for addnode RPC when enabled (Kittywhiskers Van Gogh)
b2ac426 merge bitcoin#29058: use v2transport for manual/addrfetch connections, add to -netinfo (Kittywhiskers Van Gogh)
92e862a merge bitcoin#28951: damage ciphertext/aad in full byte range (Kittywhiskers Van Gogh)
4e96e26 merge bitcoin#28805: Make existing functional tests compatible with --v2transport (Kittywhiskers Van Gogh)
9371e2e merge bitcoin#28849: fix node index bug when comparing peerinfo (Kittywhiskers Van Gogh)
400c9dd merge bitcoin#28634: add check for missing garbage terminator detection (Kittywhiskers Van Gogh)
65eb194 merge bitcoin#28588: add checks for v1 prefix matching / wrong network magic detection (Kittywhiskers Van Gogh)
6074974 merge bitcoin#28577: raise V1_PREFIX_LEN from 12 to 16 (Kittywhiskers Van Gogh)
ff92d1a partial bitcoin#28331: BIP324 integration (Kittywhiskers Van Gogh)
f9f8805 fix: drop `CConnman::mapNodesWithDataToSend`, use transport data (UdjinM6)
d39d8a4 partial bitcoin#28452: Do not use std::vector = {} to release memory (Kittywhiskers Van Gogh)

Pull request description:

  ## Additional Information

  * Dependent on #6280

  * Dependent on #6276

  * Dependency for #6329

  * [bitcoin#28452](bitcoin#28452) was backported as the behavior it introduces is required for backports like [bitcoin#28331](bitcoin#28331). As it pre-dates earlier BIP324 backports, the `ClearShrink` usage from those backports have also been incorporated into this backport.

  * When backporting [bitcoin#28331](bitcoin#28331), in TestFramework's `add_nodes()`, `extra_args[i]` is not converted to a `list` like it is done upstream and avoiding duplication of `-v2transport=1` is instead done by an additional check. This is done to prevent test failures in `feature_mnehf.py`.

  * The local variable `args` is removed in [bitcoin#28805](bitcoin#28805) as it does nothing (the argument appending logic is removed as part of the backport) and upstream removes it anyways.

  Special thanks to UdjinM6 for significant contributions to this and dependent PRs! 🎉

  ## Breaking Changes

  None expected.

  ## Checklist

  - [x] I have performed a self-review of my own code
  - [x] I have commented my code, particularly in hard-to-understand areas **(note: N/A)**
  - [x] I have added or updated relevant unit/integration/functional/e2e tests
  - [x] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

ACKs for top commit:
  UdjinM6:
    light ACK 5dd60c4
  PastaPastaPasta:
    utACK 5dd60c4

Tree-SHA512: 7f3d0e54e1c96fc99b2d6b1e64485110aa73aeec0e4e4245ed4e6dc0529a7608e9c39103af636d5945d289775c40d3d15d7d4a75bea82462194dbf355fca48dc
@bitcoin bitcoin locked and limited conversation to collaborators Nov 27, 2024
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.

8 participants