fix ttd handling in sealing engine
This commit is contained in:
parent
effc874d47
commit
a90bf1c99a
|
@ -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] = [
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue