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.
This commit is contained in:
jangko 2022-04-11 16:36:22 +07:00
parent 0fba19b81a
commit 83bdde55aa
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 6 additions and 5 deletions

View File

@ -229,19 +229,20 @@ proc sealingLoop(engine: SealingEngineRef): Future[void] {.async.} =
template unsafeQuantityToInt64(q: web3types.Quantity): int64 = template unsafeQuantityToInt64(q: web3types.Quantity): int64 =
int64 q int64 q
import debug
proc generateExecutionPayload*(engine: SealingEngineRef, proc generateExecutionPayload*(engine: SealingEngineRef,
payloadAttrs: PayloadAttributesV1, payloadAttrs: PayloadAttributesV1,
payloadRes: var ExecutionPayloadV1): Result[void, string] = payloadRes: var ExecutionPayloadV1): Result[void, string] =
let headBlock = try: engine.chain.db.getCanonicalHead()
except CatchableError: return err "No head block in database"
let let
headBlock = try: engine.chain.db.getCanonicalHead()
except CatchableError: return err "No head block in database"
prevRandao = Hash256(data: distinctBase payloadAttrs.prevRandao) prevRandao = Hash256(data: distinctBase payloadAttrs.prevRandao)
timestamp = fromUnix(payloadAttrs.timestamp.unsafeQuantityToInt64) timestamp = fromUnix(payloadAttrs.timestamp.unsafeQuantityToInt64)
coinbase = EthAddress payloadAttrs.suggestedFeeRecipient coinbase = EthAddress payloadAttrs.suggestedFeeRecipient
if headBlock.blockHash != engine.txPool.head.blockHash:
# reorg
discard engine.txPool.smartHead(headBlock)
var blk: EthBlock var blk: EthBlock
engine.txPool.feeRecipient = coinbase engine.txPool.feeRecipient = coinbase