write block ttd in `persistHeaderToDbWithoutSetHead`

This commit is contained in:
jangko 2022-03-08 21:47:51 +07:00
parent 25e7debf5e
commit d41a3dedf0
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 5 additions and 0 deletions

View File

@ -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))