Skip to content

Conversation

@stevenroose
Copy link
Contributor

Ran into this while writing a multi-chain test for Elements where I call this method more than once.

@fanquake fanquake added the Tests label Nov 26, 2018
Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

LGTM, restarted travis.

for i in range(num_nodes):
self.nodes.append(TestNode(i, get_datadir_path(self.options.tmpdir, i), rpchost=rpchost, timewait=self.rpc_timewait, bitcoind=binary[i], bitcoin_cli=self.options.bitcoincli, mocktime=self.mocktime, coverage_dir=self.options.coveragedir, extra_conf=extra_confs[i], extra_args=extra_args[i], use_cli=self.options.usecli))
numnode = len(self.nodes)
self.nodes.append(TestNode(numnode, get_datadir_path(self.options.tmpdir, numnode), rpchost=rpchost, timewait=self.rpc_timewait, bitcoind=binary[i], bitcoin_cli=self.options.bitcoincli, mocktime=self.mocktime, coverage_dir=self.options.coveragedir, extra_conf=extra_confs[i], extra_args=extra_args[i], use_cli=self.options.usecli))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, we could return the added nodes.

@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:

  • #14519 (tests: add utility to easily profile node performance with perf by jamesob)

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.

@laanwj
Copy link
Member

laanwj commented Dec 13, 2018

LGTM, though we don't need it at the moment, this is a sufficiently small and useful change I don't see any reason to consider not merging it.
utACK 98a1846

@laanwj laanwj merged commit 98a1846 into bitcoin:master Dec 13, 2018
laanwj added a commit that referenced this pull request Dec 13, 2018
98a1846 tests: Support calling add_nodes more than once (Steven Roose)

Pull request description:

  Ran into this while writing [a multi-chain test for Elements](ElementsProject/elements#458) where I call this method more than once.

Tree-SHA512: f2d698fcb560552aa5d81a4c3fbf40b7269b228b34d85a118291649ef83f8c0a30cd82a28d418237b55893bcecd538046b704e64a4d8a41f2c0aef8033dc83e5
@jnewbery
Copy link
Contributor

(sorry for the post-merge review. I only just saw this)

This isn't really safe and I suggest we revert it. add_nodes was designed to only be called once at the top of the test. The idea is that the number of required nodes is declared up front, and each node can then be stopped/started during the test.

We could relax that restriction if necessary, but I don't think it is necessary. Issues with this implementation:

  • _initialize_chain() and _initialize_chain_clean() both use the num_nodes property to create each node's directory with chainstate and wallet at the start of the test. If an extra node is added later with add_nodes() then it won't have this preconfigured directory, which will probably be unexpected and difficult to debug.
  • if add_nodes() is called later in the test with the num_nodes argument set to >1, each of the additional new nodes will have the same index (see self.nodes.append(TestNode(numnode,...)

@stevenroose. I don't think you need this for your test in ElementsProject/elements#458. You can declare the num_nodes for your test, override the setup_nodes() method to only start the ones you need at the beginning of the test, then update node.args for the nodes you want to update the arguments for before starting them.

Apologies - I should have commented the add_nodes() method more thoroughly when I added it.

@stevenroose
Copy link
Contributor Author

Yeah, without documentation, the name add_nodes suggests that you can "add" nodes with it, implying it should be able to be called more than once.

if add_nodes() is called later in the test with the num_nodes argument set to >1, each of the additional new nodes will have the same index (see self.nodes.append(TestNode(numnode,...)

That is not true, that is exactly the issue that I solved.

So yeah, regarding your first point, I setup the num_nodes variable upfront and then add the nodes one by one, because they are all (4) different.

@jnewbery
Copy link
Contributor

That is not true, that is exactly the issue that I solved.

Apologies, yes - you're right.

I believe the first point is still a problem.

pravblockc pushed a commit to pravblockc/dash that referenced this pull request Aug 3, 2021
98a1846 tests: Support calling add_nodes more than once (Steven Roose)

Pull request description:

  Ran into this while writing [a multi-chain test for Elements](ElementsProject/elements#458) where I call this method more than once.

Tree-SHA512: f2d698fcb560552aa5d81a4c3fbf40b7269b228b34d85a118291649ef83f8c0a30cd82a28d418237b55893bcecd538046b704e64a4d8a41f2c0aef8033dc83e5
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
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