Do not rewrite the blockchain file at startup
This commit is contained in:
@@ -200,8 +200,8 @@ class Blockchain:
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
if last_valid is not None:
|
if last_valid is not None:
|
||||||
self.set_latest_block(last_valid.own_hash)
|
self.set_latest_block(last_valid.own_hash, persist = False)
|
||||||
def set_latest_block(self, block_hash):
|
def set_latest_block(self, block_hash, persist = True):
|
||||||
new_block = self.get_block(block_hash)
|
new_block = self.get_block(block_hash)
|
||||||
assert new_block is not None
|
assert new_block is not None
|
||||||
assert new_block.valid
|
assert new_block.valid
|
||||||
@@ -220,7 +220,8 @@ class Blockchain:
|
|||||||
if self.__latest_block_hash != latest_block_hash:
|
if self.__latest_block_hash != latest_block_hash:
|
||||||
continue
|
continue
|
||||||
self.__latest_block_hash = block_hash
|
self.__latest_block_hash = block_hash
|
||||||
self.__persist_block_update(latest_block, new_block)
|
if persist:
|
||||||
|
self.__persist_block_update(latest_block, new_block)
|
||||||
return True
|
return True
|
||||||
def __persist_block_update(self, old_block, new_block):
|
def __persist_block_update(self, old_block, new_block):
|
||||||
if old_block is not None:
|
if old_block is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user