mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-31 17:31:36 +00:00
fix parent_branch_size in blockchain swap
This commit is contained in:
parent
313d53fe0b
commit
ce977e0385
1 changed files with 8 additions and 7 deletions
|
@ -184,19 +184,21 @@ class Blockchain(util.PrintError):
|
||||||
with open(filename, 'rb+') as f:
|
with open(filename, 'rb+') as f:
|
||||||
f.seek(d)
|
f.seek(d)
|
||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
# order files
|
self.swap_with_parent()
|
||||||
if self.parent_id is not None and self.parent().get_branch_size() < self.size():
|
|
||||||
self.swap_with_parent()
|
|
||||||
|
|
||||||
def swap_with_parent(self):
|
def swap_with_parent(self):
|
||||||
|
if self.parent_id is None:
|
||||||
|
return
|
||||||
|
parent_branch_size = self.parent().height() - self.checkpoint + 1
|
||||||
|
if parent_branch_size >= self.size():
|
||||||
|
return
|
||||||
self.print_error("swap", self.checkpoint, self.parent_id)
|
self.print_error("swap", self.checkpoint, self.parent_id)
|
||||||
parent_id = self.parent_id
|
parent_id = self.parent_id
|
||||||
checkpoint = self.checkpoint
|
checkpoint = self.checkpoint
|
||||||
parent = self.parent()
|
parent = self.parent()
|
||||||
size = parent.get_branch_size()
|
|
||||||
with open(parent.path(), 'rb+') as f:
|
with open(parent.path(), 'rb+') as f:
|
||||||
f.seek((checkpoint - parent.checkpoint)*80)
|
f.seek((checkpoint - parent.checkpoint)*80)
|
||||||
parent_data = f.read(size*80)
|
parent_data = f.read(parent_branch_size*80)
|
||||||
f.seek((checkpoint - parent.checkpoint)*80)
|
f.seek((checkpoint - parent.checkpoint)*80)
|
||||||
f.truncate()
|
f.truncate()
|
||||||
with open(self.path(), 'rb+') as f:
|
with open(self.path(), 'rb+') as f:
|
||||||
|
@ -233,8 +235,7 @@ class Blockchain(util.PrintError):
|
||||||
f.seek(delta * 80)
|
f.seek(delta * 80)
|
||||||
f.write(data)
|
f.write(data)
|
||||||
# order files
|
# order files
|
||||||
if self.parent_id is not None and self.parent().get_branch_size() < self.size():
|
self.swap_with_parent()
|
||||||
self.swap_with_parent()
|
|
||||||
|
|
||||||
def read_header(self, height):
|
def read_header(self, height):
|
||||||
assert self.parent_id != self.checkpoint
|
assert self.parent_id != self.checkpoint
|
||||||
|
|
Loading…
Add table
Reference in a new issue