From 123a3e589fbd29b025fbea4c35ef8b5e548df674 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Wed, 17 Jan 2024 20:22:11 +0330 Subject: [PATCH] eth/catalyst: update simulated beacon for cancun --- eth/catalyst/simulated_beacon.go | 41 ++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/eth/catalyst/simulated_beacon.go b/eth/catalyst/simulated_beacon.go index 3c081074cc..dc1b792440 100644 --- a/eth/catalyst/simulated_beacon.go +++ b/eth/catalyst/simulated_beacon.go @@ -148,26 +148,41 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u c.feeRecipientLock.Unlock() // Reset to CurrentBlock in case of the chain was rewound - if header := c.eth.BlockChain().CurrentBlock(); c.curForkchoiceState.HeadBlockHash != header.Hash() { + var ( + header = c.eth.BlockChain().CurrentBlock() + number = new(big.Int).Add(header.Number, big.NewInt(1)) + isCancun = c.eth.BlockChain().Config().IsCancun(number, timestamp) + ) + if c.curForkchoiceState.HeadBlockHash != header.Hash() { finalizedHash := c.finalizedBlockHash(header.Number.Uint64()) c.setCurrentState(header.Hash(), *finalizedHash) } var random [32]byte rand.Read(random[:]) - fcResponse, err := c.engineAPI.ForkchoiceUpdatedV2(c.curForkchoiceState, &engine.PayloadAttributes{ - Timestamp: timestamp, - SuggestedFeeRecipient: feeRecipient, - Withdrawals: withdrawals, - Random: random, - }) + + var ( + attrs = &engine.PayloadAttributes{ + Timestamp: timestamp, + SuggestedFeeRecipient: feeRecipient, + Withdrawals: withdrawals, + Random: random, + } + fcResponse engine.ForkChoiceResponse + err error + ) + if isCancun { + attrs.BeaconRoot = &common.Hash{} + fcResponse, err = c.engineAPI.ForkchoiceUpdatedV3(c.curForkchoiceState, attrs) + } else { + fcResponse, err = c.engineAPI.ForkchoiceUpdatedV2(c.curForkchoiceState, attrs) + } if err != nil { return err } if fcResponse == engine.STATUS_SYNCING { return errors.New("chain rewind prevented invocation of payload creation") } - envelope, err := c.engineAPI.getPayload(*fcResponse.PayloadID, true) if err != nil { return err @@ -186,8 +201,14 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u } // Mark the payload as canon - if _, err = c.engineAPI.NewPayloadV2(*payload); err != nil { - return err + if isCancun { + if _, err = c.engineAPI.NewPayloadV3(*payload, []common.Hash{}, &common.Hash{}); err != nil { + return err + } + } else { + if _, err = c.engineAPI.NewPayloadV2(*payload); err != nil { + return err + } } c.setCurrentState(payload.BlockHash, finalizedHash)