forked from LBRYCommunity/lbry-sdk
make integrity check faster
This commit is contained in:
parent
9990889cce
commit
2481305a1a
1 changed files with 13 additions and 7 deletions
|
@ -165,18 +165,24 @@ class BaseHeaders:
|
||||||
)
|
)
|
||||||
|
|
||||||
def repair(self):
|
def repair(self):
|
||||||
|
previous_header_hash = fail = None
|
||||||
for height in range(self.height):
|
for height in range(self.height):
|
||||||
chunk = self.get_raw_header(height)
|
raw = self.get_raw_header(height)
|
||||||
try:
|
header = self.deserialize(height, raw)
|
||||||
# validate_chunk() is CPU bound and reads previous chunks from file system
|
if height:
|
||||||
self.validate_chunk(height, chunk)
|
if header['prev_block_hash'] != previous_header_hash:
|
||||||
except InvalidHeader as e:
|
fail = True
|
||||||
log.warning("Header file corrupted at height %s, truncating it.", e.height)
|
else:
|
||||||
self.io.seek((e.height) * self.header_size, os.SEEK_SET)
|
if self.hash_header(raw) != self.genesis_hash:
|
||||||
|
fail = True
|
||||||
|
if fail:
|
||||||
|
log.warning("Header file corrupted at height %s, truncating it.", height - 1)
|
||||||
|
self.io.seek((height - 1) * self.header_size, os.SEEK_SET)
|
||||||
self.io.truncate()
|
self.io.truncate()
|
||||||
self.io.flush()
|
self.io.flush()
|
||||||
self._size = None
|
self._size = None
|
||||||
return
|
return
|
||||||
|
previous_header_hash = self.hash_header(raw)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_proof_of_work(header_hash: bytes) -> ArithUint256:
|
def get_proof_of_work(header_hash: bytes) -> ArithUint256:
|
||||||
|
|
Loading…
Add table
Reference in a new issue