forked from LBRYCommunity/lbry-sdk
test and fix verifying from middle
This commit is contained in:
parent
d2fb7a7151
commit
1b83a1d09a
2 changed files with 8 additions and 2 deletions
|
@ -311,12 +311,15 @@ class Headers:
|
|||
headers = headers[:(len(headers) // self.header_size) * self.header_size]
|
||||
for header_hash, header in self._iterate_headers(height, headers):
|
||||
height = header['block_height']
|
||||
if height:
|
||||
if previous_header_hash:
|
||||
if header['prev_block_hash'] != previous_header_hash:
|
||||
fail = True
|
||||
else:
|
||||
elif height == 0:
|
||||
if header_hash != self.genesis_hash:
|
||||
fail = True
|
||||
else:
|
||||
# for sanity and clarity, since it is the only way we can end up here
|
||||
assert start_height > 0 and height == start_height
|
||||
if fail:
|
||||
log.warning("Header file corrupted at height %s, truncating it.", height - 1)
|
||||
def __truncate(at_height):
|
||||
|
|
|
@ -143,6 +143,9 @@ class TestHeaders(AsyncioTestCase):
|
|||
self.assertEqual(7, headers.height)
|
||||
await headers.connect(len(headers), HEADERS[block_bytes(8):])
|
||||
self.assertEqual(19, headers.height)
|
||||
# verify from middle
|
||||
await headers.repair(start_height=10)
|
||||
self.assertEqual(19, headers.height)
|
||||
|
||||
async def test_misalignment_triggers_repair_on_open(self):
|
||||
headers = Headers(':memory:')
|
||||
|
|
Loading…
Add table
Reference in a new issue