mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 05:14:14 +00:00
fix ttd logic in sealing engine
also fix isBlockAfterTtd in chain_desc.nim
This commit is contained in:
parent
cf0cc531c3
commit
89fd986a00
@ -76,8 +76,8 @@ func toNextFork(n: BlockNumber): uint64 =
|
|||||||
result = n.truncate(uint64)
|
result = n.truncate(uint64)
|
||||||
|
|
||||||
func isBlockAfterTtd*(c: Chain, blockHeader: BlockHeader): bool =
|
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 =
|
func getNextFork(c: ChainConfig, fork: ChainFork): uint64 =
|
||||||
let next: array[ChainFork, uint64] = [
|
let next: array[ChainFork, uint64] = [
|
||||||
0'u64,
|
0'u64,
|
||||||
|
@ -121,6 +121,8 @@ proc prepareHeader(engine: SealingEngineRef,
|
|||||||
header.mixDigest = default(Hash256)
|
header.mixDigest = default(Hash256)
|
||||||
header.nonce = default(BlockNonce)
|
header.nonce = default(BlockNonce)
|
||||||
header.extraData = @[] # TODO: probably this should be configurable by user?
|
header.extraData = @[] # TODO: probably this should be configurable by user?
|
||||||
|
# Stop the block generator if we reach TTD
|
||||||
|
engine.state = EnginePostMerge
|
||||||
else:
|
else:
|
||||||
let res = engine.chain.clique.prepare(parent, header)
|
let res = engine.chain.clique.prepare(parent, header)
|
||||||
if res.isErr:
|
if res.isErr:
|
||||||
@ -147,10 +149,7 @@ proc generateBlock(engine: SealingEngineRef,
|
|||||||
header: res.get()
|
header: res.get()
|
||||||
)
|
)
|
||||||
|
|
||||||
if engine.chain.isBlockAfterTtd(outBlock.header):
|
if engine.state != EnginePostMerge:
|
||||||
# Stop the block generator if we reach TTD
|
|
||||||
engine.state = EnginePostMerge
|
|
||||||
else:
|
|
||||||
# Post merge, Clique should not be executing
|
# Post merge, Clique should not be executing
|
||||||
let sealRes = engine.chain.clique.seal(outBlock)
|
let sealRes = engine.chain.clique.seal(outBlock)
|
||||||
if sealRes.isErr:
|
if sealRes.isErr:
|
||||||
@ -261,6 +260,7 @@ proc generateExecutionPayload*(engine: SealingEngineRef,
|
|||||||
# make sure both generated block header and payloadRes(ExecutionPayloadV1)
|
# make sure both generated block header and payloadRes(ExecutionPayloadV1)
|
||||||
# produce the same blockHash
|
# produce the same blockHash
|
||||||
blk.header.prevRandao = Hash256(data: distinctBase payloadAttrs.prevRandao)
|
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], [
|
let res = engine.chain.persistBlocks([blk.header], [
|
||||||
BlockBody(transactions: blk.txs, uncles: blk.uncles)
|
BlockBody(transactions: blk.txs, uncles: blk.uncles)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user