From ce977e0385f7eaa910df5f47ed90c6347c2c7d99 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Fri, 21 Jul 2017 09:02:58 +0200 Subject: [PATCH] fix parent_branch_size in blockchain swap --- lib/blockchain.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/blockchain.py b/lib/blockchain.py index fb51532db..370b24d47 100644 --- a/lib/blockchain.py +++ b/lib/blockchain.py @@ -184,19 +184,21 @@ class Blockchain(util.PrintError): with open(filename, 'rb+') as f: f.seek(d) f.write(chunk) - # 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 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) parent_id = self.parent_id checkpoint = self.checkpoint parent = self.parent() - size = parent.get_branch_size() with open(parent.path(), 'rb+') as f: 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.truncate() with open(self.path(), 'rb+') as f: @@ -233,8 +235,7 @@ class Blockchain(util.PrintError): f.seek(delta * 80) f.write(data) # 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): assert self.parent_id != self.checkpoint