From f2f92f560835e669b4d8d79f931dfba60dca2d2f Mon Sep 17 00:00:00 2001 From: andri lim Date: Fri, 5 Apr 2019 16:29:05 +0700 Subject: [PATCH] fix block 1.487.668 problem: getScore int overflow --- nimbus/db/db_chain.nim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nimbus/db/db_chain.nim b/nimbus/db/db_chain.nim index 706a87c8c..534bd1c9e 100644 --- a/nimbus/db/db_chain.nim +++ b/nimbus/db/db_chain.nim @@ -79,8 +79,8 @@ proc getBlockHeader*(self: BaseChainDB; n: BlockNumber): BlockHeader = ## Raises BlockNotFound error if the block is not in the DB. self.getBlockHeader(self.getBlockHash(n)) -proc getScore*(self: BaseChainDB; blockHash: Hash256): uint64 = - rlp.decode(self.db.get(blockHashToScoreKey(blockHash).toOpenArray).toRange, uint64) +proc getScore*(self: BaseChainDB; blockHash: Hash256): Uint256 = + rlp.decode(self.db.get(blockHashToScoreKey(blockHash).toOpenArray).toRange, Uint256) iterator findNewAncestors(self: BaseChainDB; header: BlockHeader): BlockHeader = ## Returns the chain leading up from the given header until the first ancestor it has in @@ -224,18 +224,18 @@ proc persistHeaderToDb*(self: BaseChainDB; header: BlockHeader): seq[BlockHeader self.db.put(genericHashKey(headerHash).toOpenArray, rlp.encode(header)) let score = if isGenesis: header.difficulty - else: self.getScore(header.parentHash).u256 + header.difficulty + else: self.getScore(header.parentHash) + header.difficulty self.db.put(blockHashToScoreKey(headerHash).toOpenArray, rlp.encode(score)) self.addBlockNumberToHashLookup(header) - var headScore: uint64 + var headScore: Uint256 try: headScore = self.getScore(self.getCanonicalHead().hash) except CanonicalHeadNotFound: return self.setAsCanonicalChainHead(headerHash) - if score > headScore.u256: + if score > headScore: result = self.setAsCanonicalChainHead(headerHash) proc addTransactionToCanonicalChain(self: BaseChainDB, txHash: Hash256,