-
Notifications
You must be signed in to change notification settings - Fork 37.8k
[tests] [demonstration] Simplify/clarify the NodeConn/NodeConnCB mininode classes #11518
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
Conversation
p2p connections can now be added to TestNode instances.
mininode.py wildcard imports all names from primitives.py. This is to avoid having to change all test scripts that import from mininode.py.
Removes the dead deliver_sleep_time and EarlyDisconnectError code
BIP31 support was added to Bitcoin Core in version 0.6.1. Our test framework is incompatible with Bitcoin Core versions that old, so remove all special logic for handling pre-BIP31 pings.
Mostly move only. Adds a few extra comments.
The mininode module includes code to support p2p versions below 60001. However, the test_framework does not support versions of Bitcoin Core before V0.13.0. Remove code supporting p2p versions before 60001 (which has never been run).
Alert messages were removed in p2p version 70013 (Bitcoin Core V0.13.0)
It's only used in a helper method in p2p-segwit.py. Change that helper method to a function which takes a node and a p2p connection as arguments.
This adds documentation explaining the separation between NodeConn (representing the low-level connection and P2P header parsing) from NodeConnCB (representing the higher level P2P payload processing and convenience methods). This commit also removes the ping keepalive logic. No tests run for more than 30 minutes, so this logic is never exercised.
This makes NodeConnCB a subclass of NodeConn, and removes the need for the client code to know anything about the implementation details of NodeConnCB. NodeConn can now be swapped out for any other implementation of a low-level connection without changing client code.
This commit moves the logic that sends a version message on connection from NodeConn to NodeConnCB. NodeConn should not be aware of the semantics or meaning of the P2P payloads.
NodeConn -> P2PConnection NodeConnCB -> P2PInterface
d28f36d
to
293459a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK. Looks good!
|
||
MAX_INV_SZ = 50000 | ||
MAX_BLOCK_BASE_SIZE = 1000000 | ||
from test_framework.primitives import * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we want to avoid *
imports or is this a case that merits exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's ugly. See the commit message for 64d947b:
mininode.py wildcard imports all names from primitives.py. This is
to avoid having to change all test scripts that import from mininode.py.
I don't like wildcard imports, but we're pretty lax about them in the functional tests, so this isn't making things much worse.
(I'd be happy to remove wildcard imports entirely and have tried to do that before in #9876 and #9943)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, thanks for the pointer. I'd be happy to help with this after the more important P2P*
changes are merged (unless there's some good reason to do the two simultaneously).
fb00c45 [tests] Explicitly disallow support for p2p versions below 60001 (John Newbery) 3858aab [tests] Remove support for p2p alert messages (John Newbery) c0b1274 [tests] Remove support for bre-BIP31 ping messages (John Newbery) 2904e30 [tests] Remove dead code from mininode.py (John Newbery) Pull request description: This is the first part of #11518. It removes a ~150 lines of unused code from the mininode module: - remove unused `deliver_sleep_time` and `EarlyDisconnectError` code - remove support for pre-BIP31 ping messages - remove support for alert message - explicitly don't support p2p versions lower than 60001 Should be an easy ACK for reviewers. If all extended tests pass, then this code really was dead :) Tree-SHA512: 508e612ceb0b094250d18e75522d51e6b14cd069443050ba4af34d6f890c58721cb5653e8bc000b60635b9474d035b0dcd9c509c0dcdb3a7501df17b787f83b0
Added #11648 for the next step. |
#11677 covers removing the |
1135c79 [tests] Tidy up mininode.py module (John Newbery) f9cd9b1 [tests] Move test_framework Bitcoin primitives into separate module (John Newbery) Pull request description: Second part of #11518. Moves the primitive Bitcoin datastructures and message classes into their own module, and tidies up the mininode.py module. - First commit is almost entirely move-only - Second commit is mostly move-only, but also does a little tidying. Tree-SHA512: 5d74802677f1ab788e43188653106a96fffd9ab1fe3aa6a4eb94e5807de5dd5c8ee212296f45e8d16c7e3d95cfc4891677e812b7944bd3ab604e04b3b88aa06e
Opened #11712 for splitting |
e9dfa9b [tests] Move version message sending from NodeConn to NodeConnCB (John Newbery) dad596f [tests] Make NodeConnCB a subclass of NodeConn (John Newbery) e30d404 [tests] Move only: move NodeConnCB below NodeConn (John Newbery) 4d50598 [tests] Tidy up mininode (John Newbery) f2ae6f3 [tests] Remove mininode periodic (half-hour) ping messages (John Newbery) ec59523 [tests] Remove rpc property from TestNode in p2p-segwit.py. (John Newbery) Pull request description: This is the final step in #11518, except for possibly renaming - for motivation, please see that PR. If this is merged, then migrating the test framework from asyncore to asyncio should be easier (I say should because I haven't dug too deeply into what would be required). Requesting review from @ryanofsky , since he always has good feedback on these refactor PRs, and I'd appreciate his take on this refactor. Note particularly that I've reverted the change suggested here: #11182 (comment) . The idea, as always, is to present a simple interface to the test writer. Tree-SHA512: 94dd467a13ec799b101108cf47d4dccb6f6240b601e375e3d785313333bbb389c26072a50759aca663bbf3d6c8b867b99e36ae8800ab8ea115e0496c151926ce
Opened #11791 to rename NodeConn and NodeConnCB. Closing this PR since that's the last task here. |
873beca [tests] Rename NodeConn and NodeConnCB (John Newbery) Pull request description: Final step in #11518 NodeConn -> P2PConnection NodeConnCB -> P2PInterface This is basically just a rename. Should be an easy review. Tree-SHA512: fe1204b2b3d8182c5e324ffa7cb4099a47ef8536380e0bb9d37a5fccf76a24f548d1f1a7988ab8f830986a3058b670696de3fc891af5e5f75dbeb4e3273005d7
fb00c45 [tests] Explicitly disallow support for p2p versions below 60001 (John Newbery) 3858aab [tests] Remove support for p2p alert messages (John Newbery) c0b1274 [tests] Remove support for bre-BIP31 ping messages (John Newbery) 2904e30 [tests] Remove dead code from mininode.py (John Newbery) Pull request description: This is the first part of bitcoin#11518. It removes a ~150 lines of unused code from the mininode module: - remove unused `deliver_sleep_time` and `EarlyDisconnectError` code - remove support for pre-BIP31 ping messages - remove support for alert message - explicitly don't support p2p versions lower than 60001 Should be an easy ACK for reviewers. If all extended tests pass, then this code really was dead :) Tree-SHA512: 508e612ceb0b094250d18e75522d51e6b14cd069443050ba4af34d6f890c58721cb5653e8bc000b60635b9474d035b0dcd9c509c0dcdb3a7501df17b787f83b0
1135c79 [tests] Tidy up mininode.py module (John Newbery) f9cd9b1 [tests] Move test_framework Bitcoin primitives into separate module (John Newbery) Pull request description: Second part of bitcoin#11518. Moves the primitive Bitcoin datastructures and message classes into their own module, and tidies up the mininode.py module. - First commit is almost entirely move-only - Second commit is mostly move-only, but also does a little tidying. Tree-SHA512: 5d74802677f1ab788e43188653106a96fffd9ab1fe3aa6a4eb94e5807de5dd5c8ee212296f45e8d16c7e3d95cfc4891677e812b7944bd3ab604e04b3b88aa06e
fb00c45 [tests] Explicitly disallow support for p2p versions below 60001 (John Newbery) 3858aab [tests] Remove support for p2p alert messages (John Newbery) c0b1274 [tests] Remove support for bre-BIP31 ping messages (John Newbery) 2904e30 [tests] Remove dead code from mininode.py (John Newbery) Pull request description: This is the first part of bitcoin#11518. It removes a ~150 lines of unused code from the mininode module: - remove unused `deliver_sleep_time` and `EarlyDisconnectError` code - remove support for pre-BIP31 ping messages - remove support for alert message - explicitly don't support p2p versions lower than 60001 Should be an easy ACK for reviewers. If all extended tests pass, then this code really was dead :) Tree-SHA512: 508e612ceb0b094250d18e75522d51e6b14cd069443050ba4af34d6f890c58721cb5653e8bc000b60635b9474d035b0dcd9c509c0dcdb3a7501df17b787f83b0
fb00c45 [tests] Explicitly disallow support for p2p versions below 60001 (John Newbery) 3858aab [tests] Remove support for p2p alert messages (John Newbery) c0b1274 [tests] Remove support for bre-BIP31 ping messages (John Newbery) 2904e30 [tests] Remove dead code from mininode.py (John Newbery) Pull request description: This is the first part of bitcoin#11518. It removes a ~150 lines of unused code from the mininode module: - remove unused `deliver_sleep_time` and `EarlyDisconnectError` code - remove support for pre-BIP31 ping messages - remove support for alert message - explicitly don't support p2p versions lower than 60001 Should be an easy ACK for reviewers. If all extended tests pass, then this code really was dead :) Tree-SHA512: 508e612ceb0b094250d18e75522d51e6b14cd069443050ba4af34d6f890c58721cb5653e8bc000b60635b9474d035b0dcd9c509c0dcdb3a7501df17b787f83b0 readd is None check Signed-off-by: Pasta <pasta@dashboost.org>
fb00c45 [tests] Explicitly disallow support for p2p versions below 60001 (John Newbery) 3858aab [tests] Remove support for p2p alert messages (John Newbery) c0b1274 [tests] Remove support for bre-BIP31 ping messages (John Newbery) 2904e30 [tests] Remove dead code from mininode.py (John Newbery) Pull request description: This is the first part of bitcoin#11518. It removes a ~150 lines of unused code from the mininode module: - remove unused `deliver_sleep_time` and `EarlyDisconnectError` code - remove support for pre-BIP31 ping messages - remove support for alert message - explicitly don't support p2p versions lower than 60001 Should be an easy ACK for reviewers. If all extended tests pass, then this code really was dead :) Tree-SHA512: 508e612ceb0b094250d18e75522d51e6b14cd069443050ba4af34d6f890c58721cb5653e8bc000b60635b9474d035b0dcd9c509c0dcdb3a7501df17b787f83b0 readd is None check Signed-off-by: Pasta <pasta@dashboost.org>
fb00c45 [tests] Explicitly disallow support for p2p versions below 60001 (John Newbery) 3858aab [tests] Remove support for p2p alert messages (John Newbery) c0b1274 [tests] Remove support for bre-BIP31 ping messages (John Newbery) 2904e30 [tests] Remove dead code from mininode.py (John Newbery) Pull request description: This is the first part of bitcoin#11518. It removes a ~150 lines of unused code from the mininode module: - remove unused `deliver_sleep_time` and `EarlyDisconnectError` code - remove support for pre-BIP31 ping messages - remove support for alert message - explicitly don't support p2p versions lower than 60001 Should be an easy ACK for reviewers. If all extended tests pass, then this code really was dead :) Tree-SHA512: 508e612ceb0b094250d18e75522d51e6b14cd069443050ba4af34d6f890c58721cb5653e8bc000b60635b9474d035b0dcd9c509c0dcdb3a7501df17b787f83b0 readd is None check Signed-off-by: Pasta <pasta@dashboost.org>
873beca [tests] Rename NodeConn and NodeConnCB (John Newbery) Pull request description: Final step in bitcoin#11518 NodeConn -> P2PConnection NodeConnCB -> P2PInterface This is basically just a rename. Should be an easy review. Tree-SHA512: fe1204b2b3d8182c5e324ffa7cb4099a47ef8536380e0bb9d37a5fccf76a24f548d1f1a7988ab8f830986a3058b670696de3fc891af5e5f75dbeb4e3273005d7
873beca [tests] Rename NodeConn and NodeConnCB (John Newbery) Pull request description: Final step in bitcoin#11518 NodeConn -> P2PConnection NodeConnCB -> P2PInterface This is basically just a rename. Should be an easy review. Tree-SHA512: fe1204b2b3d8182c5e324ffa7cb4099a47ef8536380e0bb9d37a5fccf76a24f548d1f1a7988ab8f830986a3058b670696de3fc891af5e5f75dbeb4e3273005d7
fb00c45 [tests] Explicitly disallow support for p2p versions below 60001 (John Newbery) 3858aab [tests] Remove support for p2p alert messages (John Newbery) c0b1274 [tests] Remove support for bre-BIP31 ping messages (John Newbery) 2904e30 [tests] Remove dead code from mininode.py (John Newbery) Pull request description: This is the first part of bitcoin#11518. It removes a ~150 lines of unused code from the mininode module: - remove unused `deliver_sleep_time` and `EarlyDisconnectError` code - remove support for pre-BIP31 ping messages - remove support for alert message - explicitly don't support p2p versions lower than 60001 Should be an easy ACK for reviewers. If all extended tests pass, then this code really was dead :) Tree-SHA512: 508e612ceb0b094250d18e75522d51e6b14cd069443050ba4af34d6f890c58721cb5653e8bc000b60635b9474d035b0dcd9c509c0dcdb3a7501df17b787f83b0 readd is None check Signed-off-by: Pasta <pasta@dashboost.org>
873beca [tests] Rename NodeConn and NodeConnCB (John Newbery) Pull request description: Final step in bitcoin#11518 NodeConn -> P2PConnection NodeConnCB -> P2PInterface This is basically just a rename. Should be an easy review. Tree-SHA512: fe1204b2b3d8182c5e324ffa7cb4099a47ef8536380e0bb9d37a5fccf76a24f548d1f1a7988ab8f830986a3058b670696de3fc891af5e5f75dbeb4e3273005d7
The mininode.py module is confusing, and the relationship between the
NodeConn
andNodeConnCB
classes is messy. This PR is an attempt to simplify the code and the external interface.First, the motivation:
NodeConnCB
, then append aNodeConn
connection to thatNodeConnCB
, while passing theNodeConnCB
into theNodeConn
as an argument. The internal interface between theNodeConn
andNodeConnCB
is equally tortuous. Note that [tests] Add P2P interface to TestNode #11182 hides that complexity from the user behindTestNode
, but this PR actually simplifies the internal implementation.Even though this is marked as [demonstration], it is already a complete implementation. It's too much to review in one PR, so this PR demonstrates the concepts. Separate PRs will be opened for the individual steps:
rpc
property fromNodeConn
NodeConn
fromNodeConnCB
NodeConn
andNodeConnCB
some notes on the implementation:
NodeConnCB
class is now a subclass ofNodeConn
. Individual tests and theTestNode
class will only need to interact with theNodeConnCB
class.NodeConn
has been renamedP2PConnection
. It's a low-level class that handles the TCP connection, reading and sending messages, and deserializing and serializing the P2P headers. It knows the names of P2P commands, but nothing about how to parse them.NodeConnCB
has been renamedP2PInterface
. It's a high-level class that handles communicating with the Bitcoin node over the P2P interface. It's responsible for processing incoming P2P payloads and constructing/sending P2P payloads.Note that the distinction above is somewhat analogous to net/net_processing in Bitcoin Core. The distinction already existed between
NodeConn
andNodeConnCB
but was blurry and not well enforced. This PR makes the distinction more formal.rpc
property of theNodeConnCB
class, which required a lot of lines of (completely mechanical) change to the p2p-segwit test. Conceptually it doesn't make sense for aNodeConnCB
P2P interface to own an rpc interface.