Skip to content

Conversation

@jnewbery
Copy link
Contributor

@jnewbery jnewbery commented Aug 18, 2020

New contributors are often confused by the terminology in the test framework, and what the difference between a node and a peer is. To summarize:

  • a 'node' is a bitcoind instance. This is the thing whose behavior is being tested. Each bitcoind node is managed by a python TestNode object which is used to start/stop the node, manage the node's data directory, read state about the node (eg process status, log file), and interact with the node over different interfaces.
  • one of the interfaces that we can use to interact with the node is the p2p interface. Each connection to a node using this interface is managed by a python P2PInterface or derived object (which is owned by the TestNode object). We can open zero, one or many p2p connections to each bitcoind node. The node sees these connections as 'peers'.

For historic reasons, the word 'mininode' has been used to refer to those p2p interface objects that we use to connect to the bitcoind node (the code was originally taken from the 'mini-node' branch of https://github.com/jgarzik/pynode/tree/mini-node). However that name has proved to be confusing for new contributors, so rename the remaining references.

@jnewbery jnewbery changed the title Remove confusing mininode terminology test: Remove confusing mininode terminology Aug 18, 2020
@jnewbery jnewbery added the Tests label Aug 18, 2020
@fanquake fanquake requested a review from maflcko August 18, 2020 12:34
@maflcko
Copy link
Member

maflcko commented Aug 18, 2020

I think instead of mv you'll need to use git mv?

@jnewbery
Copy link
Contributor Author

I think instead of mv you'll need to use git mv?

Thanks Marco. Should be fixed now.

@jnewbery jnewbery force-pushed the 2020-08-no-mininode branch from 31244d0 to a4a2f78 Compare August 18, 2020 14:30
@amitiuttarwar
Copy link
Contributor

concept ACK! I still have to stop and think to distinguish testnode from mininode. I was skeptical about the rename to p2p, but looking at the code has convinced me it makes sense.

@practicalswift
Copy link
Contributor

Concept ACK

On behalf of future generations of Bitcoin Core contributors: thank you! :)

@dhruv
Copy link
Contributor

dhruv commented Aug 18, 2020

Concept ACK! Thank you for the PR, @jnewbery.

As a newcomer, I have started to think about mininode as "mocknode" and testnode as just "node". Since the entire network is peer-to-peer anyway, would it be valuable to avoid using that to mean mock?

@jnewbery
Copy link
Contributor Author

As a newcomer, I have started to think about mininode as "mocknode" and testnode as just "node".

Yes indeed. A P2PInterface object can be thought of as a mock node.

Since the entire network is peer-to-peer anyway, would it be valuable to avoid using that to mean mock?

In the abstract, it doesn't make sense to talk about a P2PInterface as a peer. When a bitcoind node creates a peering connection to a P2PInterface, it makes sense to call it the node's peer.

@laanwj
Copy link
Member

laanwj commented Aug 19, 2020

Concept ACK

@mzumsande
Copy link
Contributor

I'm not sure if this makes things less confusing:

In a test where our node has, in current terminology, one connection to a mininode and one to another bitcoind instance, it would in future terminology have one test framework p2p connection and another connection to a regular node, which we probably shouldn't call test framework p2p connection, even though the node would be managed by the test framework (TestNode) as well - this sounds a bit confusing too.

Since I am used to thinking of a mininode as an object first, it would help me if someone could explain where exactly the confusion with mininode was, and why a renaming to p2p or test framework p2p connection is suggested (instead of something more similar like mocknode as suggested by @dhruv).

Copy link
Member

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

(very big Concept ACK)

I added a few suggestions because I, too, have opinions for making the test framework clearer 😅 .

  1. There's almost always a better option than the test_framework.util wait_until, which does not grab the lock automatically, and doesn't have any context from the TestFramework instance.
  2. The TestNode p2p property can be misleading, especially in situations where there are multiple p2p_conns connected. It's very possible to be referring to the wrong connection when using node.p2p. Generally I think it's always better to either use the connection returned by add_p2p_connection or index into the p2ps list.

@glozow
Copy link
Member

glozow commented Aug 19, 2020

(Edited for some inaccuracies pointed out by sipa)

The main thing is that people often call mininodes "nodes" when they are not, so we want to remove that naming. I think the main thing is that we don't want people to confuse mininodes (a minimal p2p interface) with testnodes (the bitcoind node we are testing in functional tests). I was skeptical about calling it "p2p" at first as well but, right now, it sounds most sensible to me. Open to discussion.

Calling it MockNode would be even more confusing I think, because that sounds so similar to TestNode, and we often "mock" things (e.g. time) so that we can manipulate them in the functional tests. I'd even be ok with renaming TestNode to MockNode.

I can't really think of anything that mininodes do other than send/receive p2p messages. I think of mininodes as fake peers (but only when connected, as jnewbery said above) that we have full control over, and can use to elicit some behavior from the TestNode(s). But all they can do is p2p messages, nothing more, so it's incorrect to call them "__nodes". The reason I think "p2p" is an appropriate name is that they only implement that portion of node functionality. Mininodes cannot validate anything and cannot make transactions or blocks (only send them). I'm pretty sure they're only able to connect to 1 TestNode at a time. They also don't even always follow p2p protocol (which can be a conservative definition of a node) e.g. p2p_leak.py.

@sipa
Copy link
Member

sipa commented Aug 19, 2020

I don't have a strong opinion either way on the renaming, but wanted to respond to this::

But all they can do is p2p messages, nothing more, so it's incorrect to call them "__nodes".

To me, that's exactly what makes something a node: whether or not it interacts with other nodes via the P2P protocol, making it a node of the P2P network graph. Here we just have a very minimal node that doesn't do anything more than that.

@promag
Copy link
Contributor

promag commented Aug 19, 2020

@sipa so "peer" == "node"?

@sipa
Copy link
Member

sipa commented Aug 20, 2020

A peer is a node that's not yourself (and you're communicating with).

@dhruv
Copy link
Contributor

dhruv commented Aug 20, 2020

A peer is a node that's not yourself.

This comment pinpoints one source of my confusion: BitcoinTestFramework.num_nodes can set up multiple TestNode instances which are also peers and speak the P2P protocol. This then starts to imply that there are nodes in the P2P network, that are not "peers" as we use that word in the test framework.

Overall, I understand the distinction now and don't have a strong opinion either way. Just my 2c as a rookie.

@jnewbery
Copy link
Contributor Author

@gzhao408

There's almost always a better option than the test_framework.util wait_until, which does not grab the lock automatically, and doesn't have any context from the TestFramework instance.

I think this is done in #19752.

Generally I think it's always better to either use the connection returned by add_p2p_connection or index into the p2ps list.

I have no problem with that happening, but it should be in a different PR.

@jnewbery jnewbery force-pushed the 2020-08-no-mininode branch from a4a2f78 to b1d9900 Compare August 20, 2020 07:43
@jnewbery
Copy link
Contributor Author

My PR description has made this conversation a bit more abstract than it needs to be. To recenter on the changes this PR is making:

  • we have a file that contains our python implementation of a p2p stack. It contains a P2PConnection object (a low level connection to a bitcoind node's P2P interface) and a P2PInterface (a higher level object that allows us to communicate with the node's net_processing layer and register callbacks). This file is currently called mininode.py, which doesn't convey much meaning. A better name for it is p2p.py which more clearly communicates what it is and does.
  • data which can be accessed by both the test logic thread and the networking thread is guarded by a global mutex called mininode_lock. Again, that doesn't convey much meaning so rename it to p2p_lock (since it's data that is used by our p2p interface objects).
  • fix up related comments.

That's all that this PR does.

Rebased on master.

@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 20, 2020

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

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.

-BEGIN VERIFY SCRIPT-
sed -i 's/mininode_lock/p2p_lock/g' $(git grep -l "mininode_lock")
-END VERIFY SCRIPT-
-BEGIN VERIFY SCRIPT-
sed -i 's/\.mininode/\.p2p/g' $(git grep -l "mininode")
git mv test/functional/test_framework/mininode.py test/functional/test_framework/p2p.py
-END VERIFY SCRIPT-
@jnewbery jnewbery force-pushed the 2020-08-no-mininode branch from b1d9900 to bf0720c Compare August 21, 2020 14:54
@jnewbery
Copy link
Contributor Author

rebased

Copy link
Member

@glozow glozow left a comment

Choose a reason for hiding this comment

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

ACK bf0720c

@amitiuttarwar
Copy link
Contributor

changes look good, but I think there are two more uses of the word "mininode" in comments that would be nice to update

  • example_test.py L170
  • feature_block.py L56

@jnewbery jnewbery force-pushed the 2020-08-no-mininode branch from bf0720c to d5800da Compare August 25, 2020 09:04
@jnewbery
Copy link
Contributor Author

there are two more uses of the word "mininode" in comments that would be nice to update

Thanks! Not sure how I missed those. I've now removed them.

@amitiuttarwar
Copy link
Contributor

ACK d5800da

Copy link
Contributor

@kallewoof kallewoof left a comment

Choose a reason for hiding this comment

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

Big concept ACK -- the mininode stuff really confused me when I first started using the test framework.

Copy link
Contributor

@kallewoof kallewoof left a comment

Choose a reason for hiding this comment

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

Code review ACK (sans scripted diff stuff; I did review the diff-scripts but did not verify that the actual changes matched up)

A sorting nit, just for you John.

assert_greater_than_or_equal,
assert_raises,
assert_raises_rpc_error,
assert_is_hex_string,
Copy link
Contributor

Choose a reason for hiding this comment

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

i < r

Copy link
Member

Choose a reason for hiding this comment

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

i < r

youropinion

@maflcko
Copy link
Member

maflcko commented Aug 26, 2020

ACK d5800da 🚞

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

ACK d5800da5199527a366024bc80cad7fcca17d5c4a 🚞
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUiZNAwAtJbH7PHEONAA5ZbYzkGjBBwJg2v6IwplI/7lrqAlWVZdGOWX3UVZemck
y4TmNTiE4fS9PFqCPtiUgZWS61ZiATQBKG03Kma1Qelb0pvEw1JbRCdKL6NloyYl
us4dHbcPVRWRL9QzMUJg8wbRa0A4wiH5IeI6wpcE3NKKJjefFLnSOqM3nOol3Uix
h+91LJTw5SIwXNYqlejDDtuwH4+6epvPXzujlg64sTSDgN61DpLDsPjWQmMbBhkd
qZ6gGUzcUJWF7n6tGXdOMQ8bXn8jZrGl2fNOirDgbSlNg9yqp2BIwYPD02j5zoBN
Aw36dLz4cxcZFoXmbtP3Jnx6X3qOScbsJaoNw47UzYNe0R58qV2o6fmEsWNU4gTJ
D+bEiltvp4AfiZc0pAnjE0BByeT+Kx79LGgHbb9rya4njKU1aDiLxmhomTCOntqk
c5TfRYHLEEN/aqtf31vHiw8T6HIDGCLJ0WC5Ge81HXIR2ztv1rNafIPuyZRHx3iP
gDMbKONs
=lPcH
-----END PGP SIGNATURE-----

Timestamp of file with hash 3742138c33de1ea14bb6d6d607e8b47dc60b479a59a308cd01f416728eb3b9ff -

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

left some nits.

@jnewbery let me know if you want this merged or want to address the nits

I think this is rfm

from test_framework.blocktools import create_block, create_coinbase
from test_framework.messages import msg_block
from test_framework.mininode import P2PInterface, mininode_lock
from test_framework.p2p import p2p_lock, P2PInterface
Copy link
Member

Choose a reason for hiding this comment

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

P < p

This python code was modified from ArtForz' public domain half-a-node, as
found in the mini-node branch of http://github.com/jgarzik/pynode.
The P2PInterface objects interact with the bitcoind nodes under test using the
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The P2PInterface objects interact with the bitcoind nodes under test using the
The P2PInterface classes interact with the ____ nodes under test using the

I think this should say "classes" instead. Also, I am not sure about bitcoind, since it is also possible to run the tests against the gui. Though using PACKAGE_NAME here might be a bit too abstract?

@jnewbery
Copy link
Contributor Author

@jnewbery let me know if you want this merged or want to address the nits

I think this is rfm

If you think it's rfm, let's merge it now. I can fix the style comments in a follow-up.

@fanquake fanquake merged commit e80e5b3 into bitcoin:master Aug 26, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 26, 2020
d5800da [test] Remove final references to mininode (John Newbery)
5e8df33 test: resort imports (John Newbery)
85165d4 scripted-diff: Rename mininode to p2p (John Newbery)
9e2897d scripted-diff: Rename mininode_lock to p2p_lock (John Newbery)

Pull request description:

  New contributors are often confused by the terminology in the test framework, and what the difference between a _node_ and a _peer_ is. To summarize:

  - a 'node' is a bitcoind instance. This is the thing whose behavior is being tested. Each bitcoind node is managed by a python `TestNode` object which is used to start/stop the node, manage the node's data directory, read state about the node (eg process status, log file), and interact with the node over different interfaces.
  - one of the interfaces that we can use to interact with the node is the p2p interface. Each connection to a node using this interface is managed by a python `P2PInterface` or derived object (which is owned by the `TestNode` object). We can open zero, one or many p2p connections to each bitcoind node. The node sees these connections as 'peers'.

  For historic reasons, the word 'mininode' has been used to refer to those p2p interface objects that we use to connect to the bitcoind node (the code was originally taken from the 'mini-node' branch of https://github.com/jgarzik/pynode/tree/mini-node). However that name has proved to be confusing for new contributors, so rename the remaining references.

ACKs for top commit:
  amitiuttarwar:
    ACK d5800da
  MarcoFalke:
    ACK d5800da 🚞

Tree-SHA512: 2c46c2ac3c4278b6e3c647cfd8108428a41e80788fc4f0e386e5b0c47675bc687d94779496c09a3e5ea1319617295be10c422adeeff2d2bd68378e00e0eeb5de
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 24, 2021
Summary:
PR description:
> New contributors are often confused by the terminology in the test framework, and what the difference between a node and a peer is. To summarize:
> -   a 'node' is a bitcoind instance. This is the thing whose behavior is being tested. Each bitcoind node is managed by a python TestNode object which is used to start/stop the node, manage the node's data directory, read state about the node (eg process status, log file), and interact with the node over different interfaces.
> -   one of the interfaces that we can use to interact with the node is the p2p interface. Each connection to a node using this interface is managed by a python P2PInterface or derived object (which is owned by the TestNode object). We can open zero, one or many p2p connections to each bitcoind node. The node sees these connections as 'peers'.
>
> For historic reasons, the word 'mininode' has been used to refer to those p2p interface objects that we use to connect to the bitcoind node (the code was originally taken from the 'mini-node' branch of https://github.com/jgarzik/pynode/tree/mini-node). However that name has proved to be confusing for new contributors, so rename the remaining references.

> ```
> -BEGIN VERIFY SCRIPT-
> sed -i 's/mininode_lock/p2p_lock/g' $(git grep -l "mininode_lock")
> -END VERIFY SCRIPT-
> ```

This is a partial backport of [[bitcoin/bitcoin#19760 | core#19760]] [1/4]
bitcoin/bitcoin@85165d4

Backport note: I did not cherry-pick the commit, I ran the `sed` script. The only deviations from the script are style changes from the linter.

Test Plan: `ninja check-functional`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9572
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 24, 2021
Summary:
This is a partial backport of [[bitcoin/bitcoin#19760 | core#19760]] [3/4]
bitcoin/bitcoin@5e8df33

Some changes are debatable (e.g. `assert_is_hex_string` > `assert_is_hash_string`), but I think it is best to deviate as little as possible from the Core code for such minor points of detail.

Depends on D9573

Test Plan: `ninja check-functional`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9574
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 24, 2021
Summary:
This concludes backport of [[bitcoin/bitcoin#19760 | core#19760]] [4/4]
bitcoin/bitcoin@d5800da

There is a minor change to a comment that is missing in  `p2p_permissions.py` because of a new test that is not yet backported.

Test Plan: `ninja check-functional`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9575
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 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.