From 89fd986a0071cbb94a77cb2d2af98e34cf75b0f3 Mon Sep 17 00:00:00 2001 From: jangko Date: Mon, 21 Mar 2022 16:15:52 +0700 Subject: [PATCH] fix ttd logic in sealing engine also fix isBlockAfterTtd in chain_desc.nim --- nimbus/p2p/chain/chain_desc.nim | 4 ++-- nimbus/sealer.nim | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nimbus/p2p/chain/chain_desc.nim b/nimbus/p2p/chain/chain_desc.nim index ede344123..98b4d3f6d 100644 --- a/nimbus/p2p/chain/chain_desc.nim +++ b/nimbus/p2p/chain/chain_desc.nim @@ -76,8 +76,8 @@ func toNextFork(n: BlockNumber): uint64 = result = n.truncate(uint64) func isBlockAfterTtd*(c: Chain, blockHeader: BlockHeader): bool = - c.db.totalDifficulty + blockHeader.difficulty > c.db.ttd - + c.db.totalDifficulty + blockHeader.difficulty >= c.db.ttd + func getNextFork(c: ChainConfig, fork: ChainFork): uint64 = let next: array[ChainFork, uint64] = [ 0'u64, diff --git a/nimbus/sealer.nim b/nimbus/sealer.nim index 898248512..abf42b4da 100644 --- a/nimbus/sealer.nim +++ b/nimbus/sealer.nim @@ -121,6 +121,8 @@ proc prepareHeader(engine: SealingEngineRef, header.mixDigest = default(Hash256) header.nonce = default(BlockNonce) header.extraData = @[] # TODO: probably this should be configurable by user? + # Stop the block generator if we reach TTD + engine.state = EnginePostMerge else: let res = engine.chain.clique.prepare(parent, header) if res.isErr: @@ -147,10 +149,7 @@ proc generateBlock(engine: SealingEngineRef, header: res.get() ) - if engine.chain.isBlockAfterTtd(outBlock.header): - # Stop the block generator if we reach TTD - engine.state = EnginePostMerge - else: + if engine.state != EnginePostMerge: # Post merge, Clique should not be executing let sealRes = engine.chain.clique.seal(outBlock) if sealRes.isErr: @@ -261,6 +260,7 @@ proc generateExecutionPayload*(engine: SealingEngineRef, # make sure both generated block header and payloadRes(ExecutionPayloadV1) # produce the same blockHash blk.header.prevRandao = Hash256(data: distinctBase payloadAttrs.prevRandao) + blk.header.fee = some(blk.header.fee.get(UInt256.zero)) # force it with some(UInt256) let res = engine.chain.persistBlocks([blk.header], [ BlockBody(transactions: blk.txs, uncles: blk.uncles)