interface: try hard not to infinite loop while getting headers

This commit is contained in:
SomberNight 2018-09-16 07:35:11 +02:00
parent da23e71db1
commit 3fc9326c43
No known key found for this signature in database
GPG key ID: B33B5F232C6271E9

View file

@ -400,6 +400,7 @@ class Interface(PrintError):
next_height = self.tip
last = None
while last is None or height <= next_height:
prev_last, prev_height = last, height
if next_height > height + 10:
could_connect, num_headers = await self.request_chunk(height, next_height)
if not could_connect:
@ -414,6 +415,7 @@ class Interface(PrintError):
last = 'catchup'
else:
last, height = await self.step(height)
assert (prev_last, prev_height) != (last, height), 'had to prevent infinite loop in interface.sync_until'
return last, height
async def step(self, height, header=None):
@ -422,7 +424,7 @@ class Interface(PrintError):
if header is None:
header = await self.get_block_header(height, 'catchup')
chain = self.blockchain.check_header(header) if 'mock' not in header else header['mock']['check'](header)
if chain: return 'catchup', height
if chain: return 'catchup', height+1
can_connect = blockchain.can_connect(header) if 'mock' not in header else header['mock']['connect'](height)
if not can_connect: