diff --git a/qa/rpc-tests/test_framework/mininode.py b/qa/rpc-tests/test_framework/mininode.py --- a/qa/rpc-tests/test_framework/mininode.py +++ b/qa/rpc-tests/test_framework/mininode.py @@ -53,6 +53,9 @@ NODE_BLOOM = (1 << 2) NODE_WITNESS = (1 << 3) +# Howmuch data will be read from the network at once +READ_BUFFER_SIZE = 8192 + # Keep our own socket map for asyncore, so that we can track disconnects # ourselves (to workaround an issue with closing an asyncore socket when # using select) @@ -1609,6 +1612,7 @@ b"getblocktxn": msg_getblocktxn, b"blocktxn": msg_blocktxn } + MAGIC_BYTES = { "mainnet": b"\xf9\xbe\xb4\xd9", # mainnet "testnet3": b"\x0b\x11\x09\x07", # testnet3 @@ -1674,13 +1678,19 @@ def handle_read(self): try: - t = self.recv(8192) - if len(t) > 0: - self.recvbuf += t - self.got_data() + with mininode_lock: + t = self.recv(READ_BUFFER_SIZE) + if len(t) > 0: + self.recvbuf += t except: pass + while True: + msg = self.got_data() + if msg == None: + break + self.got_message(msg) + def readable(self): return True @@ -1709,43 +1719,43 @@ def got_data(self): try: - while True: + with mininode_lock: if len(self.recvbuf) < 4: - return + return None if self.recvbuf[:4] != self.MAGIC_BYTES[self.network]: raise ValueError("got garbage %s" % repr(self.recvbuf)) if self.ver_recv < 209: if len(self.recvbuf) < 4 + 12 + 4: - return + return None command = self.recvbuf[4:4+12].split(b"\x00", 1)[0] msglen = struct.unpack("