From 606103a849c68fb3b06eec60fb68b958e333c0d1 Mon Sep 17 00:00:00 2001 From: localhuman Date: Tue, 19 Sep 2017 21:02:41 -0500 Subject: [PATCH] fix for header index less than block index on startup --- neo/Core/Helper.py | 2 +- neo/Core/State/AssetState.py | 1 - neo/IO/BinaryReader.py | 1 + .../Blockchains/LevelDB/LevelDBBlockchain.py | 20 ++++++++++++++++--- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/neo/Core/Helper.py b/neo/Core/Helper.py index 2c86f18ea..1e1d443f2 100644 --- a/neo/Core/Helper.py +++ b/neo/Core/Helper.py @@ -104,7 +104,7 @@ def VerifyScripts(verifiable): res = engine.Execute() if not res: - print("engine did not execune") + print("engine did not execute") return False diff --git a/neo/Core/State/AssetState.py b/neo/Core/State/AssetState.py index 348692168..b5b44282e 100644 --- a/neo/Core/State/AssetState.py +++ b/neo/Core/State/AssetState.py @@ -114,7 +114,6 @@ def Serialize(self, writer): writer.WriteFixed8(self.Fee) writer.WriteUInt160(self.FeeAddress) self.Owner.Serialize(writer) - print("6") writer.WriteUInt160(self.Admin) writer.WriteUInt160(self.Issuer) writer.WriteUInt32(self.Expiration) diff --git a/neo/IO/BinaryReader.py b/neo/IO/BinaryReader.py index eaff691b7..5073436c6 100644 --- a/neo/IO/BinaryReader.py +++ b/neo/IO/BinaryReader.py @@ -118,6 +118,7 @@ def ReadSerializableArray(self, class_name, max=sys.maxsize ): klass = getattr(importlib.import_module(module), klassname) length = self.ReadVarInt(max=max) items = [] + try: for i in range(0, length): item = klass() diff --git a/neo/Implementations/Blockchains/LevelDB/LevelDBBlockchain.py b/neo/Implementations/Blockchains/LevelDB/LevelDBBlockchain.py index a1975309f..d457a149a 100644 --- a/neo/Implementations/Blockchains/LevelDB/LevelDBBlockchain.py +++ b/neo/Implementations/Blockchains/LevelDB/LevelDBBlockchain.py @@ -118,8 +118,8 @@ def __init__(self, path): current_header_height = int.from_bytes(ba[-4:], 'little') current_header_hash = bytes(ba[:64].decode('utf-8'), encoding='utf-8') - self.__log.debug("current header hash!! %s " % current_header_hash) - self.__log.debug("current header height, hashes %s %s %s" %(self._current_block_height, self._header_index, current_header_height) ) +# self.__log.debug("current header hash!! %s " % current_header_hash) +# self.__log.debug("current header height, hashes %s %s %s" %(self._current_block_height, self._header_index, current_header_height) ) hashes = [] @@ -157,7 +157,21 @@ def __init__(self, path): if h.Index > 0: self._header_index.append(h.Hash.ToBytes()) + elif current_header_height > self._stored_header_count: + try: + hash = current_header_hash + targethash = self._header_index[-1] + + newhashes = [] + while hash != targethash: + header = self.GetHeader(hash) + newhashes.insert(0, header) + hash = header.PrevHash.ToBytes() + + self.AddHeaders(newhashes) + except Exception as e: + pass else: with self._db.write_batch() as wb: for key,value in self._db.iterator(): @@ -347,7 +361,7 @@ def GetHeader(self, hash): out = out[8:] outhex = binascii.unhexlify(out) return Header.FromTrimmedData(outhex, 0) - except TypeError: + except TypeError as e2: pass except Exception as e: self.__log.debug("OTHER ERRROR %s " % e)