fix ttd handling in sealing engine

This commit is contained in:
jangko 2022-03-23 21:06:26 +07:00
parent effc874d47
commit a90bf1c99a
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 15 additions and 5 deletions

View File

@ -83,7 +83,16 @@ func toNextFork(n: Option[BlockNumber]): uint64 =
0'u64
func isBlockAfterTtd*(c: Chain, blockHeader: BlockHeader): bool =
c.db.totalDifficulty + blockHeader.difficulty >= c.db.ttd
let
ttd = c.db.ttd
totalDifficulty = c.db.totalDifficulty + blockHeader.difficulty
# c.db.totalDifficulty is parent.totalDifficulty
# TerminalBlock is defined as header.totalDifficulty >= TTD
# and parent.totalDifficulty < TTD
# So blockAfterTTD must be both header.totalDifficulty >= TTD
# and parent.totalDifficulty >= TTD
c.db.totalDifficulty >= ttd and totalDifficulty >= ttd
func getNextFork(c: ChainConfig, fork: ChainFork): uint64 =
let next: array[ChainFork, uint64] = [

View File

@ -223,10 +223,6 @@ proc sealingLoop(engine: SealingEngineRef): Future[void] {.async.} =
error "sealing engine generateBlock error", msg=blkRes.error
break
# if TTD reached during block generation, stop the sealer
if engine.state != EngineRunning:
break
let res = engine.chain.persistBlocks([blk.header], [
BlockBody(transactions: blk.txs, uncles: blk.uncles)
])
@ -237,6 +233,11 @@ proc sealingLoop(engine: SealingEngineRef): Future[void] {.async.} =
info "block generated", number=blk.header.blockNumber
# if TTD reached during block generation, stop the sealer
if engine.state != EngineRunning:
info "TTD reached, stop sealing engine"
break
template unsafeQuantityToInt64(q: web3types.Quantity): int64 =
int64 q