test: Remove confusing mininode terminology #19760

pull jnewbery wants to merge 4 commits into bitcoin:master from jnewbery:2020-08-no-mininode changing 46 files +165 −165
  1. jnewbery commented at 11:05 AM on August 18, 2020: member

    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.

  2. jnewbery renamed this:
    Remove confusing mininode terminology
    test: Remove confusing mininode terminology
    on Aug 18, 2020
  3. jnewbery added the label Tests on Aug 18, 2020
  4. fanquake requested review from MarcoFalke on Aug 18, 2020
  5. MarcoFalke commented at 2:18 PM on August 18, 2020: member

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

  6. jnewbery commented at 2:30 PM on August 18, 2020: member

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

    Thanks Marco. Should be fixed now.

  7. jnewbery force-pushed on Aug 18, 2020
  8. amitiuttarwar commented at 4:16 PM on August 18, 2020: 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.

  9. practicalswift commented at 5:25 PM on August 18, 2020: contributor

    Concept ACK

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

  10. dhruv commented at 10:28 PM on August 18, 2020: member

    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?

  11. jnewbery commented at 8:38 AM on August 19, 2020: member

    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.

  12. laanwj commented at 2:53 PM on August 19, 2020: member

    Concept ACK

  13. mzumsande commented at 4:27 PM on August 19, 2020: member

    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).

  14. in test/functional/wallet_resendwallettransactions.py:36 in a4a2f78991 outdated
      32 | @@ -33,7 +33,7 @@ def run_test(self):
      33 |          time.sleep(1.1)
      34 |  
      35 |          # Can take a few seconds due to transaction trickling
      36 | -        wait_until(lambda: node.p2p.tx_invs_received[txid] >= 1, lock=mininode_lock)
      37 | +        wait_until(lambda: node.p2p.tx_invs_received[txid] >= 1, lock=p2p_lock)
    


    glozow commented at 6:11 PM on August 19, 2020:

    I've been waiting for someone to touch these lines so I can recommend using this function I made 😂
    Avoid using the test_framework.util wait_until and also avoid using the p2p property.

            node.p2ps[0].wait_for_broadcast([txid])
    

    This requires that you don't convert txid to an int (i.e. get rid of int(..., 16)) which I think is a good thing.


    jnewbery commented at 7:13 AM on August 20, 2020:

    These all seem like fine suggestions, but out of scope for this renaming PR.

  15. in test/functional/wallet_resendwallettransactions.py:67 in a4a2f78991 outdated
      63 | @@ -64,7 +64,7 @@ def run_test(self):
      64 |          # Transaction should be rebroadcast approximately 24 hours in the future,
      65 |          # but can range from 12-36. So bump 36 hours to be sure.
      66 |          node.setmocktime(now + 36 * 60 * 60)
      67 | -        wait_until(lambda: node.p2ps[1].tx_invs_received[txid] >= 1, lock=mininode_lock)
      68 | +        wait_until(lambda: node.p2ps[1].tx_invs_received[txid] >= 1, lock=p2p_lock)
    


    glozow commented at 6:12 PM on August 19, 2020:

    Same here

            node.p2ps[1].wait_for_broadcast([txid])
    

    jnewbery commented at 7:13 AM on August 20, 2020:

    as above

  16. in test/functional/example_test.py:206 in a4a2f78991 outdated
     202 | @@ -203,13 +203,13 @@ def run_test(self):
     203 |  
     204 |          # wait_until() will loop until a predicate condition is met. Use it to test properties of the
     205 |          # P2PInterface objects.
     206 | -        wait_until(lambda: sorted(blocks) == sorted(list(self.nodes[2].p2p.block_receive_map.keys())), timeout=5, lock=mininode_lock)
     207 | +        wait_until(lambda: sorted(blocks) == sorted(list(self.nodes[2].p2p.block_receive_map.keys())), timeout=5, lock=p2p_lock)
    


    glozow commented at 6:15 PM on August 19, 2020:

    Since you're touching this line, I'd say avoid using the p2p property. Especially in example_test.py

            wait_until(lambda: sorted(blocks) == sorted(list(self.nodes[2].p2ps[0].block_receive_map.keys())), timeout=5, lock=p2p_lock)
    

    jnewbery commented at 7:13 AM on August 20, 2020:

    as above

  17. glozow commented at 6:22 PM on August 19, 2020: member

    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.
  18. glozow commented at 6:46 PM on August 19, 2020: member

    (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.

  19. sipa commented at 7:11 PM on August 19, 2020: member

    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.

  20. promag commented at 10:16 PM on August 19, 2020: member

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

  21. sipa commented at 12:21 AM on August 20, 2020: member

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

  22. dhruv commented at 1:38 AM on August 20, 2020: member

    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.

  23. DrahtBot added the label Needs rebase on Aug 20, 2020
  24. jnewbery commented at 7:12 AM on August 20, 2020: member

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

  25. jnewbery force-pushed on Aug 20, 2020
  26. jnewbery commented at 7:45 AM on August 20, 2020: member

    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.

  27. DrahtBot removed the label Needs rebase on Aug 20, 2020
  28. DrahtBot commented at 7:58 PM on August 20, 2020: member

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #19804 (test: remove confusing p2p property by gzhao408)
    • #19801 (test: check for all possible OP_CLTV fail reasons in feature_cltv.py (BIP 65) by theStack)
    • #19752 (test: Update wait_until usage in tests not to use the one from utils by slmtpz)
    • #19315 ([tests] Allow outbound & block-relay-only connections in functional tests. by amitiuttarwar)

    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.

  29. DrahtBot added the label Needs rebase on Aug 21, 2020
  30. scripted-diff: Rename mininode_lock to p2p_lock
    -BEGIN VERIFY SCRIPT-
    sed -i 's/mininode_lock/p2p_lock/g' $(git grep -l "mininode_lock")
    -END VERIFY SCRIPT-
    9e2897d020
  31. scripted-diff: Rename mininode to p2p
    -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-
    85165d4332
  32. test: resort imports 5e8df3312e
  33. jnewbery force-pushed on Aug 21, 2020
  34. jnewbery commented at 2:54 PM on August 21, 2020: member

    rebased

  35. DrahtBot removed the label Needs rebase on Aug 21, 2020
  36. amitiuttarwar commented at 9:10 PM on August 24, 2020: 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
  37. [test] Remove final references to mininode d5800da519
  38. jnewbery force-pushed on Aug 25, 2020
  39. jnewbery commented at 9:04 AM on August 25, 2020: member

    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.

  40. jnewbery deleted a comment on Aug 25, 2020
  41. amitiuttarwar commented at 7:44 PM on August 25, 2020: contributor

    ACK d5800da519

  42. kallewoof commented at 2:02 AM on August 26, 2020: member

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

  43. in test/functional/rpc_blockchain.py:43 in 5e8df3312e outdated
      40 | +    assert_equal,
      41 | +    assert_greater_than,
      42 | +    assert_greater_than_or_equal,
      43 | +    assert_raises,
      44 | +    assert_raises_rpc_error,
      45 | +    assert_is_hex_string,
    


    kallewoof commented at 2:04 AM on August 26, 2020:

    i < r


    sipa commented at 3:11 AM on August 26, 2020:

    i < r

    youropinion

  44. kallewoof commented at 2:05 AM on August 26, 2020: member

    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.

  45. MarcoFalke commented at 5:08 AM on August 26, 2020: member

    ACK d5800da5199527a366024bc80cad7fcca17d5c4a 🚞

    <details><summary>Show signature and timestamp</summary>

    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 -

    </details>

  46. in test/functional/feature_versionbits_warning.py:15 in d5800da519
      11 | @@ -12,7 +12,7 @@
      12 |  
      13 |  from test_framework.blocktools import create_block, create_coinbase
      14 |  from test_framework.messages import msg_block
      15 | -from test_framework.mininode import P2PInterface, mininode_lock
      16 | +from test_framework.p2p import p2p_lock, P2PInterface
    


    MarcoFalke commented at 5:09 AM on August 26, 2020:

    P < p

    <img src="https://upload.wikimedia.org/wikipedia/commons/c/cf/USASCII_code_chart.png"></img>

  47. in test/functional/test_framework/p2p.py:9 in d5800da519
       3 | @@ -4,10 +4,14 @@
       4 |  # Copyright (c) 2010-2020 The Bitcoin Core developers
       5 |  # Distributed under the MIT software license, see the accompanying
       6 |  # file COPYING or http://www.opensource.org/licenses/mit-license.php.
       7 | -"""Bitcoin P2P network half-a-node.
       8 | +"""Test objects for interacting with a bitcoind node over the p2p protocol.
       9 |  
      10 | -This python code was modified from ArtForz' public domain half-a-node, as
      11 | -found in the mini-node branch of http://github.com/jgarzik/pynode.
      12 | +The P2PInterface objects interact with the bitcoind nodes under test using the
    


    MarcoFalke commented at 5:11 AM on August 26, 2020:
    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?

  48. MarcoFalke commented at 5:12 AM on August 26, 2020: member

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

    I think this is rfm

  49. jnewbery commented at 7:14 AM on August 26, 2020: member

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

  50. fanquake merged this on Aug 26, 2020
  51. fanquake closed this on Aug 26, 2020

  52. sidhujag referenced this in commit 996def89b9 on Aug 26, 2020
  53. Fabcien referenced this in commit a514e5c8c8 on May 24, 2021
  54. Fabcien referenced this in commit 4c832e8e98 on May 24, 2021
  55. deadalnix referenced this in commit a11aba3347 on May 24, 2021
  56. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-17 06:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me