From 83bdde55aa26ac742d10ba03a2620278da30bb7a Mon Sep 17 00:00:00 2001 From: jangko Date: Mon, 11 Apr 2022 16:36:22 +0700 Subject: [PATCH] handle reorg case in sealing engine if engine api receive forkChoiceUpdated and turn out reorg happened, sealing engine must update txpool head. so in the next iteration when the txpool asked to produce a fresh block, it will produce it in the current 'correct' chain and abandon side chain. --- nimbus/sealer.nim | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nimbus/sealer.nim b/nimbus/sealer.nim index 95244dd2d..83912f2c7 100644 --- a/nimbus/sealer.nim +++ b/nimbus/sealer.nim @@ -229,19 +229,20 @@ proc sealingLoop(engine: SealingEngineRef): Future[void] {.async.} = template unsafeQuantityToInt64(q: web3types.Quantity): int64 = int64 q -import debug - proc generateExecutionPayload*(engine: SealingEngineRef, payloadAttrs: PayloadAttributesV1, payloadRes: var ExecutionPayloadV1): Result[void, string] = - let headBlock = try: engine.chain.db.getCanonicalHead() - except CatchableError: return err "No head block in database" - let + headBlock = try: engine.chain.db.getCanonicalHead() + except CatchableError: return err "No head block in database" prevRandao = Hash256(data: distinctBase payloadAttrs.prevRandao) timestamp = fromUnix(payloadAttrs.timestamp.unsafeQuantityToInt64) coinbase = EthAddress payloadAttrs.suggestedFeeRecipient + if headBlock.blockHash != engine.txPool.head.blockHash: + # reorg + discard engine.txPool.smartHead(headBlock) + var blk: EthBlock engine.txPool.feeRecipient = coinbase