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:23:32 +0000 |
commit | 010542614dbebba5f5ad6a58c0554930e9e214fc (patch) | |
tree | cd059d76169e95b298d729ba6acac7545f566449 /test | |
parent | 9b4054cb7af22123c7fcc4989e143606a630b2af (diff) |
[test] Move MY_RELAY to p2p.py
messages.py is for message and primitive data structures. Specifics
about the test framework's p2p implementation should be in p2p.py.
Also rename to P2P_VERSION_RELAY. Also rename msg_version.nRelay to
relay. In Bitcoin Core, this is referred to as fRelay, since it's a
bool, so this field has always been misnamed.
Diffstat (limited to 'test')
-rwxr-xr-x | test/functional/p2p_filter.py | 4 | ||||
-rwxr-xr-x | test/functional/p2p_leak.py | 4 | ||||
-rwxr-xr-x | test/functional/test_framework/messages.py | 18 | ||||
-rwxr-xr-x | test/functional/test_framework/p2p.py | 3 |
4 files changed, 16 insertions, 13 deletions
diff --git a/test/functional/p2p_filter.py b/test/functional/p2p_filter.py index 78bdb32cf4..4df3dd6a21 100755 --- a/test/functional/p2p_filter.py +++ b/test/functional/p2p_filter.py @@ -221,11 +221,11 @@ class FilterTest(BitcoinTestFramework): self.log.info('Test BIP 37 for a node with fRelay = False') # Add peer but do not send version yet filter_peer_without_nrelay = self.nodes[0].add_p2p_connection(P2PBloomFilter(), send_version=False, wait_for_verack=False) - # Send version with fRelay=False + # Send version with relay=False version_without_fRelay = msg_version() version_without_fRelay.nVersion = P2P_VERSION version_without_fRelay.strSubVer = P2P_SUBVERSION - version_without_fRelay.nRelay = 0 + version_without_fRelay.relay = 0 filter_peer_without_nrelay.send_message(version_without_fRelay) filter_peer_without_nrelay.wait_for_verack() assert not self.nodes[0].getpeerinfo()[0]['relaytxes'] diff --git a/test/functional/p2p_leak.py b/test/functional/p2p_leak.py index 2cf327fc18..42e9b9f270 100755 --- a/test/functional/p2p_leak.py +++ b/test/functional/p2p_leak.py @@ -20,6 +20,7 @@ from test_framework.messages import ( from test_framework.p2p import ( P2PInterface, P2P_SUBVERSION, + P2P_VERSION_RELAY, ) from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( @@ -128,13 +129,14 @@ class P2PLeakTest(BitcoinTestFramework): assert_equal(ver.addrFrom.port, 0) assert_equal(ver.addrFrom.ip, '0.0.0.0') assert_equal(ver.nStartingHeight, 201) - assert_equal(ver.nRelay, 1) + assert_equal(ver.relay, 1) self.log.info('Check that old peers are disconnected') p2p_old_peer = self.nodes[0].add_p2p_connection(P2PInterface(), send_version=False, wait_for_verack=False) old_version_msg = msg_version() old_version_msg.nVersion = 31799 old_version_msg.strSubVer = P2P_SUBVERSION + old_version_msg.relay = P2P_VERSION_RELAY with self.nodes[0].assert_debug_log(['peer=3 using obsolete version 31799; disconnecting']): p2p_old_peer.send_message(old_version_msg) p2p_old_peer.wait_for_disconnect() diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index cee662aade..5170d430b7 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -31,8 +31,6 @@ import time from test_framework.siphash import siphash256 from test_framework.util import hex_str_to_bytes, assert_equal -MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37) - MAX_LOCATOR_SZ = 101 MAX_BLOCK_BASE_SIZE = 1000000 MAX_BLOOM_FILTER_SIZE = 36000 @@ -1018,7 +1016,7 @@ class CMerkleBlock: # Objects that correspond to messages on the wire class msg_version: - __slots__ = ("addrFrom", "addrTo", "nNonce", "nRelay", "nServices", + __slots__ = ("addrFrom", "addrTo", "nNonce", "relay", "nServices", "nStartingHeight", "nTime", "nVersion", "strSubVer") msgtype = b"version" @@ -1031,7 +1029,7 @@ class msg_version: self.nNonce = random.getrandbits(64) self.strSubVer = '' self.nStartingHeight = -1 - self.nRelay = MY_RELAY + self.relay = 0 def deserialize(self, f): self.nVersion = struct.unpack("<i", f.read(4))[0] @@ -1050,11 +1048,11 @@ class msg_version: if self.nVersion >= 70001: # Relay field is optional for version 70001 onwards try: - self.nRelay = struct.unpack("<b", f.read(1))[0] + self.relay = struct.unpack("<b", f.read(1))[0] except: - self.nRelay = 0 + self.relay = 0 else: - self.nRelay = 0 + self.relay = 0 def serialize(self): r = b"" @@ -1066,14 +1064,14 @@ class msg_version: r += struct.pack("<Q", self.nNonce) r += ser_string(self.strSubVer.encode('utf-8')) r += struct.pack("<i", self.nStartingHeight) - r += struct.pack("<b", self.nRelay) + r += struct.pack("<b", self.relay) return r def __repr__(self): - return 'msg_version(nVersion=%i nServices=%i nTime=%s addrTo=%s addrFrom=%s nNonce=0x%016X strSubVer=%s nStartingHeight=%i nRelay=%i)' \ + return 'msg_version(nVersion=%i nServices=%i nTime=%s addrTo=%s addrFrom=%s nNonce=0x%016X strSubVer=%s nStartingHeight=%i relay=%i)' \ % (self.nVersion, self.nServices, time.ctime(self.nTime), repr(self.addrTo), repr(self.addrFrom), self.nNonce, - self.strSubVer, self.nStartingHeight, self.nRelay) + self.strSubVer, self.nStartingHeight, self.relay) class msg_verack: diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py index 0814dec546..179d03e93a 100755 --- a/test/functional/test_framework/p2p.py +++ b/test/functional/test_framework/p2p.py @@ -85,6 +85,8 @@ MIN_P2P_VERSION_SUPPORTED = 60001 P2P_VERSION = 70016 # The P2P user agent string that this test framework sends in its `version` message P2P_SUBVERSION = "/python-p2p-tester:0.0.3/" +# Value for relay that this test framework sends in its `version` message +P2P_VERSION_RELAY = 1 MESSAGEMAP = { b"addr": msg_addr, @@ -336,6 +338,7 @@ class P2PInterface(P2PConnection): vt = msg_version() vt.nVersion = P2P_VERSION vt.strSubVer = P2P_SUBVERSION + vt.relay = P2P_VERSION_RELAY vt.nServices = services vt.addrTo.ip = self.dstaddr vt.addrTo.port = self.dstport |