Fix read_headers
This commit is contained in:
parent
7f03b0fa73
commit
e452c0bca7
@ -369,22 +369,23 @@ class FSCache(LoggedClass):
|
|||||||
self.headers = []
|
self.headers = []
|
||||||
self.height += blocks_done
|
self.height += blocks_done
|
||||||
|
|
||||||
def read_headers(self, height, count):
|
def read_headers(self, start, count):
|
||||||
read_count = min(count, self.height + 1 - height)
|
|
||||||
|
|
||||||
assert height >= 0 and read_count >= 0
|
|
||||||
assert count <= read_count + len(self.headers)
|
|
||||||
|
|
||||||
result = b''
|
result = b''
|
||||||
if read_count > 0:
|
|
||||||
header_len = self.coin.HEADER_LEN
|
|
||||||
self.headers_file.seek(height * header_len)
|
|
||||||
result = self.headers_file.read(read_count * header_len)
|
|
||||||
|
|
||||||
count -= read_count
|
# Read some from disk
|
||||||
if count:
|
disk_count = min(count, self.height + 1 - start)
|
||||||
start = (height + read_count) - (self.height + 1)
|
if disk_count > 0:
|
||||||
result += b''.join(self.headers[start: start + count])
|
header_len = self.coin.HEADER_LEN
|
||||||
|
assert start >= 0
|
||||||
|
self.headers_file.seek(start * header_len)
|
||||||
|
result = self.headers_file.read(disk_count * header_len)
|
||||||
|
count -= disk_count
|
||||||
|
start += disk_count
|
||||||
|
|
||||||
|
# The rest from memory
|
||||||
|
start -= self.height + 1
|
||||||
|
assert count >= 0 and start + count <= len(self.headers)
|
||||||
|
result += b''.join(self.headers[start: start + count])
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user