mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
[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.
This commit is contained in:
parent
652311165c
commit
7e158a6910
3 changed files with 14 additions and 8 deletions
|
@ -19,7 +19,11 @@ from test_framework.messages import (
|
||||||
msg_mempool,
|
msg_mempool,
|
||||||
msg_version,
|
msg_version,
|
||||||
)
|
)
|
||||||
from test_framework.p2p import P2PInterface, p2p_lock
|
from test_framework.p2p import (
|
||||||
|
P2PInterface,
|
||||||
|
P2P_VERSION,
|
||||||
|
p2p_lock,
|
||||||
|
)
|
||||||
from test_framework.script import MAX_SCRIPT_ELEMENT_SIZE
|
from test_framework.script import MAX_SCRIPT_ELEMENT_SIZE
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
|
|
||||||
|
@ -218,6 +222,7 @@ class FilterTest(BitcoinTestFramework):
|
||||||
filter_peer_without_nrelay = self.nodes[0].add_p2p_connection(P2PBloomFilter(), send_version=False, wait_for_verack=False)
|
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 fRelay=False
|
||||||
version_without_fRelay = msg_version()
|
version_without_fRelay = msg_version()
|
||||||
|
version_without_fRelay.nVersion = P2P_VERSION
|
||||||
version_without_fRelay.nRelay = 0
|
version_without_fRelay.nRelay = 0
|
||||||
filter_peer_without_nrelay.send_message(version_without_fRelay)
|
filter_peer_without_nrelay.send_message(version_without_fRelay)
|
||||||
filter_peer_without_nrelay.wait_for_verack()
|
filter_peer_without_nrelay.wait_for_verack()
|
||||||
|
|
|
@ -31,7 +31,6 @@ import time
|
||||||
from test_framework.siphash import siphash256
|
from test_framework.siphash import siphash256
|
||||||
from test_framework.util import hex_str_to_bytes, assert_equal
|
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_SUBVERSION = "/python-p2p-tester:0.0.3/"
|
||||||
MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37)
|
MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37)
|
||||||
|
|
||||||
|
@ -325,22 +324,20 @@ class CBlockLocator:
|
||||||
__slots__ = ("nVersion", "vHave")
|
__slots__ = ("nVersion", "vHave")
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.nVersion = MY_VERSION
|
|
||||||
self.vHave = []
|
self.vHave = []
|
||||||
|
|
||||||
def deserialize(self, f):
|
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)
|
self.vHave = deser_uint256_vector(f)
|
||||||
|
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
r = b""
|
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)
|
r += ser_uint256_vector(self.vHave)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "CBlockLocator(nVersion=%i vHave=%s)" \
|
return "CBlockLocator(vHave=%s)" % (repr(self.vHave))
|
||||||
% (self.nVersion, repr(self.vHave))
|
|
||||||
|
|
||||||
|
|
||||||
class COutPoint:
|
class COutPoint:
|
||||||
|
@ -1027,7 +1024,7 @@ class msg_version:
|
||||||
msgtype = b"version"
|
msgtype = b"version"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.nVersion = MY_VERSION
|
self.nVersion = 0
|
||||||
self.nServices = NODE_NETWORK | NODE_WITNESS
|
self.nServices = NODE_NETWORK | NODE_WITNESS
|
||||||
self.nTime = int(time.time())
|
self.nTime = int(time.time())
|
||||||
self.addrTo = CAddress()
|
self.addrTo = CAddress()
|
||||||
|
|
|
@ -80,6 +80,9 @@ logger = logging.getLogger("TestFramework.p2p")
|
||||||
|
|
||||||
# The minimum P2P version that this test framework supports
|
# The minimum P2P version that this test framework supports
|
||||||
MIN_P2P_VERSION_SUPPORTED = 60001
|
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 = {
|
MESSAGEMAP = {
|
||||||
b"addr": msg_addr,
|
b"addr": msg_addr,
|
||||||
|
@ -329,6 +332,7 @@ class P2PInterface(P2PConnection):
|
||||||
def peer_connect_send_version(self, services):
|
def peer_connect_send_version(self, services):
|
||||||
# Send a version msg
|
# Send a version msg
|
||||||
vt = msg_version()
|
vt = msg_version()
|
||||||
|
vt.nVersion = P2P_VERSION
|
||||||
vt.nServices = services
|
vt.nServices = services
|
||||||
vt.addrTo.ip = self.dstaddr
|
vt.addrTo.ip = self.dstaddr
|
||||||
vt.addrTo.port = self.dstport
|
vt.addrTo.port = self.dstport
|
||||||
|
|
Loading…
Add table
Reference in a new issue