mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-30 17:01:34 +00:00
interface: try hard not to infinite loop while getting headers
This commit is contained in:
parent
da23e71db1
commit
3fc9326c43
1 changed files with 3 additions and 1 deletions
|
@ -400,6 +400,7 @@ class Interface(PrintError):
|
||||||
next_height = self.tip
|
next_height = self.tip
|
||||||
last = None
|
last = None
|
||||||
while last is None or height <= next_height:
|
while last is None or height <= next_height:
|
||||||
|
prev_last, prev_height = last, height
|
||||||
if next_height > height + 10:
|
if next_height > height + 10:
|
||||||
could_connect, num_headers = await self.request_chunk(height, next_height)
|
could_connect, num_headers = await self.request_chunk(height, next_height)
|
||||||
if not could_connect:
|
if not could_connect:
|
||||||
|
@ -414,6 +415,7 @@ class Interface(PrintError):
|
||||||
last = 'catchup'
|
last = 'catchup'
|
||||||
else:
|
else:
|
||||||
last, height = await self.step(height)
|
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
|
return last, height
|
||||||
|
|
||||||
async def step(self, height, header=None):
|
async def step(self, height, header=None):
|
||||||
|
@ -422,7 +424,7 @@ class Interface(PrintError):
|
||||||
if header is None:
|
if header is None:
|
||||||
header = await self.get_block_header(height, 'catchup')
|
header = await self.get_block_header(height, 'catchup')
|
||||||
chain = self.blockchain.check_header(header) if 'mock' not in header else header['mock']['check'](header)
|
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)
|
can_connect = blockchain.can_connect(header) if 'mock' not in header else header['mock']['connect'](height)
|
||||||
|
|
||||||
if not can_connect:
|
if not can_connect:
|
||||||
|
|
Loading…
Add table
Reference in a new issue