diff options
author | John Newbery <john@johnnewbery.com> | 2020-11-28 11:41:25 +0000 |
---|---|---|
committer | John Newbery <john@johnnewbery.com> | 2021-02-17 09:00:53 +0000 |
commit | 7e158a69104831611462cb555da931331b237c78 (patch) | |
tree | f971e3a91e458b076d793fa801e759a581cd955a /test/functional/test_framework | |
parent | 652311165c4ef298dab71d7162f9054abf439f77 (diff) | |
download | bitcoin-7e158a69104831611462cb555da931331b237c78.tar.xz |
[test] Move MY_VERSION to p2p.py
The messages.py module should contain code and helpers for
[de]serializing p2p messages. Specific usage of those messages should
be in p2p.py. Therefore move MY_VERSION to p2p.py.
Also rename to P2P_VERSION to distinguish it from
other versioning used in Bitcoin/Bitcoin Core.
Also always set the nVersion field in CBlockLocator to 0 and ignore the
field in deserialized messages. The field is not currently used for
anything in Bitcoin Core.
Diffstat (limited to 'test/functional/test_framework')
-rwxr-xr-x | test/functional/test_framework/messages.py | 11 | ||||
-rwxr-xr-x | test/functional/test_framework/p2p.py | 4 |
2 files changed, 8 insertions, 7 deletions
diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index 623c01908b..b120ce2438 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -31,7 +31,6 @@ import time from test_framework.siphash import siphash256 from test_framework.util import hex_str_to_bytes, assert_equal -MY_VERSION = 70016 # past wtxid relay MY_SUBVERSION = "/python-p2p-tester:0.0.3/" MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37) @@ -325,22 +324,20 @@ class CBlockLocator: __slots__ = ("nVersion", "vHave") def __init__(self): - self.nVersion = MY_VERSION self.vHave = [] def deserialize(self, f): - self.nVersion = struct.unpack("<i", f.read(4))[0] + struct.unpack("<i", f.read(4))[0] # Ignore version field. self.vHave = deser_uint256_vector(f) def serialize(self): r = b"" - r += struct.pack("<i", self.nVersion) + r += struct.pack("<i", 0) # Bitcoin Core ignores version field. Set it to 0. r += ser_uint256_vector(self.vHave) return r def __repr__(self): - return "CBlockLocator(nVersion=%i vHave=%s)" \ - % (self.nVersion, repr(self.vHave)) + return "CBlockLocator(vHave=%s)" % (repr(self.vHave)) class COutPoint: @@ -1027,7 +1024,7 @@ class msg_version: msgtype = b"version" def __init__(self): - self.nVersion = MY_VERSION + self.nVersion = 0 self.nServices = NODE_NETWORK | NODE_WITNESS self.nTime = int(time.time()) self.addrTo = CAddress() diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py index befadc894f..998763ff4d 100755 --- a/test/functional/test_framework/p2p.py +++ b/test/functional/test_framework/p2p.py @@ -80,6 +80,9 @@ logger = logging.getLogger("TestFramework.p2p") # The minimum P2P version that this test framework supports MIN_P2P_VERSION_SUPPORTED = 60001 +# The P2P version that this test framework implements and sends in its `version` message +# Version 70016 supports wtxid relay +P2P_VERSION = 70016 MESSAGEMAP = { b"addr": msg_addr, @@ -329,6 +332,7 @@ class P2PInterface(P2PConnection): def peer_connect_send_version(self, services): # Send a version msg vt = msg_version() + vt.nVersion = P2P_VERSION vt.nServices = services vt.addrTo.ip = self.dstaddr vt.addrTo.port = self.dstport |