fix ttd logic in sealing engine

also fix isBlockAfterTtd in chain_desc.nim
This commit is contained in:
jangko 2022-03-21 16:15:52 +07:00
parent cf0cc531c3
commit 89fd986a00
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 6 additions and 6 deletions

View File

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

View File

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