From 72463097bc45d29ba66974e496423ecf65e0e1f7 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Wed, 23 Aug 2023 23:18:14 +0800 Subject: [PATCH] eth/catalyst: reset to current header if chain is rewinded Signed-off-by: jsvisa --- eth/catalyst/simulated_beacon.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/eth/catalyst/simulated_beacon.go b/eth/catalyst/simulated_beacon.go index e319264f4c..617b783a7b 100644 --- a/eth/catalyst/simulated_beacon.go +++ b/eth/catalyst/simulated_beacon.go @@ -144,6 +144,16 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal) error { feeRecipient := c.feeRecipient c.feeRecipientLock.Unlock() + // Reset to CurrentBlock incase the chain is rewinded + block := c.eth.BlockChain().CurrentBlock() + if c.curForkchoiceState.HeadBlockHash != block.Hash() { + c.curForkchoiceState = engine.ForkchoiceStateV1{ + HeadBlockHash: block.Hash(), + SafeBlockHash: block.Hash(), + FinalizedBlockHash: block.Hash(), + } + } + fcResponse, err := c.engineAPI.ForkchoiceUpdatedV2(c.curForkchoiceState, &engine.PayloadAttributes{ Timestamp: tstamp, SuggestedFeeRecipient: feeRecipient, @@ -211,7 +221,7 @@ func (c *SimulatedBeacon) loopOnDemand() { } } -// loopOnDemand runs the block production loop for non-zero period configuration +// loop runs the block production loop for non-zero period configuration func (c *SimulatedBeacon) loop() { timer := time.NewTimer(0) for {