Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/mininode.py
Show All 17 Lines | |||||
from io import BytesIO | from io import BytesIO | ||||
import logging | import logging | ||||
import socket | import socket | ||||
import struct | import struct | ||||
import sys | import sys | ||||
import threading | import threading | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
CBlockHeader, | |||||
MIN_VERSION_SUPPORTED, | MIN_VERSION_SUPPORTED, | ||||
msg_addr, | msg_addr, | ||||
msg_block, | msg_block, | ||||
MSG_BLOCK, | MSG_BLOCK, | ||||
msg_blocktxn, | msg_blocktxn, | ||||
msg_cmpctblock, | msg_cmpctblock, | ||||
msg_feefilter, | msg_feefilter, | ||||
msg_getaddr, | msg_getaddr, | ||||
▲ Show 20 Lines • Show All 546 Lines • ▼ Show 20 Lines | def on_getheaders(self, message): | ||||
headers_list = [self.block_store[self.last_block_hash]] | headers_list = [self.block_store[self.last_block_hash]] | ||||
maxheaders = 2000 | maxheaders = 2000 | ||||
while headers_list[-1].sha256 not in locator.vHave: | while headers_list[-1].sha256 not in locator.vHave: | ||||
# Walk back through the block store, adding headers to headers_list | # Walk back through the block store, adding headers to headers_list | ||||
# as we go. | # as we go. | ||||
prev_block_hash = headers_list[-1].hashPrevBlock | prev_block_hash = headers_list[-1].hashPrevBlock | ||||
if prev_block_hash in self.block_store: | if prev_block_hash in self.block_store: | ||||
prev_block_header = self.block_store[prev_block_hash] | prev_block_header = CBlockHeader( | ||||
self.block_store[prev_block_hash]) | |||||
headers_list.append(prev_block_header) | headers_list.append(prev_block_header) | ||||
if prev_block_header.sha256 == hash_stop: | if prev_block_header.sha256 == hash_stop: | ||||
# if this is the hashstop header, stop here | # if this is the hashstop header, stop here | ||||
break | break | ||||
else: | else: | ||||
logger.debug('block hash {} not found in block store'.format( | logger.debug('block hash {} not found in block store'.format( | ||||
hex(prev_block_hash))) | hex(prev_block_hash))) | ||||
break | break | ||||
Show All 25 Lines | def send_blocks_and_test(self, blocks, rpc, success=True, request_block=True, reject_code=None, reject_reason=None, timeout=60): | ||||
with mininode_lock: | with mininode_lock: | ||||
self.reject_code_received = None | self.reject_code_received = None | ||||
self.reject_reason_received = None | self.reject_reason_received = None | ||||
for block in blocks: | for block in blocks: | ||||
self.block_store[block.sha256] = block | self.block_store[block.sha256] = block | ||||
self.last_block_hash = block.sha256 | self.last_block_hash = block.sha256 | ||||
self.send_message(msg_headers([blocks[-1]])) | self.send_message(msg_headers([CBlockHeader(blocks[-1])])) | ||||
if request_block: | if request_block: | ||||
wait_until( | wait_until( | ||||
lambda: blocks[-1].sha256 in self.getdata_requests, timeout=timeout, lock=mininode_lock) | lambda: blocks[-1].sha256 in self.getdata_requests, timeout=timeout, lock=mininode_lock) | ||||
if success: | if success: | ||||
wait_until(lambda: rpc.getbestblockhash() == | wait_until(lambda: rpc.getbestblockhash() == | ||||
blocks[-1].hash, timeout=timeout) | blocks[-1].hash, timeout=timeout) | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |