[tests] Explicitly disallow support for p2p versions below 60001

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).
pull/11638/head
John Newbery 7 years ago
parent 3858aabbd0
commit fb00c45c32

@ -37,6 +37,7 @@ from threading import RLock, Thread
from test_framework.siphash import siphash256 from test_framework.siphash import siphash256
from test_framework.util import hex_str_to_bytes, bytes_to_hex_str, wait_until from test_framework.util import hex_str_to_bytes, bytes_to_hex_str, wait_until
MIN_VERSION_SUPPORTED = 60001
MY_VERSION = 70014 # past bip-31 for ping/pong MY_VERSION = 70014 # past bip-31 for ping/pong
MY_SUBVERSION = b"/python-mininode-tester:0.0.3/" MY_SUBVERSION = b"/python-mininode-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)
@ -1423,11 +1424,8 @@ class NodeConnCB():
self.verack_received = True self.verack_received = True
def on_version(self, conn, message): def on_version(self, conn, message):
if message.nVersion >= 209: assert message.nVersion >= MIN_VERSION_SUPPORTED, "Version {} received. Test framework only supports versions greater than {}".format(message.nVersion, MIN_VERSION_SUPPORTED)
conn.send_message(msg_verack()) conn.send_message(msg_verack())
conn.ver_send = min(MY_VERSION, message.nVersion)
if message.nVersion < 209:
conn.ver_recv = conn.ver_send
conn.nServices = message.nServices conn.nServices = message.nServices
# Connection helper methods # Connection helper methods
@ -1609,40 +1607,27 @@ class NodeConn(asyncore.dispatcher):
return return
if self.recvbuf[:4] != self.MAGIC_BYTES[self.network]: if self.recvbuf[:4] != self.MAGIC_BYTES[self.network]:
raise ValueError("got garbage %s" % repr(self.recvbuf)) raise ValueError("got garbage %s" % repr(self.recvbuf))
if self.ver_recv < 209: if len(self.recvbuf) < 4 + 12 + 4 + 4:
if len(self.recvbuf) < 4 + 12 + 4: return
return command = self.recvbuf[4:4+12].split(b"\x00", 1)[0]
command = self.recvbuf[4:4+12].split(b"\x00", 1)[0] msglen = struct.unpack("<i", self.recvbuf[4+12:4+12+4])[0]
msglen = struct.unpack("<i", self.recvbuf[4+12:4+12+4])[0] checksum = self.recvbuf[4+12+4:4+12+4+4]
checksum = None if len(self.recvbuf) < 4 + 12 + 4 + 4 + msglen:
if len(self.recvbuf) < 4 + 12 + 4 + msglen: return
return msg = self.recvbuf[4+12+4+4:4+12+4+4+msglen]
msg = self.recvbuf[4+12+4:4+12+4+msglen] th = sha256(msg)
self.recvbuf = self.recvbuf[4+12+4+msglen:] h = sha256(th)
else: if checksum != h[:4]:
if len(self.recvbuf) < 4 + 12 + 4 + 4: raise ValueError("got bad checksum " + repr(self.recvbuf))
return self.recvbuf = self.recvbuf[4+12+4+4+msglen:]
command = self.recvbuf[4:4+12].split(b"\x00", 1)[0] if command not in self.messagemap:
msglen = struct.unpack("<i", self.recvbuf[4+12:4+12+4])[0] raise ValueError("Received unknown command from %s:%d: '%s' %s" % (self.dstaddr, self.dstport, command, repr(msg)))
checksum = self.recvbuf[4+12+4:4+12+4+4] f = BytesIO(msg)
if len(self.recvbuf) < 4 + 12 + 4 + 4 + msglen: t = self.messagemap[command]()
return t.deserialize(f)
msg = self.recvbuf[4+12+4+4:4+12+4+4+msglen] self.got_message(t)
th = sha256(msg)
h = sha256(th)
if checksum != h[:4]:
raise ValueError("got bad checksum " + repr(self.recvbuf))
self.recvbuf = self.recvbuf[4+12+4+4+msglen:]
if command in self.messagemap:
f = BytesIO(msg)
t = self.messagemap[command]()
t.deserialize(f)
self.got_message(t)
else:
logger.warning("Received unknown command from %s:%d: '%s' %s" % (self.dstaddr, self.dstport, command, repr(msg)))
raise ValueError("Unknown command: '%s'" % (command))
except Exception as e: except Exception as e:
logger.exception('got_data:', repr(e)) logger.exception('Error reading message:', repr(e))
raise raise
def send_message(self, message, pushbuf=False): def send_message(self, message, pushbuf=False):
@ -1655,10 +1640,9 @@ class NodeConn(asyncore.dispatcher):
tmsg += command tmsg += command
tmsg += b"\x00" * (12 - len(command)) tmsg += b"\x00" * (12 - len(command))
tmsg += struct.pack("<I", len(data)) tmsg += struct.pack("<I", len(data))
if self.ver_send >= 209: th = sha256(data)
th = sha256(data) h = sha256(th)
h = sha256(th) tmsg += h[:4]
tmsg += h[:4]
tmsg += data tmsg += data
with mininode_lock: with mininode_lock:
if (len(self.sendbuf) == 0 and not pushbuf): if (len(self.sendbuf) == 0 and not pushbuf):

Loading…
Cancel
Save