From d41a3dedf0a177e2d64bafc10e465a6f2ed56801 Mon Sep 17 00:00:00 2001 From: jangko Date: Tue, 8 Mar 2022 21:47:51 +0700 Subject: [PATCH] write block ttd in `persistHeaderToDbWithoutSetHead` --- nimbus/db/db_chain.nim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nimbus/db/db_chain.nim b/nimbus/db/db_chain.nim index af4462f9a..d1e428225 100644 --- a/nimbus/db/db_chain.nim +++ b/nimbus/db/db_chain.nim @@ -396,7 +396,12 @@ proc persistHeaderToDb*(self: BaseChainDB; header: BlockHeader): seq[BlockHeader result = self.setAsCanonicalChainHead(headerHash) proc persistHeaderToDbWithoutSetHead*(self: BaseChainDB; header: BlockHeader) = + let isGenesis = header.parentHash == GENESIS_PARENT_HASH let headerHash = header.blockHash + let score = if isGenesis: header.difficulty + else: self.getScore(header.parentHash) + header.difficulty + + self.db.put(blockHashToScoreKey(headerHash).toOpenArray, rlp.encode(score)) self.addBlockNumberToHashLookup(header) self.db.put(genericHashKey(headerHash).toOpenArray, rlp.encode(header))