Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/mininode.py
Show All 20 Lines | |||||
from io import BytesIO | from io import BytesIO | ||||
import logging | import logging | ||||
import struct | import struct | ||||
import sys | import sys | ||||
import threading | import threading | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
CBlockHeader, | CBlockHeader, | ||||
MAX_HEADERS_RESULTS, | |||||
MIN_VERSION_SUPPORTED, | MIN_VERSION_SUPPORTED, | ||||
msg_addr, | msg_addr, | ||||
msg_addrv2, | msg_addrv2, | ||||
msg_avapoll, | msg_avapoll, | ||||
msg_avaproof, | msg_avaproof, | ||||
msg_tcpavaresponse, | msg_tcpavaresponse, | ||||
msg_avahello, | msg_avahello, | ||||
msg_block, | msg_block, | ||||
▲ Show 20 Lines • Show All 604 Lines • ▼ Show 20 Lines | def on_getheaders(self, message): | ||||
locator, hash_stop = message.locator, message.hashstop | locator, hash_stop = message.locator, message.hashstop | ||||
# Assume that the most recent block added is the tip | # Assume that the most recent block added is the tip | ||||
if not self.block_store: | if not self.block_store: | ||||
return | return | ||||
headers_list = [self.block_store[self.last_block_hash]] | headers_list = [self.block_store[self.last_block_hash]] | ||||
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 = CBlockHeader( | prev_block_header = CBlockHeader( | ||||
self.block_store[prev_block_hash]) | 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 | ||||
# Truncate the list if there are too many headers | # Truncate the list if there are too many headers | ||||
headers_list = headers_list[:-maxheaders - 1:-1] | headers_list = headers_list[:-MAX_HEADERS_RESULTS - 1:-1] | ||||
response = msg_headers(headers_list) | response = msg_headers(headers_list) | ||||
if response is not None: | if response is not None: | ||||
self.send_message(response) | self.send_message(response) | ||||
def send_blocks_and_test(self, blocks, node, *, success=True, force_send=False, | def send_blocks_and_test(self, blocks, node, *, success=True, force_send=False, | ||||
reject_reason=None, expect_disconnect=False, timeout=60): | reject_reason=None, expect_disconnect=False, timeout=60): | ||||
"""Send blocks to test node and test whether the tip advances. | """Send blocks to test node and test whether the tip advances. | ||||
▲ Show 20 Lines • Show All 117 Lines • Show Last 20 Lines |